From 7bad3c8dc8554997afc6d48c9923a3876f2f0df3 Mon Sep 17 00:00:00 2001 From: Tu Nombre Date: Tue, 2 Jul 2024 10:08:25 +0200 Subject: [PATCH] [16.0][MIG] mrp_production_deconstruction: Migration to 16.0 --- mrp_production_deconstruction/README.rst | 2 +- mrp_production_deconstruction/__manifest__.py | 4 +- .../models/mrp_bom.py | 6 +- .../models/mrp_production.py | 74 ++++----- .../models/stock_move_line.py | 20 ++- .../views/mrp_bom_view.xml | 20 +-- .../views/mrp_production_view.xml | 141 ++++-------------- .../odoo/addons/mrp_production_deconstruction | 1 + setup/mrp_production_deconstruction/setup.py | 6 + 9 files changed, 93 insertions(+), 181 deletions(-) create mode 120000 setup/mrp_production_deconstruction/odoo/addons/mrp_production_deconstruction create mode 100644 setup/mrp_production_deconstruction/setup.py diff --git a/mrp_production_deconstruction/README.rst b/mrp_production_deconstruction/README.rst index b4c68e928..bb4f97174 100644 --- a/mrp_production_deconstruction/README.rst +++ b/mrp_production_deconstruction/README.rst @@ -6,7 +6,7 @@ MPR Production Deconstruction ============================== -Deconstruction in production order. If is a deconstruction, it changes the location and the destination location. +Deconstruction in production order. If is a deconstruction, it changes the source location and the destination location. Bug Tracker =========== diff --git a/mrp_production_deconstruction/__manifest__.py b/mrp_production_deconstruction/__manifest__.py index 0bbce5063..2badeb5ef 100644 --- a/mrp_production_deconstruction/__manifest__.py +++ b/mrp_production_deconstruction/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "MRP Production Deconstruction", - "version": "14.0.1.0.0", + 'version': '16.0.1.0.0', "author": "Avanzosc", "website": "https://github.com/avanzosc/mrp-addons", "category": "MRP", @@ -14,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 61c710154..b5ff49fcc 100644 --- a/mrp_production_deconstruction/models/mrp_bom.py +++ b/mrp_production_deconstruction/models/mrp_bom.py @@ -1,12 +1,10 @@ # Copyright 2022 Berezi Amubieta - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import models, fields 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 2b0bb4d13..9fdef93ad 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, fields, models +from odoo import api, models, fields class MrpProduction(models.Model): @@ -9,33 +9,31 @@ 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() + result = 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) + return result def write(self, vals): res = super(MrpProduction, self).write(vals) @@ -49,39 +47,28 @@ 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, - } - ) + move.write({ + "location_id": dest.id, + "location_dest_id": origin.id}) for line in move.move_line_ids: - line.write( - { - "location_id": dest.id, - "location_dest_id": origin.id, - } - ) + line.write({ + "location_id": dest.id, + "location_dest_id": origin.id}) def action_confirm(self): self._check_is_deconstruction() @@ -93,10 +80,7 @@ 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 998c6e8ad..2307ae640 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, fields, models +from odoo import _, api, models, fields class StockMoveLine(models.Model): @@ -28,8 +28,10 @@ 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): @@ -40,9 +42,13 @@ 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( @@ -51,5 +57,7 @@ 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 667bef786..7d66722cc 100644 --- a/mrp_production_deconstruction/views/mrp_bom_view.xml +++ b/mrp_production_deconstruction/views/mrp_bom_view.xml @@ -1,32 +1,26 @@ - + 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 bdf4c8726..f789a78c5 100644 --- a/mrp_production_deconstruction/views/mrp_production_view.xml +++ b/mrp_production_deconstruction/views/mrp_production_view.xml @@ -1,90 +1,35 @@ - + mrp.production - + - + - {'column_invisible':[('parent.is_deconstruction', '=', True)]} + {'column_invisible':[('parent.is_deconstruction', '=', True)]} - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -94,52 +39,28 @@ mrp.production - + - + mrp.production - + - - + + - - - - - + + + + + diff --git a/setup/mrp_production_deconstruction/odoo/addons/mrp_production_deconstruction b/setup/mrp_production_deconstruction/odoo/addons/mrp_production_deconstruction new file mode 120000 index 000000000..fc7692cfb --- /dev/null +++ b/setup/mrp_production_deconstruction/odoo/addons/mrp_production_deconstruction @@ -0,0 +1 @@ +../../../../mrp_production_deconstruction \ No newline at end of file diff --git a/setup/mrp_production_deconstruction/setup.py b/setup/mrp_production_deconstruction/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_production_deconstruction/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)