diff --git a/stock_orderpoint_move_link/README.rst b/stock_orderpoint_move_link/README.rst new file mode 100644 index 00000000..16a5ec25 --- /dev/null +++ b/stock_orderpoint_move_link/README.rst @@ -0,0 +1,80 @@ +========================== +Stock Orderpoint Move Link +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e48b874278a5a3db3d37d13b0c1ae1c08f6ef83c019d7317079fb964925a870d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--orderpoint-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-orderpoint/tree/18.0/stock_orderpoint_move_link + :alt: OCA/stock-logistics-orderpoint +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-orderpoint-18-0/stock-logistics-orderpoint-18-0-stock_orderpoint_move_link + :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/stock-logistics-orderpoint&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds to stock moves a direct link to the reordering rules +that created them. In chained moves, the reordering rule is propagated. + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- Jordi Ballester Alomar +- Kitti Upariphutthiphong +- Héctor Villarreal Ortega +- Guewen Baconnier + +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. + +This module is part of the `OCA/stock-logistics-orderpoint `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_orderpoint_move_link/__init__.py b/stock_orderpoint_move_link/__init__.py new file mode 100644 index 00000000..61460882 --- /dev/null +++ b/stock_orderpoint_move_link/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2019 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import models diff --git a/stock_orderpoint_move_link/__manifest__.py b/stock_orderpoint_move_link/__manifest__.py new file mode 100644 index 00000000..86c21868 --- /dev/null +++ b/stock_orderpoint_move_link/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2019 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Orderpoint Move Link", + "summary": "Link Reordering rules to stock moves", + "version": "18.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/OCA/stock-logistics-orderpoint", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "category": "Warehouse Management", + "depends": ["stock"], + "data": ["views/stock_move_views.xml"], + "installable": True, + "auto_install": False, +} diff --git a/stock_orderpoint_move_link/i18n/it.po b/stock_orderpoint_move_link/i18n/it.po new file mode 100644 index 00000000..a3765385 --- /dev/null +++ b/stock_orderpoint_move_link/i18n/it.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_move_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-24 17:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: stock_orderpoint_move_link +#: model:ir.model.fields,field_description:stock_orderpoint_move_link.field_stock_move__orderpoint_ids +msgid "Linked Reordering Rules" +msgstr "Regole riordino collegate" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "Regola giacenza minima" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_rule +msgid "Stock Rule" +msgstr "Regola di giacenza" + +#. module: stock_orderpoint_move_link +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_move_link.view_warehouse_orderpoint_move_form +msgid "Transfers" +msgstr "Trasferimenti" diff --git a/stock_orderpoint_move_link/i18n/stock_orderpoint_move_link.pot b/stock_orderpoint_move_link/i18n/stock_orderpoint_move_link.pot new file mode 100644 index 00000000..591f4fc5 --- /dev/null +++ b/stock_orderpoint_move_link/i18n/stock_orderpoint_move_link.pot @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_move_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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: stock_orderpoint_move_link +#: model:ir.model.fields,field_description:stock_orderpoint_move_link.field_stock_move__orderpoint_ids +msgid "Linked Reordering Rules" +msgstr "" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_rule +msgid "Stock Rule" +msgstr "" + +#. module: stock_orderpoint_move_link +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_move_link.view_warehouse_orderpoint_move_form +msgid "Transfers" +msgstr "" diff --git a/stock_orderpoint_move_link/i18n/zh_CN.po b/stock_orderpoint_move_link/i18n/zh_CN.po new file mode 100644 index 00000000..04b50eaa --- /dev/null +++ b/stock_orderpoint_move_link/i18n/zh_CN.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_move_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-10-12 16:36+0000\n" +"Last-Translator: 黎伟杰 <674416404@qq.com>\n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 3.8\n" + +#. module: stock_orderpoint_move_link +#: model:ir.model.fields,field_description:stock_orderpoint_move_link.field_stock_move__orderpoint_ids +msgid "Linked Reordering Rules" +msgstr "链接的重新订购规则" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "最小库存规则" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_move +msgid "Stock Move" +msgstr "库存移动" + +#. module: stock_orderpoint_move_link +#: model:ir.model,name:stock_orderpoint_move_link.model_stock_rule +msgid "Stock Rule" +msgstr "库存规则" + +#. module: stock_orderpoint_move_link +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_move_link.view_warehouse_orderpoint_move_form +msgid "Transfers" +msgstr "调拨" diff --git a/stock_orderpoint_move_link/models/__init__.py b/stock_orderpoint_move_link/models/__init__.py new file mode 100644 index 00000000..a1d16300 --- /dev/null +++ b/stock_orderpoint_move_link/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import stock +from . import stock_move +from . import stock_warehouse_orderpoint diff --git a/stock_orderpoint_move_link/models/stock.py b/stock_orderpoint_move_link/models/stock.py new file mode 100644 index 00000000..ce5e660d --- /dev/null +++ b/stock_orderpoint_move_link/models/stock.py @@ -0,0 +1,34 @@ +# Copyright 2019 ForgeFlow, S.L., Ecosoft +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): + vals = super()._get_stock_move_values( + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ) + if values.get("orderpoint_id"): + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] + elif values.get("orderpoint_ids"): + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] + return vals diff --git a/stock_orderpoint_move_link/models/stock_move.py b/stock_orderpoint_move_link/models/stock_move.py new file mode 100644 index 00000000..a2a7dc4a --- /dev/null +++ b/stock_orderpoint_move_link/models/stock_move.py @@ -0,0 +1,22 @@ +# Copyright 2019 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + orderpoint_ids = fields.Many2many( + comodel_name="stock.warehouse.orderpoint", string="Linked Reordering Rules" + ) + + def _prepare_procurement_values(self): + res = super()._prepare_procurement_values() + if self.orderpoint_ids: + res["orderpoint_ids"] = self.orderpoint_ids + return res + + def _merge_moves_fields(self): + res = super()._merge_moves_fields() + res["orderpoint_ids"] = [(4, m.id) for m in self.mapped("orderpoint_ids")] + return res diff --git a/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py b/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py new file mode 100644 index 00000000..8cc2ac07 --- /dev/null +++ b/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py @@ -0,0 +1,17 @@ +# Copyright 2019 ForgeFlow S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class StockWarehouseOrderpoint(models.Model): + _inherit = "stock.warehouse.orderpoint" + + def action_view_stock_picking(self): + result = self.env["ir.actions.act_window"]._for_xml_id( + "stock.action_picking_tree_all" + ) + result["context"] = {} + result["domain"] = f"[('move_ids.orderpoint_ids', 'in', {self.ids})]" + return result diff --git a/stock_orderpoint_move_link/pyproject.toml b/stock_orderpoint_move_link/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/stock_orderpoint_move_link/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_orderpoint_move_link/readme/CONTRIBUTORS.md b/stock_orderpoint_move_link/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..f7e65e02 --- /dev/null +++ b/stock_orderpoint_move_link/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Jordi Ballester Alomar \ +- Kitti Upariphutthiphong \ +- Héctor Villarreal Ortega \ +- Guewen Baconnier \ diff --git a/stock_orderpoint_move_link/readme/DESCRIPTION.md b/stock_orderpoint_move_link/readme/DESCRIPTION.md new file mode 100644 index 00000000..a4060a0a --- /dev/null +++ b/stock_orderpoint_move_link/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds to stock moves a direct link to the reordering rules +that created them. In chained moves, the reordering rule is propagated. diff --git a/stock_orderpoint_move_link/static/description/icon.png b/stock_orderpoint_move_link/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/stock_orderpoint_move_link/static/description/icon.png differ diff --git a/stock_orderpoint_move_link/static/description/index.html b/stock_orderpoint_move_link/static/description/index.html new file mode 100644 index 00000000..5c646799 --- /dev/null +++ b/stock_orderpoint_move_link/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Stock Orderpoint Move Link + + + + + + diff --git a/stock_orderpoint_move_link/tests/__init__.py b/stock_orderpoint_move_link/tests/__init__.py new file mode 100644 index 00000000..bc24fd9a --- /dev/null +++ b/stock_orderpoint_move_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_orderpoint_move_link diff --git a/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py b/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py new file mode 100644 index 00000000..c0ccabba --- /dev/null +++ b/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py @@ -0,0 +1,137 @@ +# Copyright 2019 ForgeFlow S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import ast + +from odoo.tests.common import TransactionCase + + +class TestStockOrderpointMoveLink(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.product_obj = cls.env["product.product"] + cls.orderpoint_obj = cls.env["stock.warehouse.orderpoint"] + cls.loc_obj = cls.env["stock.location"] + cls.route_obj = cls.env["stock.route"] + cls.group_obj = cls.env["procurement.group"] + cls.move_obj = cls.env["stock.move"] + cls.picking_obj = cls.env["stock.picking"] + + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.stock_loc = cls.env.ref("stock.stock_location_stock") + + # Create a new locations and routes: + cls.intermediate_loc = cls.loc_obj.create( + { + "name": "Test location 1", + "usage": "internal", + "location_id": cls.warehouse.view_location_id.id, + } + ) + cls.test_route = cls.route_obj.create( + { + "name": "Stock -> Test 1", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "stock to test", + "action": "pull", + "location_dest_id": cls.intermediate_loc.id, + "location_src_id": cls.stock_loc.id, + "procure_method": "make_to_stock", + "picking_type_id": cls.env.ref( + "stock.picking_type_internal" + ).id, + }, + ) + ], + } + ) + cls.need_loc = cls.loc_obj.create( + { + "name": "Test location 2", + "usage": "internal", + "location_id": cls.warehouse.view_location_id.id, + } + ) + cls.test_route_2 = cls.route_obj.create( + { + "name": "Test 1 -> Test 2", + "product_selectable": True, + "rule_ids": [ + ( + 0, + 0, + { + "name": "Test 1 to Test 2", + "action": "pull", + "location_dest_id": cls.need_loc.id, + "location_src_id": cls.intermediate_loc.id, + "procure_method": "make_to_order", + "picking_type_id": cls.env.ref( + "stock.picking_type_internal" + ).id, + }, + ) + ], + } + ) + + # Prepare Products: + routes = cls.test_route_2 + cls.test_route + cls.product = cls.product_obj.create( + {"name": "Test Product", "route_ids": [(6, 0, routes.ids)]} + ) + + # Create Orderpoint: + cls.orderpoint_need_loc = cls.orderpoint_obj.create( + { + "warehouse_id": cls.warehouse.id, + "location_id": cls.need_loc.id, + "product_id": cls.product.id, + "product_min_qty": 10.0, + "product_max_qty": 50.0, + "product_uom": cls.product.uom_id.id, + } + ) + cls.group_obj.run_scheduler() + + def test_01_stock_orderpoint_move_link(self): + """Tests if manual procurement fills orderpoint_ids field.""" + move = self.move_obj.search( + [("orderpoint_ids", "=", self.orderpoint_need_loc.id)] + ) + self.assertEqual(len(move), 2) + + def test_02_stock_orderpoint_move_link_action_view(self): + sp_orderpoint = self.move_obj.search( + [("orderpoint_ids", "in", self.orderpoint_need_loc.id)] + ).mapped("picking_id") + result = self.orderpoint_need_loc.action_view_stock_picking() + sp_action = self.picking_obj.search(ast.literal_eval(result["domain"])) + self.assertEqual(sp_orderpoint, sp_action) + + def test_03_stock_orderpoint_move_link_merge_moves(self): + # Previous moves generation + moves = self.move_obj.search( + [("orderpoint_ids", "=", self.orderpoint_need_loc.id)] + ) + self.assertEqual(moves.mapped("product_qty"), [50.0, 50.0]) + self.assertEqual(len(moves), 2) + self.assertEqual(moves.mapped("orderpoint_ids"), self.orderpoint_need_loc) + # Force reordering (new moves will be merged into the old ones) + self.orderpoint_need_loc.write( + { + "product_min_qty": 60.0, + "product_max_qty": 75.0, + } + ) + self.group_obj.run_scheduler() + # Check merged moves + self.assertEqual(moves.mapped("product_qty"), [75.0, 75.0]) + self.assertEqual(len(moves), 2) + self.assertEqual(moves.mapped("orderpoint_ids"), self.orderpoint_need_loc) diff --git a/stock_orderpoint_move_link/views/stock_move_views.xml b/stock_orderpoint_move_link/views/stock_move_views.xml new file mode 100644 index 00000000..140ffb98 --- /dev/null +++ b/stock_orderpoint_move_link/views/stock_move_views.xml @@ -0,0 +1,33 @@ + + + + + stock.move.form + stock.move + + + + + + + + + stock.warehouse.orderpoint.move.form + stock.warehouse.orderpoint + + +
+
+
+
+
+
+