From 1d67f0583e396ffcc42e241bd8f20335f4d607d8 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Wed, 26 Aug 2020 09:56:03 +0000 Subject: [PATCH] [FIX] purchase(_stock): make orderpoint qtys depend on POs Before this commit, `stock.warehouse.orderpoint` `_compute_qty` didn't depend on `purchase.order.line` (POL). This means when a relevant POL was edited/cancelled, then the `qty_forecast` wouldn't correctly update. To reproduce: - Create a product w/ a vendor and buy route active, - Go to replenishment report, create a reordering rule, and hit order for product (RFQ should be created) - Cancel the RFQ and go back to replenishment report The product should reappear in the list view, but does not because it's `qty_forecast` has not updated and therefore has not updated corresponding `qty_to_order` value. Note string rename of `purchase_line_warn` 'Purchase Order Line' => 'Purchase Order Line Warning' is due to repeat label use issue. It is better to rename the poorly labeled `purchase_line_warn` than to give a hacky label for new One2many field. Task: 2285912 Manual forward port of: odoo/odoo#56580 due to migration test error closes odoo/odoo#56625 Closes: odoo/odoo#56625 Signed-off-by: Arnold Moyaux --- addons/purchase/models/product.py | 2 +- addons/purchase_stock/models/product.py | 2 ++ addons/purchase_stock/models/stock.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/purchase/models/product.py b/addons/purchase/models/product.py index bb5817086c9..ddd3c558950 100644 --- a/addons/purchase/models/product.py +++ b/addons/purchase/models/product.py @@ -22,7 +22,7 @@ class ProductTemplate(models.Model): ('receive', 'On received quantities'), ], string="Control Policy", help="On ordered quantities: Control bills based on ordered quantities.\n" "On received quantities: Control bills based on received quantities.", default="receive") - purchase_line_warn = fields.Selection(WARNING_MESSAGE, 'Purchase Order Line', help=WARNING_HELP, required=True, default="no-message") + purchase_line_warn = fields.Selection(WARNING_MESSAGE, 'Purchase Order Line Warning', help=WARNING_HELP, required=True, default="no-message") purchase_line_warn_msg = fields.Text('Message for Purchase Order Line') def _compute_purchased_product_qty(self): diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index f09db2e1167..66bfb199b3a 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -23,6 +23,8 @@ class ProductProduct(models.Model): _name = 'product.product' _inherit = 'product.product' + purchase_order_line_ids = fields.One2many('purchase.order.line', 'product_id', help='Technical: used to compute quantities.') + def _get_quantity_in_progress(self, location_ids=False, warehouse_ids=False): if not location_ids: location_ids = [] diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py index 89e46abbe1f..4e690217e23 100644 --- a/addons/purchase_stock/models/stock.py +++ b/addons/purchase_stock/models/stock.py @@ -183,6 +183,11 @@ class Orderpoint(models.Model): 'product.supplierinfo', string='Vendor', check_company=True, domain="['|', ('product_id', '=', product_id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product_tmpl_id)]") + @api.depends('product_id.purchase_order_line_ids', 'product_id.purchase_order_line_ids.state') + def _compute_qty(self): + """ Extend to add more depends values """ + return super()._compute_qty() + @api.depends('route_id') def _compute_show_suppplier(self): buy_route = []