summaryrefslogtreecommitdiff
path: root/addons/purchase/tests/test_create_picking.py
diff options
context:
space:
mode:
authorSimon Lejeune <sle@openerp.com>2018-02-07 14:36:44 +0100
committerSimon Lejeune <sle@openerp.com>2018-02-19 14:29:09 +0100
commit97ed2e730e5addda38d396b32ff48a369d85033f (patch)
treebcc845f089e2dba94c865f5fa1519f0159b0fade /addons/purchase/tests/test_create_picking.py
parentd28f8f704febe030f9c068f895adf0b1ce3e8dc1 (diff)
[FIX] purchase, sale_stock: propagation of UOM
Before this commit, the uom defined on the sale order line and on the purchase order line was propagated to the moves. This is not the behaviour of v8-10 and may confuse the stock operator (one time he's working in dozen, another time in units for example). It also leads to rounding issues if the configuration is not adapted correctly (product's uom is in units, sale order line is in dozen, the rouding precision on the uom is left to their defaults, now if a dozen is partially available there's a good chance converting back and forth form dozen to units will break). An ir.config_parameter was added to restore the behaviour before this commit.
Diffstat (limited to 'addons/purchase/tests/test_create_picking.py')
-rw-r--r--addons/purchase/tests/test_create_picking.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/addons/purchase/tests/test_create_picking.py b/addons/purchase/tests/test_create_picking.py
index b29e85b3825..9cdfe0fb4fd 100644
--- a/addons/purchase/tests/test_create_picking.py
+++ b/addons/purchase/tests/test_create_picking.py
@@ -174,3 +174,53 @@ class TestCreatePicking(common.TestProductCommon):
customer_move._action_assign()
self.assertEqual(customer_move.state, 'assigned', 'Reservation should work with the new quantity provided by the PO.')
+
+ def test_03_uom(self):
+ """ Buy a dozen of products stocked in units. Check that the quantities on the purchase order
+ lines as well as the received quantities are handled in dozen while the moves themselves
+ are handled in units. Edit the ordered quantities, check that the quantites are correctly
+ updated on the moves. Edit the ir.config_parameter to propagate the uom of the purchase order
+ lines to the moves and edit a last time the ordered quantities. Receive, check the quantities.
+ """
+ uom_unit = self.env.ref('product.product_uom_unit')
+ uom_dozen = self.env.ref('product.product_uom_dozen')
+
+ self.assertEqual(self.product_id_1.uom_po_id.id, uom_unit.id)
+
+ # buy a dozen
+ po = self.env['purchase.order'].create(self.po_vals)
+
+ po.order_line.product_qty = 1
+ po.order_line.product_uom = uom_dozen.id
+ po.button_confirm()
+
+ # the move should be 12 units
+ # note: move.product_qty = computed field, always in the uom of the quant
+ # move.product_uom_qty = stored field representing the initial demand in move.product_uom
+ move1 = po.picking_ids.move_lines[0]
+ self.assertEqual(move1.product_uom_qty, 12)
+ self.assertEqual(move1.product_uom.id, uom_unit.id)
+ self.assertEqual(move1.product_qty, 12)
+
+ # edit the so line, sell 2 dozen, the move should now be 24 units
+ po.order_line.product_qty = 2
+ self.assertEqual(move1.product_uom_qty, 24)
+ self.assertEqual(move1.product_uom.id, uom_unit.id)
+ self.assertEqual(move1.product_qty, 24)
+
+ # force the propagation of the uom, sell 3 dozen
+ self.env['ir.config_parameter'].sudo().set_param('stock.propagate_uom', '1')
+ po.order_line.product_qty = 3
+ move2 = po.picking_ids.move_lines.filtered(lambda m: m.product_uom.id == uom_dozen.id)
+ self.assertEqual(move2.product_uom_qty, 1)
+ self.assertEqual(move2.product_uom.id, uom_dozen.id)
+ self.assertEqual(move2.product_qty, 12)
+
+ # deliver everything
+ move1.quantity_done = 24
+ move2.quantity_done = 1
+ po.picking_ids.button_validate()
+
+ # check the delivered quantity
+ self.assertEqual(po.order_line.qty_received, 3.0)
+