From ad40ed029ce0cf7cafec4454b4e9ca3a8db33d55 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Wed, 9 Jan 2019 12:52:01 +0000 Subject: [PATCH] [FIX] delivery: weight computation without quant The weight computation was not working anymore on packages that don't have any quant, because they are fresh ones. We fix this by setting back the behaviour with the picking id in context and adapt the function to find the corresponding move lines. closes odoo/odoo#30071 --- addons/delivery/models/stock_picking.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index a9afc258004..e8a1344cb08 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -16,8 +16,13 @@ class StockQuantPackage(models.Model): @api.depends('quant_ids') def _compute_weight(self): weight = 0.0 - for quant in self.quant_ids: - weight += quant.quantity * quant.product_id.weight + if self.env.context.get('picking_id'): + current_picking_move_line_ids = self.env['stock.move.line'].search([('result_package_id', '=', self.id), ('picking_id', '=', self.env.context['picking_id'])]) + for ml in current_picking_move_line_ids: + weight += ml.product_uom_id._compute_quantity(ml.qty_done,ml.product_id.uom_id) * ml.product_id.weight + else: + for quant in self.quant_ids: + weight += quant.quantity * quant.product_id.weight self.weight = weight weight = fields.Float(compute='_compute_weight', help="Weight computed based on the sum of the weights of the products.")