common.py 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # -*- coding: utf-8 -*-
  2. from odoo.tests import common
  3. class TestStockCommon(common.TransactionCase):
  4. @classmethod
  5. def setUpClass(cls):
  6. super(TestStockCommon, cls).setUpClass()
  7. cls.ProductObj = cls.env['product.product']
  8. cls.UomObj = cls.env['uom.uom']
  9. cls.PartnerObj = cls.env['res.partner']
  10. cls.ModelDataObj = cls.env['ir.model.data']
  11. cls.StockPackObj = cls.env['stock.move.line']
  12. cls.StockQuantObj = cls.env['stock.quant']
  13. cls.PickingObj = cls.env['stock.picking']
  14. cls.MoveObj = cls.env['stock.move']
  15. cls.LotObj = cls.env['stock.lot']
  16. # Model Data
  17. cls.picking_type_in = cls.ModelDataObj._xmlid_to_res_id('stock.picking_type_in')
  18. cls.picking_type_out = cls.ModelDataObj._xmlid_to_res_id('stock.picking_type_out')
  19. cls.env['stock.picking.type'].browse(cls.picking_type_out).reservation_method = 'manual'
  20. cls.supplier_location = cls.ModelDataObj._xmlid_to_res_id('stock.stock_location_suppliers')
  21. cls.stock_location = cls.ModelDataObj._xmlid_to_res_id('stock.stock_location_stock')
  22. pack_location = cls.env.ref('stock.location_pack_zone')
  23. pack_location.active = True
  24. cls.pack_location = pack_location.id
  25. output_location = cls.env.ref('stock.stock_location_output')
  26. output_location.active = True
  27. cls.output_location = output_location.id
  28. cls.customer_location = cls.ModelDataObj._xmlid_to_res_id('stock.stock_location_customers')
  29. cls.categ_unit = cls.ModelDataObj._xmlid_to_res_id('uom.product_uom_categ_unit')
  30. cls.categ_kgm = cls.ModelDataObj._xmlid_to_res_id('uom.product_uom_categ_kgm')
  31. # Product Created A, B, C, D
  32. cls.productA = cls.ProductObj.create({'name': 'Product A', 'type': 'product'})
  33. cls.productB = cls.ProductObj.create({'name': 'Product B', 'type': 'product'})
  34. cls.productC = cls.ProductObj.create({'name': 'Product C', 'type': 'product'})
  35. cls.productD = cls.ProductObj.create({'name': 'Product D', 'type': 'product'})
  36. cls.productE = cls.ProductObj.create({'name': 'Product E', 'type': 'product'})
  37. # Configure unit of measure.
  38. cls.uom_kg = cls.env['uom.uom'].search([('category_id', '=', cls.categ_kgm), ('uom_type', '=', 'reference')], limit=1)
  39. cls.uom_kg.write({
  40. 'name': 'Test-KG',
  41. 'rounding': 0.000001})
  42. cls.uom_tone = cls.UomObj.create({
  43. 'name': 'Test-Tone',
  44. 'category_id': cls.categ_kgm,
  45. 'uom_type': 'bigger',
  46. 'factor_inv': 1000.0,
  47. 'rounding': 0.001})
  48. cls.uom_gm = cls.UomObj.create({
  49. 'name': 'Test-G',
  50. 'category_id': cls.categ_kgm,
  51. 'uom_type': 'smaller',
  52. 'factor': 1000.0,
  53. 'rounding': 0.001})
  54. cls.uom_mg = cls.UomObj.create({
  55. 'name': 'Test-MG',
  56. 'category_id': cls.categ_kgm,
  57. 'uom_type': 'smaller',
  58. 'factor': 100000.0,
  59. 'rounding': 0.001})
  60. # Check Unit
  61. cls.uom_unit = cls.env['uom.uom'].search([('category_id', '=', cls.categ_unit), ('uom_type', '=', 'reference')], limit=1)
  62. cls.uom_unit.write({
  63. 'name': 'Test-Unit',
  64. 'rounding': 1.0})
  65. cls.uom_dozen = cls.UomObj.create({
  66. 'name': 'Test-DozenA',
  67. 'category_id': cls.categ_unit,
  68. 'factor_inv': 12,
  69. 'uom_type': 'bigger',
  70. 'rounding': 0.001})
  71. cls.uom_sdozen = cls.UomObj.create({
  72. 'name': 'Test-SDozenA',
  73. 'category_id': cls.categ_unit,
  74. 'factor_inv': 144,
  75. 'uom_type': 'bigger',
  76. 'rounding': 0.001})
  77. cls.uom_sdozen_round = cls.UomObj.create({
  78. 'name': 'Test-SDozenA Round',
  79. 'category_id': cls.categ_unit,
  80. 'factor_inv': 144,
  81. 'uom_type': 'bigger',
  82. 'rounding': 1.0})
  83. # Product for different unit of measure.
  84. cls.DozA = cls.ProductObj.create({'name': 'Dozon-A', 'type': 'product', 'uom_id': cls.uom_dozen.id, 'uom_po_id': cls.uom_dozen.id})
  85. cls.SDozA = cls.ProductObj.create({'name': 'SuperDozon-A', 'type': 'product', 'uom_id': cls.uom_sdozen.id, 'uom_po_id': cls.uom_sdozen.id})
  86. cls.SDozARound = cls.ProductObj.create({'name': 'SuperDozenRound-A', 'type': 'product', 'uom_id': cls.uom_sdozen_round.id, 'uom_po_id': cls.uom_sdozen_round.id})
  87. cls.UnitA = cls.ProductObj.create({'name': 'Unit-A', 'type': 'product'})
  88. cls.kgB = cls.ProductObj.create({'name': 'kg-B', 'type': 'product', 'uom_id': cls.uom_kg.id, 'uom_po_id': cls.uom_kg.id})
  89. cls.gB = cls.ProductObj.create({'name': 'g-B', 'type': 'product', 'uom_id': cls.uom_gm.id, 'uom_po_id': cls.uom_gm.id})