diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py index 7bff8e91ec7..02e93e30dc2 100644 --- a/addons/purchase_stock/models/stock.py +++ b/addons/purchase_stock/models/stock.py @@ -97,7 +97,7 @@ class Orderpoint(models.Model): vendor_id = fields.Many2one(related='supplier_id.partner_id', string="Vendor", store=True) purchase_visibility_days = fields.Float(default=0.0, help="Visibility Days applied on the purchase routes.") - @api.depends('product_id.purchase_order_line_ids', 'product_id.purchase_order_line_ids.state') + @api.depends('product_id.purchase_order_line_ids.product_qty', 'product_id.purchase_order_line_ids.state') def _compute_qty(self): """ Extend to add more depends values """ return super()._compute_qty() diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index e484cb30e01..956342fb911 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -259,6 +259,64 @@ class TestReorderingRule(TransactionCase): self.assertEqual(len(purchase_order.order_line), 1, 'Not enough purchase order lines created.') purchase_order.button_confirm() + def test_reordering_rule_triggered_two_times(self): + """ + A product P wth RR 0-0-1. + Confirm a delivery with 1 x P -> PO created for it. + Confirm a second delivery, with 1 x P again: + - The PO should be updated + - The qty to order of the RR should be zero + """ + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) + stock_location = warehouse.lot_stock_id + out_type = warehouse.out_type_id + customer_location = self.env.ref('stock.stock_location_customers') + + rr = self.env['stock.warehouse.orderpoint'].create({ + 'location_id': stock_location.id, + 'product_id': self.product_01.id, + 'product_min_qty': 0, + 'product_max_qty': 0, + 'qty_multiple': 1, + }) + + delivery = self.env['stock.picking'].create({ + 'picking_type_id': out_type.id, + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + 'move_ids': [(0, 0, { + 'name': self.product_01.name, + 'product_id': self.product_01.id, + 'product_uom_qty': 1, + 'product_uom': self.product_01.uom_id.id, + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + })] + }) + delivery.action_confirm() + + pol = self.env['purchase.order.line'].search([('product_id', '=', self.product_01.id)]) + self.assertEqual(pol.product_qty, 1.0) + self.assertEqual(rr.qty_to_order, 0.0) + + delivery = self.env['stock.picking'].create({ + 'picking_type_id': out_type.id, + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + 'move_ids': [(0, 0, { + 'name': self.product_01.name, + 'product_id': self.product_01.id, + 'product_uom_qty': 1, + 'product_uom': self.product_01.uom_id.id, + 'location_id': stock_location.id, + 'location_dest_id': customer_location.id, + })] + }) + delivery.action_confirm() + + self.assertEqual(pol.product_qty, 2.0) + self.assertEqual(rr.qty_to_order, 0.0) + def test_replenish_report_1(self): """Tests the auto generation of manual orderpoints.