diff --git a/custom_mrp_line_cost/__manifest__.py b/custom_mrp_line_cost/__manifest__.py index c782fd2cf..92f78e95d 100644 --- a/custom_mrp_line_cost/__manifest__.py +++ b/custom_mrp_line_cost/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Custom MRP Line Cost", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "category": "MRP", "license": "AGPL-3", "author": "AvanzOSC", @@ -28,4 +28,5 @@ "views/mrp_routing_workcenter_view.xml", ], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/custom_mrp_line_cost/i18n/custom_mrp_line_cost.pot b/custom_mrp_line_cost/i18n/custom_mrp_line_cost.pot index 643c17d11..ff617721b 100644 --- a/custom_mrp_line_cost/i18n/custom_mrp_line_cost.pot +++ b/custom_mrp_line_cost/i18n/custom_mrp_line_cost.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-29 11:24+0000\n" -"PO-Revision-Date: 2024-08-29 11:24+0000\n" +"POT-Creation-Date: 2024-09-12 09:08+0000\n" +"PO-Revision-Date: 2024-09-12 09:08+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -152,6 +152,11 @@ msgstr "" msgid "Dest Kg" msgstr "" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__dif_total_amount +msgid "Dif. Total Amount" +msgstr "" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_killing_cost__display_name #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom__display_name @@ -295,6 +300,11 @@ msgstr "" msgid "October" msgstr "" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__operation_id +msgid "Operation" +msgstr "" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__origin_qty msgid "Origin Qty" diff --git a/custom_mrp_line_cost/i18n/es.po b/custom_mrp_line_cost/i18n/es.po index f8d298865..a7cefccba 100644 --- a/custom_mrp_line_cost/i18n/es.po +++ b/custom_mrp_line_cost/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-29 11:28+0000\n" -"PO-Revision-Date: 2024-08-29 11:28+0000\n" +"POT-Creation-Date: 2024-09-12 09:08+0000\n" +"PO-Revision-Date: 2024-09-12 09:08+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -152,6 +152,11 @@ msgstr "Diciembre" msgid "Dest Kg" msgstr "Cantidad destino" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__dif_total_amount +msgid "Dif. Total Amount" +msgstr "Dif. importe" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_killing_cost__display_name #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom__display_name @@ -295,6 +300,11 @@ msgstr "Noviembre" msgid "October" msgstr "Octubre" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__operation_id +msgid "Operation" +msgstr "OperaciĆ³n" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_production__origin_qty msgid "Origin Qty" diff --git a/custom_mrp_line_cost/migrations/14.0.1.1.0/pre-migration.py b/custom_mrp_line_cost/migrations/14.0.1.1.0/pre-migration.py new file mode 100644 index 000000000..8769403c6 --- /dev/null +++ b/custom_mrp_line_cost/migrations/14.0.1.1.0/pre-migration.py @@ -0,0 +1,31 @@ +# Copyright 2024 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + cr = env.cr + if not openupgrade.column_exists(cr, "stock_move_line", "operation_id"): + cr.execute( + """ + ALTER TABLE stock_move_line + ADD COLUMN operation_id integer; + """ + ) + cr.execute( + """ + UPDATE stock_move_line + SET operation_id = (SELECT mrp_bom_byproduct.operation_id + FROM mrp_bom_byproduct, + stock_move + WHERE stock_move.id = stock_move_line.move_id + AND move_id IS NOT NULL + AND mrp_bom_byproduct.id = stock_move.byproduct_id + AND byproduct_id IS NOT NULL) + """ + ) diff --git a/custom_mrp_line_cost/models/mrp_production.py b/custom_mrp_line_cost/models/mrp_production.py index 7c2a94123..7ba3e8cd9 100644 --- a/custom_mrp_line_cost/models/mrp_production.py +++ b/custom_mrp_line_cost/models/mrp_production.py @@ -73,10 +73,22 @@ class MrpProduction(models.Model): entry_total_amount = fields.Float( string="Entry Total Amount", compute="_compute_entry_total_amount", store=True ) - output_total_amount = fields.Float(string="Output Total Amount") + output_total_amount = fields.Float( + string="Output Total Amount", compute="_compute_output_total_amount", store=True + ) consume_qty = fields.Float( string="Consumed Qty", compute="_compute_consume_qty", store=True ) + dif_total_amount = fields.Float( + string="Dif. Total Amount", compute="_compute_dif_total_amount", store=True + ) + + @api.depends("entry_total_amount", "output_total_amount") + def _compute_dif_total_amount(self): + for production in self: + production.dif_total_amount = ( + production.output_total_amount - production.entry_total_amount + ) @api.depends( "move_line_ids.qty_done", @@ -103,7 +115,7 @@ def _compute_entry_total_amount(self): for line in self: entry_total_amount = 0 if line.move_line_ids: - entry_total_amount = sum(self.move_line_ids.mapped("amount")) + entry_total_amount = sum(line.move_line_ids.mapped("amount")) line.entry_total_amount = entry_total_amount @api.depends("finished_move_line_ids.amount") @@ -263,6 +275,7 @@ def button_calculate_costs(self): for line in production.finished_move_line_ids: line.applied_price = line.base_price line.standard_price = line.applied_price + line.amount = line.standard_price * line.qty_done dif = ( (production.average_cost + production.month_cost) * production.consume_qty diff --git a/custom_mrp_line_cost/models/stock_move_line.py b/custom_mrp_line_cost/models/stock_move_line.py index dd6717f78..f807e1649 100644 --- a/custom_mrp_line_cost/models/stock_move_line.py +++ b/custom_mrp_line_cost/models/stock_move_line.py @@ -54,6 +54,12 @@ def _default_pallet_id(self): month_cost = fields.Float( string="Month Cost", compute="_compute_month_cost", store=True ) + operation_id = fields.Many2one( + string="Operation", + comodel_name="mrp.routing.workcenter", + related="move_id.byproduct_id.operation_id", + store=True, + ) pallet_id = fields.Many2one( string="Pallet", comodel_name="product.product", @@ -187,6 +193,8 @@ def _compute_expense_kg(self): "production_id.average_cost", "production_id.month_cost", "production_id.is_deconstruction", + "production_id.move_line_ids", + "production_id.move_line_ids.amount", ) def _compute_base_price(self): for line in self: 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 ff12a21c0..c20dabe49 100644 --- a/custom_mrp_line_cost/views/stock_move_line_view.xml +++ b/custom_mrp_line_cost/views/stock_move_line_view.xml @@ -41,6 +41,7 @@ attrs="{'readonly': [('tracking', 'not in', ('lot', 'serial'))]}" context="{'default_product_id': product_id, 'default_company_id': company_id}" domain="[('product_id', '=', product_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]" + options="{'no_create': True}" />