[FIX] purchase_stock: update RR's qty_to_order on POL's qty change

When a RR updates the qty of a POL, the qty to order of that RR will
be incorrect

To reproduce the issue:
1. Create a product
   - Storable
   - With a vendor
2. Create a RR:
   - Min 0
   - Max 0
   - Factor 1
3. Confirm a delivery with 1 x P
   - It should create a PO
4. Confirm a second delivery with 1 x P
    - The POL of the PO should be updated
5. Open the Replenishment page

Error: The qty to order of the product is 1 while it should be 0

`qty_to_order` is a computed field and one of the `depends` is the POL
related to the product. This explains why, after step 3, everything
is ok: the compute is triggered (because of the new POL) and the qty
to order becomes 0. However, step 4, the POL qty is updated -> it
does not concern any `depends` -> the compute is not triggered,
hence the error

OPW-3292297

closes odoo/odoo#128279

X-original-commit: 80521431601323c1eb7c85cafbf08e8ae0adbdd6
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
This commit is contained in:
Adrien Widart (awt)
2023-07-13 07:18:51 +02:00
parent 4e2256dc6a
commit 4333b16d8c
2 changed files with 59 additions and 1 deletions
+1 -1
View File
@@ -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()
@@ -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.