From 86778a8bb6d3ca8b822b673aac577f6d4d26e898 Mon Sep 17 00:00:00 2001 From: Berezi Date: Tue, 11 Feb 2025 13:25:30 +0100 Subject: [PATCH] [14.0][IMP] custom_mrp_line_cost: Add default function to container. --- custom_mrp_line_cost/models/mrp_production.py | 31 ++++++++++--------- .../models/stock_move_line.py | 8 ++++- .../views/stock_move_line_view.xml | 4 +-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/custom_mrp_line_cost/models/mrp_production.py b/custom_mrp_line_cost/models/mrp_production.py index 9398ddebe..bef02a846 100644 --- a/custom_mrp_line_cost/models/mrp_production.py +++ b/custom_mrp_line_cost/models/mrp_production.py @@ -258,21 +258,22 @@ def button_calculate_costs(self): ).mapped("qty_done") ) ) - i = qty.index(max(qty)) - max_lot = lots[i] - max_qty = qty[i] - if max_lot and max_qty: - lot_lines = production.move_line_ids.filtered( - lambda c: c.lot_id == max_lot - ) - amount = (production.cost - production.entry_total_amount) + sum( - lot_lines.mapped("amount") - ) - price = amount / max_qty - for max_line in lot_lines: - max_line.applied_price = price - max_line.onchange_applied_price() - production._compute_entry_total_amount() + if qty: + i = qty.index(max(qty)) + max_lot = lots[i] + max_qty = qty[i] + if max_lot and max_qty: + lot_lines = production.move_line_ids.filtered( + lambda c: c.lot_id == max_lot + ) + amount = ( + production.cost - production.entry_total_amount + ) + sum(lot_lines.mapped("amount")) + price = amount / max_qty + for max_line in lot_lines: + max_line.applied_price = price + max_line.onchange_applied_price() + production._compute_entry_total_amount() elif ( not production.is_deconstruction and (production.average_cost) diff --git a/custom_mrp_line_cost/models/stock_move_line.py b/custom_mrp_line_cost/models/stock_move_line.py index 96e9d7642..88f913e65 100644 --- a/custom_mrp_line_cost/models/stock_move_line.py +++ b/custom_mrp_line_cost/models/stock_move_line.py @@ -18,7 +18,13 @@ def _default_pallet_id(self): result = False return result - container = fields.Integer(string="Containers") + def _default_container(self): + result = 0 + if "default_production_id" in self.env.context: + result = 1 + return result + + container = fields.Integer(string="Containers", default=_default_container) unit = fields.Integer(string="Unit") product_unit_container = fields.Integer( string="Product Unit/Container", related="product_id.unit_container", store=True diff --git a/custom_mrp_line_cost/views/stock_move_line_view.xml b/custom_mrp_line_cost/views/stock_move_line_view.xml index 79110fc08..740aa2b08 100644 --- a/custom_mrp_line_cost/views/stock_move_line_view.xml +++ b/custom_mrp_line_cost/views/stock_move_line_view.xml @@ -27,7 +27,7 @@ stock.move.line.tree.view stock.move.line - + stock.move.line.tree.view stock.move.line - +