diff --git a/mrp_unbuild_move_link/README.rst b/mrp_unbuild_move_link/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/mrp_unbuild_move_link/__init__.py b/mrp_unbuild_move_link/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_unbuild_move_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_unbuild_move_link/__manifest__.py b/mrp_unbuild_move_link/__manifest__.py new file mode 100644 index 000000000..4395db64b --- /dev/null +++ b/mrp_unbuild_move_link/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "Stock moves of manufacturing orders added to unbuild orders", + "version": "14.0.1.0.0", + "license": "LGPL-3", + "category": "Manufacture", + "summary": "Link the stock moves of manufacturing orders to the respective unbuild orders", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "depends": ["mrp_account"], + "data": ["views/stock_move_views.xml"], + "installable": True, +} diff --git a/mrp_unbuild_move_link/models/__init__.py b/mrp_unbuild_move_link/models/__init__.py new file mode 100644 index 000000000..684159918 --- /dev/null +++ b/mrp_unbuild_move_link/models/__init__.py @@ -0,0 +1,2 @@ +from . import mrp_unbuild +from . import stock_move diff --git a/mrp_unbuild_move_link/models/mrp_unbuild.py b/mrp_unbuild_move_link/models/mrp_unbuild.py new file mode 100644 index 000000000..77a6a4bef --- /dev/null +++ b/mrp_unbuild_move_link/models/mrp_unbuild.py @@ -0,0 +1,14 @@ +from odoo import models + + +class MrpUnbuild(models.Model): + _inherit = "mrp.unbuild" + + def _generate_move_from_existing_move( + self, move, factor, location_id, location_dest_id + ): + result = super(MrpUnbuild, self)._generate_move_from_existing_move( + move, factor, location_id, location_dest_id + ) + result.origin_mrp_manufacture_move_id = move.id + return result diff --git a/mrp_unbuild_move_link/models/stock_move.py b/mrp_unbuild_move_link/models/stock_move.py new file mode 100644 index 000000000..88af57d1b --- /dev/null +++ b/mrp_unbuild_move_link/models/stock_move.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + origin_mrp_manufacture_move_id = fields.Many2one( + "stock.move", + string="Manufacturing order stock move", + checkcompany=True, + help="Stock move id of the previous manufacturing order", + ) diff --git a/mrp_unbuild_move_link/readme/CONTRIBUTORS.rst b/mrp_unbuild_move_link/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..da18dd75a --- /dev/null +++ b/mrp_unbuild_move_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `_: + + * Thiago Mulero diff --git a/mrp_unbuild_move_link/readme/DESCRIPTION.rst b/mrp_unbuild_move_link/readme/DESCRIPTION.rst new file mode 100644 index 000000000..632eaac6b --- /dev/null +++ b/mrp_unbuild_move_link/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module associates the id of the stock move of a manufacturing order to the stock move created from its unbuild order diff --git a/mrp_unbuild_move_link/static/description/icon.png b/mrp_unbuild_move_link/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_unbuild_move_link/static/description/icon.png differ diff --git a/mrp_unbuild_move_link/tests/__init__.py b/mrp_unbuild_move_link/tests/__init__.py new file mode 100644 index 000000000..c98545f8e --- /dev/null +++ b/mrp_unbuild_move_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_unbuild_move_link diff --git a/mrp_unbuild_move_link/tests/test_mrp_unbuild_move_link.py b/mrp_unbuild_move_link/tests/test_mrp_unbuild_move_link.py new file mode 100644 index 000000000..14c0d78da --- /dev/null +++ b/mrp_unbuild_move_link/tests/test_mrp_unbuild_move_link.py @@ -0,0 +1,56 @@ +from odoo.tests import Form + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +class TestUnbuild(TestMrpCommon): + def setUp(self): + super(TestUnbuild, self).setUp() + self.stock_location = self.env.ref("stock.stock_location_stock") + self.env.ref("base.group_user").write( + {"implied_ids": [(4, self.env.ref("stock.group_production_lot").id)]} + ) + + def test_unbuild_with_move_mrp_link(self): + """This test creates an Unbuild order from a Manufacturing order and then + check if the unbuild order has the id of the manufacturing order stock move. + """ + mo, bom, p_final, p1, p2 = self.generate_mo() + + self.env["stock.quant"]._update_available_quantity(p1, self.stock_location, 100) + self.env["stock.quant"]._update_available_quantity(p2, self.stock_location, 5) + mo.action_assign() + + mo_form = Form(mo) + mo_form.qty_producing = 5.0 + mo = mo_form.save() + mo.button_mark_done() + a = mo.button_unbuild() + unbuild = self.env["mrp.unbuild"].create( + { + "product_id": a["context"]["default_product_id"], + "mo_id": a["context"]["default_mo_id"], + "company_id": a["context"]["default_company_id"], + "location_id": a["context"]["default_location_id"], + "location_dest_id": a["context"]["default_location_dest_id"], + "product_uom_id": mo["product_uom_id"].id, + "product_qty": 1, + } + ) + + unbuild.action_validate() + mo_stock_move_id = mo.move_finished_ids.id + so = self.env["stock.move"].browse(unbuild.produce_line_ids.ids[0]) + unbuild_mo_stock_move_id = so.origin_mrp_manufacture_move_id.id + + self.assertTrue( + unbuild_mo_stock_move_id, + "You should have one value in origin_mrp_manufacture_move_id field" + "in the stock move of the unbuild order", + ) + self.assertEqual( + mo_stock_move_id, + unbuild_mo_stock_move_id, + "You should have the origin manufacturing order stock move " + "in the stock move of the unbuild order", + ) diff --git a/mrp_unbuild_move_link/views/stock_move_views.xml b/mrp_unbuild_move_link/views/stock_move_views.xml new file mode 100644 index 000000000..76f2a646b --- /dev/null +++ b/mrp_unbuild_move_link/views/stock_move_views.xml @@ -0,0 +1,13 @@ + + + + stock.move.form.inhereted - MO move link + stock.move + + + + + + + + diff --git a/setup/mrp_unbuild_move_link/odoo/addons/mrp_unbuild_move_link b/setup/mrp_unbuild_move_link/odoo/addons/mrp_unbuild_move_link new file mode 120000 index 000000000..084b10bf2 --- /dev/null +++ b/setup/mrp_unbuild_move_link/odoo/addons/mrp_unbuild_move_link @@ -0,0 +1 @@ +../../../../mrp_unbuild_move_link \ No newline at end of file diff --git a/setup/mrp_unbuild_move_link/setup.py b/setup/mrp_unbuild_move_link/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mrp_unbuild_move_link/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)