From f7414c0b180027f6f89d05d293c69738258faa7b Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 16 Apr 2019 13:48:45 +0000 Subject: [PATCH] [FIX] sale_mrp: No delivered_qty computed with partial delivery Steps to reproduce the bug: - Create a consumable or storable final product A with invoicing policy in "delivered quantity" - Create two storable products B and C - Create a BOM kit for A with 1 B and 1 C - Create a SO with 5 qty of A and confirm it - Deliver 3 B and 2 C and either on "No backorder" or "With backorder" Bug: The delivered_qty on the SO line is of course not automatically updated (as in this case, a right value is not computable) but the delivered_qty was not updatable manually and then it was possible to invoice the SO. Co-authored-by: nim-odoo opw:1966170 closes odoo/odoo#32733 Signed-off-by: Simon Goffin (sig) --- addons/sale_mrp/models/sale_mrp.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/sale_mrp/models/sale_mrp.py b/addons/sale_mrp/models/sale_mrp.py index 9a5ba682392..7cf94b6a3c3 100644 --- a/addons/sale_mrp/models/sale_mrp.py +++ b/addons/sale_mrp/models/sale_mrp.py @@ -60,6 +60,19 @@ class SaleOrderLine(models.Model): return self.env.context['previous_product_uom_qty'].get(self.id, 0.0) return super(SaleOrderLine, self)._get_qty_procurement() + @api.multi + @api.depends('product_id', 'move_ids.state') + def _compute_qty_delivered_method(self): + lines = self.env['sale.order.line'] + for line in self: + bom = self.env['mrp.bom']._bom_find(product=line.product_id, company_id=line.company_id.id) + if bom and bom.type == 'phantom' and line.order_id.state == 'sale': + bom_delivered = all([move.state == 'done' for move in line.move_ids]) + if not bom_delivered: + line.qty_delivered_method = 'manual' + lines |= line + super(SaleOrderLine, self - lines)._compute_qty_delivered_method() + class AccountInvoiceLine(models.Model): # TDE FIXME: what is this code ??