From 72023b8a62ed15ba26a614c9c34d44e0afd2f0c6 Mon Sep 17 00:00:00 2001 From: Oihane Crucelaegui Date: Thu, 27 Jun 2024 14:44:48 +0200 Subject: [PATCH] [IMP] mrp_production_deconstruction: pre-commit stuff --- mrp_production_deconstruction/__manifest__.py | 5 +- .../models/mrp_bom.py | 6 +- .../models/mrp_production.py | 71 +++++---- .../models/stock_move_line.py | 20 +-- .../views/mrp_bom_view.xml | 20 ++- .../views/mrp_production_view.xml | 141 ++++++++++++++---- 6 files changed, 180 insertions(+), 83 deletions(-) diff --git a/mrp_production_deconstruction/__manifest__.py b/mrp_production_deconstruction/__manifest__.py index bfd287a96..0bbce5063 100644 --- a/mrp_production_deconstruction/__manifest__.py +++ b/mrp_production_deconstruction/__manifest__.py @@ -2,8 +2,9 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "MRP Production Deconstruction", - 'version': '14.0.1.0.0', + "version": "14.0.1.0.0", "author": "Avanzosc", + "website": "https://github.com/avanzosc/mrp-addons", "category": "MRP", "depends": [ "mrp", @@ -13,5 +14,5 @@ "views/mrp_bom_view.xml", ], "license": "AGPL-3", - 'installable': True, + "installable": True, } diff --git a/mrp_production_deconstruction/models/mrp_bom.py b/mrp_production_deconstruction/models/mrp_bom.py index b5ff49fcc..61c710154 100644 --- a/mrp_production_deconstruction/models/mrp_bom.py +++ b/mrp_production_deconstruction/models/mrp_bom.py @@ -1,10 +1,12 @@ # Copyright 2022 Berezi Amubieta - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import models, fields +from odoo import fields, models class MrpBom(models.Model): _inherit = "mrp.bom" is_deconstruction = fields.Boolean( - string="Is Deconstruction?", default=False) + string="Is Deconstruction?", + default=False, + ) diff --git a/mrp_production_deconstruction/models/mrp_production.py b/mrp_production_deconstruction/models/mrp_production.py index 4bfa58eb5..2b0bb4d13 100644 --- a/mrp_production_deconstruction/models/mrp_production.py +++ b/mrp_production_deconstruction/models/mrp_production.py @@ -1,6 +1,6 @@ # Copyright 2022 Berezi Amubieta - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, models, fields +from odoo import api, fields, models class MrpProduction(models.Model): @@ -9,30 +9,33 @@ class MrpProduction(models.Model): is_deconstruction = fields.Boolean( string="Is Deconstruction?", related="bom_id.is_deconstruction", - store=True) + store=True, + ) move_line_ids = fields.One2many( string="Move Lines", comodel_name="stock.move.line", inverse_name="production_id", domain=lambda self: [ - ("location_dest_id", "in", self.production_location_id.ids)], - ) + ("location_dest_id", "in", self.production_location_id.ids) + ], + ) finished_move_line_ids = fields.One2many( compute=False, inverse_name="production_id", domain=lambda self: [ ("location_id", "in", self.production_location_id.ids), - ("location_dest_id", "in", self.location_dest_id.ids)], - ) + ("location_dest_id", "in", self.location_dest_id.ids), + ], + ) - @api.depends('product_id', 'company_id', "is_deconstruction") + @api.depends("product_id", "company_id", "is_deconstruction") def _compute_production_location(self): super(MrpProduction, self)._compute_production_location() for production in self: if production.is_deconstruction: production.production_location_id = ( - production.picking_type_id.default_location_src_id.id) or ( - False) + production.picking_type_id.default_location_src_id.id + ) or (False) def write(self, vals): res = super(MrpProduction, self).write(vals) @@ -46,28 +49,39 @@ def write(self, vals): def _check_is_deconstruction(self): for production in self: - if production.bom_id and ( - production.is_deconstruction) is True and ( - production.move_raw_ids): + if ( + production.bom_id + and production.is_deconstruction is True + and production.move_raw_ids + ): origin = production.picking_type_id.default_location_src_id if origin.usage != "internal" and ( - production.production_location_id.usage) == ( - "internal"): + production.production_location_id.usage == "internal" + ): origin = production.production_location_id dest = production.move_raw_ids.location_dest_id if dest.usage == "production": - production.write({ - "location_dest_id": dest.id, - "location_src_id": dest.id, - "production_location_id": origin.id}) + production.write( + { + "location_dest_id": dest.id, + "location_src_id": dest.id, + "production_location_id": origin.id, + } + ) for move in production.move_raw_ids: - move.write({ - "location_id": dest.id, - "location_dest_id": origin.id}) - for line in move.move_line_ids: - line.write({ + move.write( + { "location_id": dest.id, - "location_dest_id": origin.id}) + "location_dest_id": origin.id, + } + ) + for line in move.move_line_ids: + line.write( + { + "location_id": dest.id, + "location_dest_id": origin.id, + } + ) def action_confirm(self): self._check_is_deconstruction() @@ -79,7 +93,10 @@ def button_mark_done(self): if production.is_deconstruction is True: origin = production.finished_move_line_ids.location_id dest = production.finished_move_line_ids.location_dest_id - production.finished_move_line_ids.write({ - "location_id": dest.id, - "location_dest_id": origin.id}) + production.finished_move_line_ids.write( + { + "location_id": dest.id, + "location_dest_id": origin.id, + } + ) return result diff --git a/mrp_production_deconstruction/models/stock_move_line.py b/mrp_production_deconstruction/models/stock_move_line.py index 2307ae640..998c6e8ad 100644 --- a/mrp_production_deconstruction/models/stock_move_line.py +++ b/mrp_production_deconstruction/models/stock_move_line.py @@ -1,6 +1,6 @@ # Copyright 2022 Berezi Amubieta - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import _, api, models, fields +from odoo import api, fields, models class StockMoveLine(models.Model): @@ -28,10 +28,8 @@ def _get_default_location_dest_id(self): result = production.picking_type_id.default_location_src_id.id return result - location_id = fields.Many2one( - default=_get_default_location_id) - location_dest_id = fields.Many2one( - default=_get_default_location_dest_id) + location_id = fields.Many2one(default=_get_default_location_id) + location_dest_id = fields.Many2one(default=_get_default_location_dest_id) @api.onchange("location_id", "location_dest_id") def onchange_product_id_domain(self): @@ -42,13 +40,9 @@ def onchange_product_id_domain(self): [("id", "=", production)], limit=1 ) domain = {} - if production.is_deconstruction is not True and ( - production.move_raw_ids - ): + if production.is_deconstruction is not True and (production.move_raw_ids): products = production.move_raw_ids.mapped("product_id") - domain = {"domain": {"product_id": [ - ("id", "in", products.ids) - ]}} + domain = {"domain": {"product_id": [("id", "in", products.ids)]}} elif "default_production_id" in self.env.context: production = self.env.context["default_production_id"] production = self.env["mrp.production"].search( @@ -57,7 +51,5 @@ def onchange_product_id_domain(self): domain = {} if production.move_byproduct_ids: products = production.move_byproduct_ids.mapped("product_id") - domain = {"domain": {"product_id": [ - ("id", "in", products.ids) - ]}} + domain = {"domain": {"product_id": [("id", "in", products.ids)]}} return domain diff --git a/mrp_production_deconstruction/views/mrp_bom_view.xml b/mrp_production_deconstruction/views/mrp_bom_view.xml index 7d66722cc..667bef786 100644 --- a/mrp_production_deconstruction/views/mrp_bom_view.xml +++ b/mrp_production_deconstruction/views/mrp_bom_view.xml @@ -1,26 +1,32 @@ - + mrp.bom - + - + - {'invisible': [('is_deconstruction', '=', True)]} + {'invisible': [('is_deconstruction', '=', True)]} mrp.bom - + - - + + diff --git a/mrp_production_deconstruction/views/mrp_production_view.xml b/mrp_production_deconstruction/views/mrp_production_view.xml index 0b54e91c6..bdf4c8726 100644 --- a/mrp_production_deconstruction/views/mrp_production_view.xml +++ b/mrp_production_deconstruction/views/mrp_production_view.xml @@ -1,35 +1,90 @@ - + mrp.production - + - + - {'column_invisible':[('parent.is_deconstruction', '=', True)]} + {'column_invisible':[('parent.is_deconstruction', '=', True)]} - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -39,28 +94,52 @@ mrp.production - + - + mrp.production - + - - + + - - - - - + + + + +