From f4fde9ec58ce2b5c2e80963596a2efa2a5ccc1dd Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Wed, 16 Feb 2022 16:05:50 +0000 Subject: [PATCH] [FIX] mrp: allow adding byproducts to confirmed MO Steps to reproduce: - Create + confirm a MO - Add a byproduct with a Produced (qty) > 1 - Change the `qty_producing` to a non-zero qty Expected result: Byproduct's "Produced" qty stays unchanged and its "To Produce" is 0 Actual result: Byproduct's "To Produce" defaults to 1 and its "Produced" qty is updated to scale to the according to the amount `qty_producing` (i.e. if `product_qty` = 2 and `qty_producing` = 1, then by-product's "Produced" = .5 Additionally, a Missing Record error pops up because of missing stock.move.line Solution, don't allow byproducts added after MO is confirmed to default to 0. Additionally allow byproducts to have 0 "To Produce" quantity and don't sum the cost share of merged byproduct moves since when Produced > To Produce then an extra move is created and the cost share ends up being doubled during the merge. closes odoo/odoo#85130 Task: 2716164 X-original-commit: 51ff14a56b909bdf22c9f1c4540347655578e1f4 Signed-off-by: Arnold Moyaux Signed-off-by: Tiffany Chang --- addons/mrp/models/mrp_production.py | 2 -- addons/mrp/models/stock_move.py | 5 ----- addons/mrp/views/mrp_production_views.xml | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 6c9451535fd..cd8adbb2984 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -744,8 +744,6 @@ class MrpProduction(models.Model): @api.constrains('move_byproduct_ids') def _check_byproducts(self): for order in self: - if any(float_compare(move.product_qty, 0.0, precision_rounding=move.product_uom.rounding or move.product_id.uom_id.rounding) <= 0 for move in order.move_byproduct_ids): - raise ValidationError(_("The quantity produced of by-products must be positive.")) if any(move.cost_share < 0 for move in order.move_byproduct_ids): raise ValidationError(_("By-products cost shares must be positive.")) if sum(order.move_byproduct_ids.mapped('cost_share')) > 100: diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 720f2196e49..cc1ac61738e 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -444,11 +444,6 @@ class StockMove(models.Model): def _prepare_merge_negative_moves_excluded_distinct_fields(self): return super()._prepare_merge_negative_moves_excluded_distinct_fields() + ['created_production_id'] - def _merge_moves_fields(self): - res = super()._merge_moves_fields() - res['cost_share'] = sum(self.mapped('cost_share')) - return res - def _compute_kit_quantities(self, product_id, kit_qty, kit_bom, filters): """ Computes the quantity delivered or received when a kit is sold or purchased. A ratio 'qty_processed/qty_needed' is computed for each component, and the lowest one is kept diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 93df559e008..1b6d11ddc14 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -396,7 +396,7 @@ - +