diff --git a/mrp_2_steps_consumed_qty_sync/README.rst b/mrp_2_steps_consumed_qty_sync/README.rst new file mode 100644 index 0000000000..d4f6291f92 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/README.rst @@ -0,0 +1,88 @@ +============================= +MRP 2 steps consumed qty sync +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bf57d7cafed692fe20d0710b88e16940f6dd8eeda49c9490253d6468ede6ded8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/15.0/mrp_2_steps_consumed_qty_sync + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-mrp_2_steps_consumed_qty_sync + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to update the quantities consumed from a production order components +when the previous picking in two steps setting is validated. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `__: + + * Sergio Teruel + * Carlos Dauden + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px + :target: https://github.com/sergio-teruel + :alt: sergio-teruel + +Current `maintainer `__: + +|maintainer-sergio-teruel| + +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_2_steps_consumed_qty_sync/__init__.py b/mrp_2_steps_consumed_qty_sync/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_2_steps_consumed_qty_sync/__manifest__.py b/mrp_2_steps_consumed_qty_sync/__manifest__.py new file mode 100644 index 0000000000..54a7cee9be --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# Copyright 2024 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "MRP 2 steps consumed qty sync", + "summary": "Update consumed quantities when in 2 steps production scope " + "the picking is validated", + "version": "15.0.0.1.0", + "development_status": "Beta", + "license": "AGPL-3", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": [ + "sergio-teruel", + ], + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing", + "depends": [ + "mrp", + ], + "installable": True, +} diff --git a/mrp_2_steps_consumed_qty_sync/i18n/es.po b/mrp_2_steps_consumed_qty_sync/i18n/es.po new file mode 100644 index 0000000000..eaa467e176 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/i18n/es.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_2_steps_consumed_qty_sync +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-17 13:16+0000\n" +"PO-Revision-Date: 2024-09-17 15:17+0200\n" +"Last-Translator: Sergio Teruel \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.0.1\n" + +#. module: mrp_2_steps_consumed_qty_sync +#: model:ir.model,name:mrp_2_steps_consumed_qty_sync.model_stock_picking +msgid "Transfer" +msgstr "Albarán" diff --git a/mrp_2_steps_consumed_qty_sync/i18n/mrp_2_steps_consumed_qty_sync.pot b/mrp_2_steps_consumed_qty_sync/i18n/mrp_2_steps_consumed_qty_sync.pot new file mode 100644 index 0000000000..c933557e36 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/i18n/mrp_2_steps_consumed_qty_sync.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_2_steps_consumed_qty_sync +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-17 13:16+0000\n" +"PO-Revision-Date: 2024-09-17 13:16+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_2_steps_consumed_qty_sync +#: model:ir.model,name:mrp_2_steps_consumed_qty_sync.model_stock_picking +msgid "Transfer" +msgstr "" diff --git a/mrp_2_steps_consumed_qty_sync/models/__init__.py b/mrp_2_steps_consumed_qty_sync/models/__init__.py new file mode 100644 index 0000000000..ae4c27227f --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/mrp_2_steps_consumed_qty_sync/models/stock_picking.py b/mrp_2_steps_consumed_qty_sync/models/stock_picking.py new file mode 100644 index 0000000000..97cb0263ba --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/models/stock_picking.py @@ -0,0 +1,30 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# Copyright 2024 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _action_done(self): + res = super()._action_done() + for picking in self: + picking_type = picking.picking_type_id + if picking_type == picking_type.warehouse_id.pbm_type_id: + productions = ( + picking.move_lines.move_dest_ids.raw_material_production_id + ) + # Update the component initial demand in production order and assign + # the moves to cover cases like pick more quantities than expected. + # In this cases the quantity done is not propagated to linked move + for move in productions.move_raw_ids: + move.product_uom_qty = sum( + move.move_orig_ids.filtered( + lambda sm: sm.state == "done" + ).mapped("quantity_done") + ) + productions.move_raw_ids._action_assign() + productions.move_raw_ids._set_quantities_to_reservation() + return res diff --git a/mrp_2_steps_consumed_qty_sync/readme/CONTRIBUTORS.rst b/mrp_2_steps_consumed_qty_sync/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..508f0287dc --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `__: + + * Sergio Teruel + * Carlos Dauden diff --git a/mrp_2_steps_consumed_qty_sync/readme/DESCRIPTION.rst b/mrp_2_steps_consumed_qty_sync/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..7dc7d7f415 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to update the quantities consumed from a production order components +when the previous picking in two steps setting is validated. diff --git a/mrp_2_steps_consumed_qty_sync/static/description/index.html b/mrp_2_steps_consumed_qty_sync/static/description/index.html new file mode 100644 index 0000000000..e823df1bb8 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +MRP 2 steps consumed qty sync + + + +
+

