From e228804a50762c56d3a9b82b9c30c6225989c7cb Mon Sep 17 00:00:00 2001 From: Tu Nombre Date: Tue, 2 Jul 2024 08:23:54 +0200 Subject: [PATCH] [14.0][IMP] custom_mrp_line_cost: New fields in stock move lines. --- custom_mrp_line_cost/__manifest__.py | 2 +- .../mrp_standar_price_decimal_precision.xml | 2 +- .../i18n/custom_mrp_line_cost.pot | 27 +- custom_mrp_line_cost/i18n/es.po | 27 +- custom_mrp_line_cost/models/killing_cost.py | 39 +-- custom_mrp_line_cost/models/mrp_bom.py | 23 +- .../models/mrp_bom_byproduct.py | 10 +- custom_mrp_line_cost/models/mrp_production.py | 327 +++++++++--------- custom_mrp_line_cost/models/mrp_workcenter.py | 3 +- .../models/product_template.py | 4 +- .../models/stock_move_line.py | 229 ++++++------ .../views/killing_cost_view.xml | 44 +-- custom_mrp_line_cost/views/mrp_bom_view.xml | 17 +- .../views/mrp_production_view.xml | 179 +++------- .../views/mrp_routing_workcenter_view.xml | 2 +- .../views/mrp_workcenter_view.xml | 28 +- .../views/mrp_workorder_view.xml | 5 +- .../views/product_template_view.xml | 8 +- .../views/stock_move_line_view.xml | 168 +++------ 19 files changed, 459 insertions(+), 685 deletions(-) diff --git a/custom_mrp_line_cost/__manifest__.py b/custom_mrp_line_cost/__manifest__.py index c782fd2cf..68179e01e 100644 --- a/custom_mrp_line_cost/__manifest__.py +++ b/custom_mrp_line_cost/__manifest__.py @@ -7,7 +7,7 @@ "category": "MRP", "license": "AGPL-3", "author": "AvanzOSC", - "website": "https://github.com/avanzosc/mrp-addons", + "website": "http://www.avanzosc.es", "depends": [ "mrp", "mrp_bom_line_coef", diff --git a/custom_mrp_line_cost/data/mrp_standar_price_decimal_precision.xml b/custom_mrp_line_cost/data/mrp_standar_price_decimal_precision.xml index 575fb9931..538f0e483 100644 --- a/custom_mrp_line_cost/data/mrp_standar_price_decimal_precision.xml +++ b/custom_mrp_line_cost/data/mrp_standar_price_decimal_precision.xml @@ -1,4 +1,3 @@ - MRP Price Decimal Precision @@ -9,3 +8,4 @@ 3 + 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 2a8352496..fe224bf41 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-02-20 11:29+0000\n" -"PO-Revision-Date: 2024-02-20 11:29+0000\n" +"POT-Creation-Date: 2024-07-02 06:20+0000\n" +"PO-Revision-Date: 2024-07-02 06:20+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -87,6 +87,16 @@ msgstr "" msgid "Canal Cost" msgstr "" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__clean_qty +msgid "Clean" +msgstr "" + +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__clean_performance +msgid "Clean Performance" +msgstr "" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom_byproduct__coefficient msgid "Coefficient" @@ -156,6 +166,7 @@ msgstr "" #. module: custom_mrp_line_cost #: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 +#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.production_move_line_ids_tree_view #, python-format @@ -297,6 +308,7 @@ msgstr "" #. module: custom_mrp_line_cost #: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 +#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.production_finished_move_line_ids_tree_view #, python-format @@ -335,12 +347,6 @@ msgstr "" msgid "Price Difference" msgstr "" -#. module: custom_mrp_line_cost -#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 -#, python-format -msgid "Produced Move Lines" -msgstr "" - #. module: custom_mrp_line_cost #: model:ir.model,name:custom_mrp_line_cost.model_stock_move_line msgid "Product Moves (Stock Move Line)" @@ -377,6 +383,11 @@ msgstr "" msgid "Purchase Unit Price" msgstr "" +#. module: custom_mrp_line_cost +#: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view +msgid "Recalculate Costs" +msgstr "" + #. module: custom_mrp_line_cost #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view msgid "Rto. %" diff --git a/custom_mrp_line_cost/i18n/es.po b/custom_mrp_line_cost/i18n/es.po index 2975aabd6..b3f86bd93 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-02-20 11:30+0000\n" -"PO-Revision-Date: 2024-02-20 11:30+0000\n" +"POT-Creation-Date: 2024-07-02 06:21+0000\n" +"PO-Revision-Date: 2024-07-02 06:21+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -87,6 +87,16 @@ msgstr "Peso medio canal" msgid "Canal Cost" msgstr "Coste canal" +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__clean_qty +msgid "Clean" +msgstr "Limpio" + +#. module: custom_mrp_line_cost +#: model:ir.model.fields,field_description:custom_mrp_line_cost.field_stock_move_line__clean_performance +msgid "Clean Performance" +msgstr "Rendimiento limpio" + #. module: custom_mrp_line_cost #: model:ir.model.fields,field_description:custom_mrp_line_cost.field_mrp_bom_byproduct__coefficient msgid "Coefficient" @@ -156,6 +166,7 @@ msgstr "Nombre mostrado" #. module: custom_mrp_line_cost #: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 +#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.production_move_line_ids_tree_view #, python-format @@ -297,6 +308,7 @@ msgstr "Importe total de salidas" #. module: custom_mrp_line_cost #: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 +#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.production_finished_move_line_ids_tree_view #, python-format @@ -335,12 +347,6 @@ msgstr "Albaranes por hacer" msgid "Price Difference" msgstr "Diferencia" -#. module: custom_mrp_line_cost -#: code:addons/custom_mrp_line_cost/models/mrp_production.py:0 -#, python-format -msgid "Produced Move Lines" -msgstr "Operaciones creadas" - #. module: custom_mrp_line_cost #: model:ir.model,name:custom_mrp_line_cost.model_stock_move_line msgid "Product Moves (Stock Move Line)" @@ -377,6 +383,11 @@ msgstr "Importe de compra" msgid "Purchase Unit Price" msgstr "Precio unitario" +#. module: custom_mrp_line_cost +#: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view +msgid "Recalculate Costs" +msgstr "Recalcular costes" + #. module: custom_mrp_line_cost #: model_terms:ir.ui.view,arch_db:custom_mrp_line_cost.mrp_production_form_view msgid "Rto. %" diff --git a/custom_mrp_line_cost/models/killing_cost.py b/custom_mrp_line_cost/models/killing_cost.py index 86be13755..4add677c3 100644 --- a/custom_mrp_line_cost/models/killing_cost.py +++ b/custom_mrp_line_cost/models/killing_cost.py @@ -9,53 +9,40 @@ class KillingCost(models.Model): workcenter_id = fields.Many2one( string="Workcenter", - comodel_name="mrp.workcenter", - ) + comodel_name="mrp.workcenter") january = fields.Float( string="January", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") february = fields.Float( string="February", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") march = fields.Float( string="March", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") april = fields.Float( string="April", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") may = fields.Float( string="May", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") june = fields.Float( string="June", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") july = fields.Float( string="July", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") august = fields.Float( string="August", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") september = fields.Float( string="September", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") october = fields.Float( string="October", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") november = fields.Float( string="November", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") december = fields.Float( string="December", - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") diff --git a/custom_mrp_line_cost/models/mrp_bom.py b/custom_mrp_line_cost/models/mrp_bom.py index 9ed0cd7f3..7531f8b26 100644 --- a/custom_mrp_line_cost/models/mrp_bom.py +++ b/custom_mrp_line_cost/models/mrp_bom.py @@ -9,12 +9,10 @@ class MrpBom(models.Model): pallet_id = fields.Many2one( string="Pallet", comodel_name="product.product", - domain="[('palet', '=', True)]", - ) + domain="[('palet', '=', True)]") packaging_id = fields.Many2one( string="Packaging", - comodel_name="product.product", - ) + comodel_name="product.product") @api.model def name_search(self, name="", args=None, operator="ilike", limit=100): @@ -24,11 +22,9 @@ def name_search(self, name="", args=None, operator="ilike", limit=100): if not name: return result my_name = "%{}%".format(name) - cond = [ - "|", - ("product_tmpl_id", operator, my_name), - ("code", operator, my_name), - ] + cond = ["|", + ("product_tmpl_id", operator, my_name), + ("code", operator, my_name)] boms = self.sudo().search(cond) for bom in boms: found = False @@ -37,10 +33,9 @@ def name_search(self, name="", args=None, operator="ilike", limit=100): found = True break if not found: - result.append( - ( - bom.id, - "{}: {}".format(bom.code, bom.product_tmpl_id.display_name), - ) + result.append(( + bom.id, "{}: {}".format( + bom.code, bom.product_tmpl_id.display_name + )) ) return result diff --git a/custom_mrp_line_cost/models/mrp_bom_byproduct.py b/custom_mrp_line_cost/models/mrp_bom_byproduct.py index 4e5a4b93c..2ecadd401 100644 --- a/custom_mrp_line_cost/models/mrp_bom_byproduct.py +++ b/custom_mrp_line_cost/models/mrp_bom_byproduct.py @@ -6,6 +6,10 @@ class MrpBomByproduct(models.Model): _inherit = "mrp.bom.byproduct" - coefficient = fields.Float(string="Coefficient") - expense_kg = fields.Boolean(string="Production Cost", default=False) - cost = fields.Float(string="Fixed Price") + coefficient = fields.Float( + string="Coefficient") + expense_kg = fields.Boolean( + string="Production Cost", + default=False) + cost = fields.Float( + string="Fixed Price") diff --git a/custom_mrp_line_cost/models/mrp_production.py b/custom_mrp_line_cost/models/mrp_production.py index 11cfa193b..d1a9f38f2 100644 --- a/custom_mrp_line_cost/models/mrp_production.py +++ b/custom_mrp_line_cost/models/mrp_production.py @@ -1,92 +1,89 @@ # Copyright 2022 Berezi Amubieta - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import _, api, fields, models +from odoo import _, api, exceptions, fields, models class MrpProduction(models.Model): _inherit = "mrp.production" - origin_qty = fields.Float(string="Origin Kg") - dest_qty = fields.Float(string="Dest Kg") - purchase_price = fields.Float(string="Purchase Amount") - purchase_unit_price = fields.Float(string="Purchase Unit Price") + origin_qty = fields.Float( + string="Origin Kg") + dest_qty = fields.Float( + string="Dest Kg") + purchase_price = fields.Float( + string="Purchase Amount") + purchase_unit_price = fields.Float( + string="Purchase Unit Price") price_difference = fields.Float( string="Price Difference", - ) + ) canal_weight = fields.Float( string="Canal Average Weight", compute="_compute_canal_weight", store=True, - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") rto_canal = fields.Float( string="Rto. Canal", compute="_compute_rto_canal", - store=True, - ) + store=True) canal_cost = fields.Float( string="Canal Cost", digits="Killing Cost Decimal Precision", compute="_compute_canal_cost", - store=True, - ) + store=True) currency_id = fields.Many2one( string="Currency", comodel_name="res.currency", - default=lambda self: self.env.company.currency_id.id, - ) + default=lambda self: self.env.company.currency_id.id) month_cost = fields.Float( string="Expense/kg", digits="Killing Cost Decimal Precision", compute="_compute_month_cost", - store=True, - ) + store=True + ) move_to_do_ids = fields.Many2many( string="Moves To Do", comodel_name="stock.move", - compute="_compute_move_to_do_ids", - ) + compute="_compute_move_to_do_ids" + ) move_line_to_do_ids = fields.Many2many( string="Move Lines To Do", comodel_name="stock.move.line", - compute="_compute_move_line_to_do_ids", - ) + compute="_compute_move_line_to_do_ids" + ) picking_to_do_ids = fields.Many2many( string="Pickings To Do", comodel_name="stock.picking", - compute="_compute_picking_to_do_ids", - ) + compute="_compute_picking_to_do_ids" + ) pallet_id = fields.Many2one( string="Pallet", comodel_name="product.product", related="bom_id.pallet_id", - store=True, - ) + store=True) packaging_id = fields.Many2one( string="Packaging", comodel_name="product.product", related="bom_id.packaging_id", - store=True, - ) + store=True) average_cost = fields.Float( string="Averga Cost", compute="_compute_average_cost", - store=True, - ) + store=True) cost = fields.Float( string="Cost", compute="_compute_cost", - store=True, - ) + store=True) 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") + store=True) + output_total_amount = fields.Float( + string="Output Total Amount") consume_qty = fields.Float( - string="Consumed Qty", compute="_compute_consume_qty", store=True - ) + string="Consumed Qty", + compute="_compute_consume_qty", + store=True) @api.depends("move_line_ids.qty_done") def _compute_consume_qty(self): @@ -101,15 +98,15 @@ def _compute_consume_qty(self): def _compute_cost(self): for production in self: production.cost = production.purchase_price + ( - production.month_cost * production.origin_qty - ) + production.month_cost * production.origin_qty) @api.depends("move_line_ids.amount") 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( + self.move_line_ids.mapped("amount")) line.entry_total_amount = entry_total_amount @api.depends("finished_move_line_ids.amount") @@ -118,106 +115,106 @@ def _compute_output_total_amount(self): output_total_amount = 0 if production.finished_move_line_ids: output_total_amount = sum( - production.finished_move_line_ids.mapped("amount") - ) + production.finished_move_line_ids.mapped("amount")) production.output_total_amount = output_total_amount - @api.depends("move_line_ids.qty_done", "move_line_ids.amount") + @api.depends("move_line_ids.qty_done", + "move_line_ids.amount") def _compute_average_cost(self): for line in self: average_cost = 0 - if ( - sum( - line.move_line_ids.filtered( - lambda c: c.location_id == line.location_src_id - ).mapped("qty_done") - ) - != 0 - ): + if sum(line.move_line_ids.filtered( + lambda c: c.location_id == line.location_src_id).mapped( + "qty_done")) != 0: average_cost = sum( line.move_line_ids.filtered( - lambda c: c.location_id == line.location_src_id - ).mapped("amount") - ) / sum( - line.move_line_ids.filtered( - lambda c: c.location_id == line.location_src_id - ).mapped("qty_done") - ) + lambda c: c.location_id == ( + line.location_src_id)).mapped("amount")) / sum( + line.move_line_ids.filtered( + lambda c: c.location_id == ( + line.location_src_id)).mapped( + "qty_done")) line.average_cost = average_cost def _compute_move_to_do_ids(self): for production in self: - domain = [ - ("state", "not in", ("done", "cancel")), - ("date", ">=", production.date_planned_start), - ("picking_code", "=", "outgoing"), - ] + domain = [("state", "not in", ("done", "cancel")), + ("date", ">=", production.date_planned_start), + ("picking_code", "=", "outgoing")] production.move_to_do_ids = self.env["stock.move"].search(domain) def _compute_move_line_to_do_ids(self): for production in self: - domain = [ - ("state", "not in", ("done", "cancel")), - ("date", ">=", production.date_planned_start), - ("picking_code", "=", "outgoing"), - ] - production.move_line_to_do_ids = self.env["stock.move.line"].search(domain) + domain = [("state", "not in", ("done", "cancel")), + ("date", ">=", production.date_planned_start), + ("picking_code", "=", "outgoing")] + production.move_line_to_do_ids = ( + self.env["stock.move.line"].search(domain)) def _compute_picking_to_do_ids(self): for production in self: - domain = [ - ("state", "not in", ("done", "cancel")), - ("scheduled_date", ">=", production.date_planned_start), - ("picking_type_code", "=", "outgoing"), - ] - production.picking_to_do_ids = self.env["stock.picking"].search(domain) + domain = [("state", "not in", ("done", "cancel")), + ("scheduled_date", ">=", production.date_planned_start), + ("picking_type_code", "=", "outgoing")] + production.picking_to_do_ids = ( + self.env["stock.picking"].search(domain)) - @api.depends( - "workorder_ids", - "workorder_ids.workcenter_id", - "workorder_ids.workcenter_id.cost_ids.january", - "workorder_ids.workcenter_id.cost_ids.february", - "workorder_ids.workcenter_id.cost_ids.march", - "workorder_ids.workcenter_id.cost_ids.april", - "workorder_ids.workcenter_id.cost_ids.may", - "workorder_ids.workcenter_id.cost_ids.june", - "workorder_ids.workcenter_id.cost_ids.july", - "workorder_ids.workcenter_id.cost_ids.august", - "workorder_ids.workcenter_id.cost_ids.september", - "workorder_ids.workcenter_id.cost_ids.october", - "workorder_ids.workcenter_id.cost_ids.november", - "workorder_ids.workcenter_id.cost_ids.december", - "date_planned_start", - ) + @api.depends("workorder_ids", "workorder_ids.workcenter_id", + "workorder_ids.workcenter_id.cost_ids.january", + "workorder_ids.workcenter_id.cost_ids.february", + "workorder_ids.workcenter_id.cost_ids.march", + "workorder_ids.workcenter_id.cost_ids.april", + "workorder_ids.workcenter_id.cost_ids.may", + "workorder_ids.workcenter_id.cost_ids.june", + "workorder_ids.workcenter_id.cost_ids.july", + "workorder_ids.workcenter_id.cost_ids.august", + "workorder_ids.workcenter_id.cost_ids.september", + "workorder_ids.workcenter_id.cost_ids.october", + "workorder_ids.workcenter_id.cost_ids.november", + "workorder_ids.workcenter_id.cost_ids.december", + "date_planned_start") def _compute_month_cost(self): for line in self: month_cost = 0 if line.date_planned_start and line.workorder_ids: month = line.date_planned_start.month if month == 1: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.january + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.january) if month == 2: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.february + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.february) if month == 3: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.march + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.march) if month == 4: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.april + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.april) if month == 5: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.may + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.may) if month == 6: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.june + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.june) if month == 7: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.july + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.july) if month == 8: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.august + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.august) if month == 9: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.september + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.september + ) if month == 10: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.october + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.october) if month == 11: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.november + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.november) if month == 12: - month_cost = line.workorder_ids[:1].workcenter_id.cost_ids.december + month_cost = ( + line.workorder_ids[:1].workcenter_id.cost_ids.december) line.month_cost = month_cost def button_mark_done(self): @@ -230,106 +227,102 @@ def button_calculate_costs(self): for production in self: qty = [] lots = [] - if production.is_deconstruction and (production.move_line_ids): + if production.is_deconstruction and ( + production.move_line_ids): for line in production.move_line_ids: line.onchange_applied_price() if not line.move_id: line.move_id = production.move_raw_ids.filtered( - lambda c: c.product_id == line.product_id - )[:1].id + lambda c: c.product_id == line.product_id)[:1].id if line.lot_id and line.lot_id not in lots: lots.append(line.lot_id) qty.append( - sum( - production.move_line_ids.filtered( - lambda c: c.lot_id == line.lot_id - ).mapped("qty_done") - ) - ) + sum(production.move_line_ids.filtered( + lambda c: c.lot_id == line.lot_id).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") - ) + 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 - and production.finished_move_line_ids - ): + elif not production.is_deconstruction and ( + production.average_cost) and ( + production.finished_move_line_ids): for line in production.finished_move_line_ids: line.applied_price = line.base_price line.standard_price = line.applied_price - dif = ( - (production.average_cost + production.month_cost) - * production.consume_qty - ) - sum(production.finished_move_line_ids.mapped("amount")) + dif = (( + production.average_cost + production.month_cost + ) * production.consume_qty) - sum( + production.finished_move_line_ids.mapped("amount") + ) if dif != 0: for line in production.finished_move_line_ids: if line.lot_id and line.lot_id not in lots: lots.append(line.lot_id) qty.append( - sum( - production.finished_move_line_ids.filtered( - lambda c: c.lot_id == line.lot_id - ).mapped("qty_done") - ) - ) + sum(production.finished_move_line_ids.filtered( + lambda c: c.lot_id == line.lot_id).mapped( + "qty_done"))) i = qty.index(max(qty)) if i: max_lot = lots[i] max_qty = qty[i] if max_lot and max_qty: - lot_lines = production.finished_move_line_ids.filtered( - lambda c: c.lot_id == max_lot - ) + lot_lines = ( + production.finished_move_line_ids.filtered( + lambda c: c.lot_id == max_lot)) amount = dif + 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() - @api.depends("move_line_ids.canal", "move_line_ids.qty_done") + @api.depends("move_line_ids.canal", + "move_line_ids.qty_done") def _compute_canal_weight(self): for line in self: canal_weight = 0 - canal_lines = line.move_line_ids.filtered(lambda c: c.canal is True) + canal_lines = line.move_line_ids.filtered( + lambda c: c.canal is True) canal_weight = sum(canal_lines.mapped("qty_done")) canal_unit = sum(canal_lines.mapped("unit")) if canal_unit != 0: canal_weight = canal_weight / canal_unit line.canal_weight = canal_weight - @api.depends("move_line_ids.canal", "move_line_ids.percentage") + @api.depends("move_line_ids.canal", + "move_line_ids.percentage") def _compute_rto_canal(self): for line in self: rto_canal = 0 - canal_lines = line.move_line_ids.filtered(lambda c: c.canal is True) + canal_lines = line.move_line_ids.filtered( + lambda c: c.canal is True) if canal_lines: rto_canal = sum(canal_lines.mapped("percentage")) line.rto_canal = rto_canal - @api.depends( - "move_line_ids.canal", "move_line_ids.qty_done", "move_line_ids.amount" - ) + @api.depends("move_line_ids.canal", + "move_line_ids.qty_done", "move_line_ids.amount") def _compute_canal_cost(self): for line in self: canal_cost = 0 if line.move_line_ids: - canal_lines = line.move_line_ids.filtered(lambda c: c.canal is True) + canal_lines = line.move_line_ids.filtered( + lambda c: c.canal is True) if canal_lines and sum(canal_lines.mapped("weight")) != 0: - canal_cost = sum(canal_lines.mapped("amount")) / sum( - canal_lines.mapped("qty_done") - ) + canal_cost = sum( + canal_lines.mapped("amount"))/sum( + canal_lines.mapped("qty_done")) line.canal_cost = canal_cost def action_view_move_to_do(self): @@ -340,7 +333,7 @@ def action_view_move_to_do(self): "res_model": "stock.move", "domain": [("id", "in", self.move_to_do_ids.ids)], "type": "ir.actions.act_window", - "context": context, + "context": context } def action_view_move_line_to_do(self): @@ -351,7 +344,7 @@ def action_view_move_line_to_do(self): "res_model": "stock.move.line", "domain": [("id", "in", self.move_line_to_do_ids.ids)], "type": "ir.actions.act_window", - "context": context, + "context": context } def action_view_picking_to_do(self): @@ -362,20 +355,18 @@ def action_view_picking_to_do(self): "res_model": "stock.picking", "domain": [("id", "in", self.picking_to_do_ids.ids)], "type": "ir.actions.act_window", - "context": context, + "context": context } def action_view_finished_move_line_ids(self): context = self.env.context.copy() - context.update( - { - "default_production_id": self.id, - "default_location_id": self.production_location_id.id, - "default_location_dest_id": self.location_dest_id.id, - "default_company_id": self.company_id.id, - "company_id": self.company_id.id, - } - ) + context.update({ + "default_production_id": self.id, + "default_location_id": self.production_location_id.id, + "default_location_dest_id": self.location_dest_id.id, + "default_company_id": self.company_id.id, + "company_id": self.company_id.id, + }) return { "name": _("Outputs"), "view_mode": "tree", @@ -385,21 +376,19 @@ def action_view_finished_move_line_ids(self): "res_model": "stock.move.line", "domain": [("id", "in", self.finished_move_line_ids.ids)], "type": "ir.actions.act_window", - "context": context, + "context": context } def action_view_move_line_ids(self): context = self.env.context.copy() - context.update( - { - "production_id": self.id, - "default_production_id": self.id, - "location_id": self.location_src_id.id, - "location_dest_id": self.production_location_id.id, - "company_id": self.company_id.id, - "default_company_id": self.company_id.id, - } - ) + context.update({ + "production_id": self.id, + "default_production_id": self.id, + "location_id": self.location_src_id.id, + "location_dest_id": self.production_location_id.id, + "company_id": self.company_id.id, + "default_company_id": self.company_id.id, + }) return { "name": _("Entries"), "view_mode": "tree", @@ -409,5 +398,5 @@ def action_view_move_line_ids(self): "res_model": "stock.move.line", "domain": [("id", "in", self.move_line_ids.ids)], "type": "ir.actions.act_window", - "context": context, + "context": context } diff --git a/custom_mrp_line_cost/models/mrp_workcenter.py b/custom_mrp_line_cost/models/mrp_workcenter.py index a0012755a..0bace4bd1 100644 --- a/custom_mrp_line_cost/models/mrp_workcenter.py +++ b/custom_mrp_line_cost/models/mrp_workcenter.py @@ -9,5 +9,4 @@ class MrpWorkcenter(models.Model): cost_ids = fields.One2many( string="Workcenter Costs", comodel_name="killing.cost", - inverse_name="workcenter_id", - ) + inverse_name="workcenter_id") diff --git a/custom_mrp_line_cost/models/product_template.py b/custom_mrp_line_cost/models/product_template.py index 7f84e3f7e..814f87d90 100644 --- a/custom_mrp_line_cost/models/product_template.py +++ b/custom_mrp_line_cost/models/product_template.py @@ -8,4 +8,6 @@ class ProductTemplate(models.Model): canal = fields.Boolean(string="Canal", default=False) unit_container = fields.Integer(string="Unit/Container") - palet = fields.Boolean(string="Is Palet", default=False) + palet = fields.Boolean( + string="Is Palet", + default=False) diff --git a/custom_mrp_line_cost/models/stock_move_line.py b/custom_mrp_line_cost/models/stock_move_line.py index a54ab0b4a..c06ceb9ca 100644 --- a/custom_mrp_line_cost/models/stock_move_line.py +++ b/custom_mrp_line_cost/models/stock_move_line.py @@ -9,11 +9,8 @@ class StockMoveLine(models.Model): def _default_pallet_id(self): if "default_production_id" in self.env.context: - result = ( - self.env["mrp.production"] - .browse(self.env.context.get("default_production_id")) - .pallet_id.id - ) + result = self.env["mrp.production"].browse( + self.env.context.get("default_production_id")).pallet_id.id else: result = False return result @@ -23,149 +20,123 @@ def _default_pallet_id(self): product_unit_container = fields.Integer( string="Product Unit/Container", related="product_id.unit_container", - store=True, - ) + store=True) unit_container = fields.Float( - string="Unit/Container", - ) + string="Unit/Container") weight = fields.Float( string="Weight", compute="_compute_weight", store=True, - digits="Killing Cost Decimal Precision", - ) + digits="Killing Cost Decimal Precision") percentage = fields.Float( string="%", compute="_compute_percentage", store=True, - digits="MRP Price Decimal Precision", - ) + digits="MRP Price Decimal Precision") base_price = fields.Float( string="Base Price", digits="MRP Price Decimal Precision", compute="_compute_base_price", - store=True, - ) + store=True) applied_price = fields.Float( string="Applied Price", - digits="MRP Price Decimal Precision", - ) + digits="MRP Price Decimal Precision") expense_kg = fields.Boolean( string="Cost/Kgm", compute="_compute_expense_kg", - store=True, - ) + store=True) canal = fields.Boolean( string="Canal", related="product_id.canal", - store=True, - ) + store=True) brut = fields.Float( - string="Brut", - ) + string="Brut") pallet = fields.Integer( - string="Pallet Qty", - ) + string="Pallet Qty") month_cost = fields.Float( string="Month Cost", compute="_compute_month_cost", - store=True, - ) + store=True) pallet_id = fields.Many2one( string="Pallet", comodel_name="product.product", default=_default_pallet_id, - domain="[('palet', '=', True)]", + domain="[('palet', '=', True)]") + clean_qty = fields.Float( + string="Clean", ) - - @api.depends( - "production_id", - "production_id.date_planned_start", - "move_id", - "move_id.bom_line_id", - "move_id.bom_line_id.operation_id", - "move_id.bom_line_id.operation_id.workcenter_id", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.january", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.february", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.march", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.april", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.may", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.june", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.july", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.august", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.september", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.october", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.november", - "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.december", + clean_performance = fields.Float( + string="Clean Performance", + compute="_compute_clean_performance", + store=True ) + + @api.depends("production_id", "production_id.move_line_ids", + "production_id.move_line_ids.clean_qty", + "production_id.move_line_ids.qty_done") + def _compute_clean_performance(self): + for line in self: + clean_performance = 0 + if line.production_id and sum( + line.production_id.move_line_ids.mapped("clean_qty") + ) != 0: + clean_performance = line.qty_done / sum(line.production_id.move_line_ids.mapped("clean_qty")) + line.clean_performance = clean_performance + + @api.depends("production_id", "production_id.date_planned_start", + "move_id", "move_id.bom_line_id", + "move_id.bom_line_id.operation_id", + "move_id.bom_line_id.operation_id.workcenter_id", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.january", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.february", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.march", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.april", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.may", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.june", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.july", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.august", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.september", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.october", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.november", + "move_id.bom_line_id.operation_id.workcenter_id.cost_ids.december" + ) def _compute_month_cost(self): for line in self: month_cost = 0 - if ( - line.production_id.date_planned_start - and line.move_id - and line.move_id.byproduct_id - and line.move_id.byproduct_id.operation_id - ): + if line.production_id.date_planned_start and line.move_id and ( + line.move_id.byproduct_id) and ( + line.move_id.byproduct_id.operation_id): month = line.production_id.date_planned_start.month if month == 1: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.january - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.january if month == 2: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.february - ) + month_cost= line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.february if month == 3: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.march - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.march if month == 4: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.april - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.april if month == 5: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.may - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.may if month == 6: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.june - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.june if month == 7: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.july - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.july if month == 8: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.august - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.august if month == 9: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.september - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.september if month == 10: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.october - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.october if month == 11: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.november - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.november if month == 12: - month_cost = ( - line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.december - ) + month_cost = line.move_id.byproduct_id.operation_id.workcenter_id.cost_ids.december line.month_cost = month_cost - @api.depends( - "move_id", - "move_id.bom_line_id", - "move_id.byproduct_id", - "move_id.bom_line_id.expense_kg", - "move_id.byproduct_id.expense_kg", - ) + @api.depends("move_id", "move_id.bom_line_id", "move_id.byproduct_id", + "move_id.bom_line_id.expense_kg", + "move_id.byproduct_id.expense_kg") def _compute_expense_kg(self): for line in self: expense_kg = 0 @@ -175,48 +146,43 @@ def _compute_expense_kg(self): expense_kg = line.move_id.byproduct_id.expense_kg line.expense_kg = expense_kg - @api.depends( - "production_id.purchase_unit_price", - "production_id.average_cost", - "production_id.month_cost", - "production_id.is_deconstruction", - ) + @api.depends("production_id.purchase_unit_price", + "production_id.average_cost", + "production_id.month_cost", + "production_id.is_deconstruction") def _compute_base_price(self): for line in self: cost = 0 if line.production_id and not line.production_id.date_planned_start: - raise ValidationError(_("You must introduce the planned date.")) + raise ValidationError( + _("You must introduce the planned date.")) else: - if ( - line.production_id - and line.move_id.bom_line_id - and line.production_id.is_deconstruction - ): + if line.production_id and ( + line.move_id.bom_line_id) and ( + line.production_id.is_deconstruction): cost = line.move_id.bom_line_id.cost if line.expense_kg: cost = ( - line.production_id.month_cost - + line.production_id.purchase_unit_price - ) * line.move_id.bom_line_id.coefficient + line.production_id.month_cost + ( + line.production_id.purchase_unit_price)) * ( + line.move_id.bom_line_id.coefficient) elif line.production_id and line.move_id.byproduct_id: cost = line.move_id.byproduct_id.cost if line.expense_kg: - entry_same_lots = line.production_id.move_line_ids.filtered( - lambda c: c.lot_id.name == line.lot_id.name - ) - if ( - not entry_same_lots - or sum(entry_same_lots.mapped("qty_done")) == 0 - ): + entry_same_lots = ( + line.production_id.move_line_ids.filtered( + lambda c: c.lot_id.name == line.lot_id.name + ) + ) + if not entry_same_lots or sum(entry_same_lots.mapped("qty_done")) == 0: cost = 0 else: - entry_cost = sum(entry_same_lots.mapped("amount")) / sum( - entry_same_lots.mapped("qty_done") - ) + entry_cost = sum( + entry_same_lots.mapped("amount") + )/sum(entry_same_lots.mapped("qty_done")) cost = ( - line.month_cost - + entry_cost * line.move_id.byproduct_id.coefficient - ) + line.month_cost + entry_cost + ) * (line.move_id.byproduct_id.coefficient) line.base_price = cost if not line.applied_price: line.applied_price = cost @@ -236,17 +202,16 @@ def _compute_percentage(self): for line in self: percentage = 0 if line.production_id.origin_qty != 0: - percentage = line.qty_done * 100 / line.production_id.origin_qty + percentage = ( + line.qty_done * 100 / line.production_id.origin_qty) line.percentage = percentage @api.onchange("brut", "pallet", "container", "pallet_id") def onchange_brut(self): if self.brut: - self.qty_done = ( - self.brut - - (self.pallet * self.pallet_id.weight) - - (self.container * self.production_id.packaging_id.weight) - ) + self.qty_done = self.brut - ( + self.pallet * self.pallet_id.weight) - ( + self.container * self.production_id.packaging_id.weight) @api.onchange("container") def onchange_container(self): diff --git a/custom_mrp_line_cost/views/killing_cost_view.xml b/custom_mrp_line_cost/views/killing_cost_view.xml index cf9c4b06e..e347f9470 100644 --- a/custom_mrp_line_cost/views/killing_cost_view.xml +++ b/custom_mrp_line_cost/views/killing_cost_view.xml @@ -1,23 +1,24 @@ - + + killing.cost.tree killing.cost - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -29,18 +30,9 @@ tree - + - + diff --git a/custom_mrp_line_cost/views/mrp_bom_view.xml b/custom_mrp_line_cost/views/mrp_bom_view.xml index 7b088977e..0934f652a 100644 --- a/custom_mrp_line_cost/views/mrp_bom_view.xml +++ b/custom_mrp_line_cost/views/mrp_bom_view.xml @@ -2,19 +2,16 @@ mrp.bom - + - - + + - - - - + + + + diff --git a/custom_mrp_line_cost/views/mrp_production_view.xml b/custom_mrp_line_cost/views/mrp_production_view.xml index 3b6d78534..8d4f5265f 100644 --- a/custom_mrp_line_cost/views/mrp_production_view.xml +++ b/custom_mrp_line_cost/views/mrp_production_view.xml @@ -2,159 +2,62 @@ mrp.production - +
-
-
-
diff --git a/custom_mrp_line_cost/views/mrp_routing_workcenter_view.xml b/custom_mrp_line_cost/views/mrp_routing_workcenter_view.xml index e01ac0ed7..1f1f91836 100644 --- a/custom_mrp_line_cost/views/mrp_routing_workcenter_view.xml +++ b/custom_mrp_line_cost/views/mrp_routing_workcenter_view.xml @@ -2,7 +2,7 @@ mrp.routing.workcenter - + hide diff --git a/custom_mrp_line_cost/views/mrp_workcenter_view.xml b/custom_mrp_line_cost/views/mrp_workcenter_view.xml index 066f5c471..84b9b8b75 100644 --- a/custom_mrp_line_cost/views/mrp_workcenter_view.xml +++ b/custom_mrp_line_cost/views/mrp_workcenter_view.xml @@ -2,25 +2,25 @@ mrp.workcenter - + - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/custom_mrp_line_cost/views/mrp_workorder_view.xml b/custom_mrp_line_cost/views/mrp_workorder_view.xml index 9352ffa3d..387125791 100644 --- a/custom_mrp_line_cost/views/mrp_workorder_view.xml +++ b/custom_mrp_line_cost/views/mrp_workorder_view.xml @@ -2,10 +2,7 @@ mrp.workorder - + hide diff --git a/custom_mrp_line_cost/views/product_template_view.xml b/custom_mrp_line_cost/views/product_template_view.xml index cb19a7d9d..afff214da 100644 --- a/custom_mrp_line_cost/views/product_template_view.xml +++ b/custom_mrp_line_cost/views/product_template_view.xml @@ -2,12 +2,12 @@ product.template - + - - - + + + 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 e1138e941..3a7d2a27a 100644 --- a/custom_mrp_line_cost/views/stock_move_line_view.xml +++ b/custom_mrp_line_cost/views/stock_move_line_view.xml @@ -2,10 +2,14 @@ stock.move.line - + - + + + + + @@ -15,66 +19,23 @@ stock.move.line - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -84,67 +45,28 @@ stock.move.line - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +