summaryrefslogtreecommitdiff
path: root/addons/purchase_stock/tests
diff options
context:
space:
mode:
authorSimon Lejeune <sle@openerp.com>2020-01-17 16:00:51 +0000
committerSimon Lejeune <sle@openerp.com>2020-01-28 14:51:36 +0000
commit9d98c43581e2579f43b35541b43264866dede5a5 (patch)
tree7f3ba58302c61624cf503d12c4cd399b4d8c3092 /addons/purchase_stock/tests
parentaebce884d4531d5671030a45376cae48ce022bab (diff)
[REF] purchase_stock: push the extra quantity
With a product configured as buy on order and a warehouse configured as receipt in two steps, if the user increases the quantity on a po line generated by a sale order before confirming it, the system will send all the quantity to input but only the ordered quantity to customer. The issue is that the "extra quantity" will stay in input. We fix this issue by creating a new move with the extra quantity to the input location so that push rules will send the extra quantity to stock while the ordered quantity will be sent to the customer. There was also an issue when incrementing the quantity on the po line after confirmation if the po line was the result of a reordering rule: only a move from supplier to the location of the reordering rule was created. This commit also introduces a change of semantic: `created_purchase_line_id` is cleared after confirming the RFQ. This allows to merge more in `_merge_moves`. task-1981355 closes odoo/odoo#43545 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons/purchase_stock/tests')
-rw-r--r--addons/purchase_stock/tests/test_reordering_rule.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py
index eee698d0b66..d5ceda8fe47 100644
--- a/addons/purchase_stock/tests/test_reordering_rule.py
+++ b/addons/purchase_stock/tests/test_reordering_rule.py
@@ -27,6 +27,9 @@ class TestReorderingRule(SavepointCase):
- Receive products in 2 steps
- The product has a reordering rule
- On the po generated, the source document should be the name of the reordering rule
+ - Increase the quantity on the RFQ, the extra quantity should follow the push rules
+ - Increase the quantity on the PO, the extra quantity should follow the push rules
+ - There should be one move supplier -> input and two moves input -> stock
"""
warehouse_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
warehouse_1.write({'reception_steps': 'two_steps'})
@@ -61,12 +64,33 @@ class TestReorderingRule(SavepointCase):
# On the po generated, the source document should be the name of the reordering rule
self.assertEqual(order_point.name, purchase_order.origin, 'Source document on purchase order should be the name of the reordering rule.')
+ self.assertEqual(purchase_order.order_line.product_qty, 10)
+
+ # Increase the quantity on the RFQ before confirming it
+ purchase_order.order_line.product_qty = 12
+ purchase_order.button_confirm()
+
+ self.assertEqual(purchase_order.picking_ids.move_lines.filtered(lambda m: m.product_id == self.product_01).product_qty, 12)
+ next_picking = purchase_order.picking_ids.move_lines.move_dest_ids.picking_id
+ self.assertEqual(len(next_picking), 2)
+ self.assertEqual(next_picking[0].move_lines.filtered(lambda m: m.product_id == self.product_01).product_qty, 10)
+ self.assertEqual(next_picking[1].move_lines.filtered(lambda m: m.product_id == self.product_01).product_qty, 2)
+
+ # Increase the quantity on the PO
+ purchase_order.order_line.product_qty = 15
+ self.assertEqual(purchase_order.picking_ids.move_lines.product_qty, 15)
+ self.assertEqual(next_picking[0].move_lines.filtered(lambda m: m.product_id == self.product_01).product_qty, 10)
+ self.assertEqual(next_picking[1].move_lines.filtered(lambda m: m.product_id == self.product_01).product_qty, 5)
def test_reordering_rule_2(self):
"""
- Receive products in 1 steps
- The product has two reordering rules, each one applying in a sublocation
- Processing the purchase order should fulfill the two sublocations
+ - Increase the quantity on the RFQ for one of the POL, the extra quantity will go to
+ the original subloc since we don't know where to push it (no move dest)
+ - Increase the quantity on the PO, the extra quantity should follow the push rules and
+ thus go to stock
"""
warehouse_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
subloc_1 = self.env['stock.location'].create({'name': 'subloc_1', 'location_id': warehouse_1.lot_stock_id.id})
@@ -115,9 +139,17 @@ class TestReorderingRule(SavepointCase):
self.assertTrue(purchase_order, 'No purchase order created.')
self.assertEqual(len(purchase_order.order_line), 2, 'Not enough purchase order lines created.')
+ # increment the qty of the first po line
+ purchase_order.order_line.filtered(lambda pol: pol.orderpoint_id == order_point_1).product_qty = 15
purchase_order.button_confirm()
- res = purchase_order.picking_ids.button_validate()
- Form(self.env[res['res_model']].with_context(res['context'])).save().process()
- self.assertEqual(self.product_01.with_context(location=subloc_1.id).virtual_available, 0)
+ self.assertEqual(self.product_01.with_context(location=subloc_1.id).virtual_available, 5)
+ self.assertEqual(self.product_01.with_context(location=subloc_2.id).virtual_available, 0)
+
+ # increment the qty of the second po line
+ purchase_order.order_line.filtered(lambda pol: pol.orderpoint_id == order_point_2).with_context(debug=True).product_qty = 15
+ self.assertEqual(self.product_01.with_context(location=subloc_1.id).virtual_available, 5)
self.assertEqual(self.product_01.with_context(location=subloc_2.id).virtual_available, 0)
+ self.assertEqual(self.product_01.with_context(location=warehouse_1.lot_stock_id.id).virtual_available, 10) # 5 on the main loc, 5 on subloc_1
+ self.assertEqual(purchase_order.picking_ids.move_lines[-1].product_qty, 5)
+ self.assertEqual(purchase_order.picking_ids.move_lines[-1].location_dest_id, warehouse_1.lot_stock_id)