MRP 2 steps consumed qty sync

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

This module allows to update the quantities consumed from a production order components +when the previous picking in two steps setting is validated.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Sergio Teruel
    • +
    • Carlos Dauden
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

sergio-teruel

+

This module is part of the OCA/manufacture project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mrp_2_steps_consumed_qty_sync/tests/__init__.py b/mrp_2_steps_consumed_qty_sync/tests/__init__.py new file mode 100644 index 0000000000..f65370360b --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_2_steps_consumed_qty_sync diff --git a/mrp_2_steps_consumed_qty_sync/tests/test_mrp_2_steps_consumed_qty_sync.py b/mrp_2_steps_consumed_qty_sync/tests/test_mrp_2_steps_consumed_qty_sync.py new file mode 100644 index 0000000000..6a873145f9 --- /dev/null +++ b/mrp_2_steps_consumed_qty_sync/tests/test_mrp_2_steps_consumed_qty_sync.py @@ -0,0 +1,82 @@ +# Copyright 2024 Tecnativa - Sergio Teruel +# Copyright 2024 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.tests import tagged +from odoo.tests.common import Form + +from odoo.addons.mrp.tests.common import TestMrpCommon + + +@tagged("post_install", "-at_install") +class TestMrp2StepsConsumedQtySync(TestMrpCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Active multilocation security group and multi step routes + grp_multi_loc = cls.env.ref("stock.group_stock_multi_locations") + grp_multi_routes = cls.env.ref("stock.group_adv_location") + cls.env.user.write({"groups_id": [(4, grp_multi_loc.id)]}) + cls.env.user.write({"groups_id": [(4, grp_multi_routes.id)]}) + + # Active produce in two steps + cls.warehouse = cls.env.ref("stock.warehouse0") + with Form(cls.warehouse) as warehouse: + warehouse.manufacture_steps = "pbm" + + def _add_product_stock(self, product, qty=50.0): + return ( + self.env["stock.quant"] + .with_context(inventory_mode=True) + .create( + { + "product_id": product.id, + "quantity": qty, + "location_id": self.warehouse.lot_stock_id.id, + } + ) + ) + + def test_consumed_qty_production_order(self): + # Generate manufacturer order + ( + production, + _, + product_to_build, + product_to_use_1, + product_to_use_2, + ) = self.generate_mo( + qty_final=10, + qty_base_1=5, + qty_base_2=4, + picking_type_id=self.warehouse.manu_type_id, + ) + + # Set stock for components + self._add_product_stock(product_to_use_1) + self._add_product_stock(product_to_use_2) + + # Complete pick components + pick_picking = production.picking_ids + pick_picking.action_assign() + pick_picking.move_line_ids.filtered( + lambda sml: sml.product_id == product_to_use_1 + ).qty_done = 10 + pick_picking.move_line_ids.filtered( + lambda sml: sml.product_id == product_to_use_2 + ).qty_done = 15 + pick_picking._action_done() + + # Check if the done quantities are sync to raw material in mo order + self.assertEqual( + production.move_raw_ids.filtered( + lambda sm: sm.product_id == product_to_use_1 + ).quantity_done, + 10.0, + ) + self.assertEqual( + production.move_raw_ids.filtered( + lambda sm: sm.product_id == product_to_use_2 + ).quantity_done, + 15.0, + ) diff --git a/setup/mrp_2_steps_consumed_qty_sync/odoo/addons/mrp_2_steps_consumed_qty_sync b/setup/mrp_2_steps_consumed_qty_sync/odoo/addons/mrp_2_steps_consumed_qty_sync new file mode 120000 index 0000000000..f84472329c --- /dev/null +++ b/setup/mrp_2_steps_consumed_qty_sync/odoo/addons/mrp_2_steps_consumed_qty_sync @@ -0,0 +1 @@ +../../../../mrp_2_steps_consumed_qty_sync \ No newline at end of file diff --git a/setup/mrp_2_steps_consumed_qty_sync/setup.py b/setup/mrp_2_steps_consumed_qty_sync/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mrp_2_steps_consumed_qty_sync/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)