diff --git a/mrp_production_deconstruction/README.rst b/mrp_production_deconstruction/README.rst new file mode 100644 index 000000000..bb4f97174 --- /dev/null +++ b/mrp_production_deconstruction/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================== +MPR Production Deconstruction +============================== + +Deconstruction in production order. If is a deconstruction, it changes the source location and the destination location. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Berezi Amubieta +* Alfredo de la Fuente +* Ana Juaristi diff --git a/mrp_production_deconstruction/__init__.py b/mrp_production_deconstruction/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_production_deconstruction/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_production_deconstruction/__manifest__.py b/mrp_production_deconstruction/__manifest__.py new file mode 100644 index 000000000..6428f3331 --- /dev/null +++ b/mrp_production_deconstruction/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2022 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "MRP Production Deconstruction", + "version": "16.0.1.0.0", + "author": "Avanzosc", + "website": "https://github.com/avanzosc/mrp-addons", + "category": "MRP", + "depends": [ + "mrp", + ], + "data": [ + "views/mrp_production_view.xml", + "views/mrp_bom_view.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/mrp_production_deconstruction/i18n/es.po b/mrp_production_deconstruction/i18n/es.po new file mode 100644 index 000000000..41f67a238 --- /dev/null +++ b/mrp_production_deconstruction/i18n/es.po @@ -0,0 +1,110 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_deconstruction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-15 15:22+0000\n" +"PO-Revision-Date: 2023-11-15 15:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_mrp_bom +msgid "Bill of Material" +msgstr "Lista de materiales" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_bom_filter +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Deconstruction" +msgstr "Deconstrucción" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__display_name +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__display_name +msgid "Display Name" +msgstr "Mostrar nombre" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__location_id +msgid "From" +msgstr "Desde" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__id +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__id +msgid "ID" +msgstr "Identificador" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__is_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__is_deconstruction +msgid "Is Deconstruction?" +msgstr "¿Es una deconstrucción?" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom____last_update +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Month" +msgstr "Último mes" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Week" +msgstr "Última semana" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Year" +msgstr "Último año" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__move_line_ids +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.mrp_production_form_view +msgid "Move Lines" +msgstr "Operaciones detalladas" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "Movimientos de Producto (Stock Move Line)" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_mrp_production +msgid "Production Order" +msgstr "Orden de producción" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__location_dest_id +msgid "To" +msgstr "Hasta" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Today" +msgstr "Hoy" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.mrp_production_form_view +msgid "Total Reserved" +msgstr "Total reservado" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Yesterday" +msgstr "Ayer" diff --git a/mrp_production_deconstruction/i18n/mrp_production_deconstruction.pot b/mrp_production_deconstruction/i18n/mrp_production_deconstruction.pot new file mode 100644 index 000000000..f2401c3d1 --- /dev/null +++ b/mrp_production_deconstruction/i18n/mrp_production_deconstruction.pot @@ -0,0 +1,110 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_deconstruction +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-15 15:22+0000\n" +"PO-Revision-Date: 2023-11-15 15:22+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_mrp_bom +msgid "Bill of Material" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_bom_filter +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Deconstruction" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__display_name +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__display_name +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__location_id +msgid "From" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__id +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__id +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__id +msgid "ID" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom__is_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__is_deconstruction +msgid "Is Deconstruction?" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_bom____last_update +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production____last_update +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Month" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Week" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Last Year" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_mrp_production__move_line_ids +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.mrp_production_form_view +msgid "Move Lines" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_stock_move_line +msgid "Product Moves (Stock Move Line)" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model,name:mrp_production_deconstruction.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: mrp_production_deconstruction +#: model:ir.model.fields,field_description:mrp_production_deconstruction.field_stock_move_line__location_dest_id +msgid "To" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Today" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.mrp_production_form_view +msgid "Total Reserved" +msgstr "" + +#. module: mrp_production_deconstruction +#: model_terms:ir.ui.view,arch_db:mrp_production_deconstruction.view_mrp_production_filter +msgid "Yesterday" +msgstr "" diff --git a/mrp_production_deconstruction/models/__init__.py b/mrp_production_deconstruction/models/__init__.py new file mode 100644 index 000000000..d469d5c76 --- /dev/null +++ b/mrp_production_deconstruction/models/__init__.py @@ -0,0 +1,3 @@ +from . import mrp_bom +from . import mrp_production +from . import stock_move_line diff --git a/mrp_production_deconstruction/models/mrp_bom.py b/mrp_production_deconstruction/models/mrp_bom.py new file mode 100644 index 000000000..713530b26 --- /dev/null +++ b/mrp_production_deconstruction/models/mrp_bom.py @@ -0,0 +1,9 @@ +# Copyright 2022 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class MrpBom(models.Model): + _inherit = "mrp.bom" + + is_deconstruction = fields.Boolean(string="Is Deconstruction?", default=False) diff --git a/mrp_production_deconstruction/models/mrp_production.py b/mrp_production_deconstruction/models/mrp_production.py new file mode 100644 index 000000000..a8c354b95 --- /dev/null +++ b/mrp_production_deconstruction/models/mrp_production.py @@ -0,0 +1,92 @@ +# Copyright 2022 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + is_deconstruction = fields.Boolean( + string="Is Deconstruction?", related="bom_id.is_deconstruction", 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) + ], + ) + 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), + ], + ) + + @api.depends("product_id", "company_id", "is_deconstruction") + def _compute_production_location(self): + result = super()._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) + return result + + def write(self, vals): + res = super().write(vals) + if "move_finished_ids" in vals: + for line in self: + if line.is_deconstruction and line.move_finished_ids: + for move in line.move_finished_ids: + move.location_id = line.production_location_id.id + move.location_dest_id = line.location_src_id.id + return res + + def _check_is_deconstruction(self): + for production in self: + 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"): + 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, + } + ) + 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( + {"location_id": dest.id, "location_dest_id": origin.id} + ) + + def action_confirm(self): + self._check_is_deconstruction() + return super().action_confirm() + + def button_mark_done(self): + result = super().button_mark_done() + for production in 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} + ) + return result diff --git a/mrp_production_deconstruction/models/stock_move_line.py b/mrp_production_deconstruction/models/stock_move_line.py new file mode 100644 index 000000000..998c6e8ad --- /dev/null +++ b/mrp_production_deconstruction/models/stock_move_line.py @@ -0,0 +1,55 @@ +# Copyright 2022 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def _get_default_location_id(self): + if "production_id" in self.env.context: + production = self.env.context["production_id"] + production = self.env["mrp.production"].search( + [("id", "=", production)], limit=1 + ) + result = production.picking_type_id.default_location_src_id.id + if production.is_deconstruction is True: + result = production.location_src_id.id + return result + + def _get_default_location_dest_id(self): + if "production_id" in self.env.context: + production = self.env.context["production_id"] + production = self.env["mrp.production"].search( + [("id", "=", production)], limit=1 + ) + result = production.production_location_id.id + if production.is_deconstruction is True: + 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) + + @api.onchange("location_id", "location_dest_id") + def onchange_product_id_domain(self): + domain = {} + if "production_id" in self.env.context: + production = self.env.context["production_id"] + production = self.env["mrp.production"].search( + [("id", "=", production)], limit=1 + ) + domain = {} + 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)]}} + elif "default_production_id" in self.env.context: + production = self.env.context["default_production_id"] + production = self.env["mrp.production"].search( + [("id", "=", production)], limit=1 + ) + domain = {} + if production.move_byproduct_ids: + products = production.move_byproduct_ids.mapped("product_id") + 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 new file mode 100644 index 000000000..667bef786 --- /dev/null +++ b/mrp_production_deconstruction/views/mrp_bom_view.xml @@ -0,0 +1,34 @@ + + + + + mrp.bom + + + + + + + {'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 new file mode 100644 index 000000000..3c08dfb66 --- /dev/null +++ b/mrp_production_deconstruction/views/mrp_production_view.xml @@ -0,0 +1,142 @@ + + + + + mrp.production + + + + + + + {'column_invisible':[('parent.is_deconstruction', '=', True)]} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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, +)