diff --git a/setup/stock_orderpoint_move_link/odoo/addons/stock_orderpoint_move_link b/setup/stock_orderpoint_move_link/odoo/addons/stock_orderpoint_move_link new file mode 120000 index 000000000..99ac3c656 --- /dev/null +++ b/setup/stock_orderpoint_move_link/odoo/addons/stock_orderpoint_move_link @@ -0,0 +1 @@ +../../../../stock_orderpoint_move_link \ No newline at end of file diff --git a/setup/stock_orderpoint_move_link/setup.py b/setup/stock_orderpoint_move_link/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_orderpoint_move_link/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_orderpoint_move_link/README.rst b/stock_orderpoint_move_link/README.rst new file mode 100644 index 000000000..7c08f8f7e --- /dev/null +++ b/stock_orderpoint_move_link/README.rst @@ -0,0 +1,77 @@ +========================== +Stock Orderpoint Move Link +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_orderpoint_move_link + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_orderpoint_move_link + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Eficent + +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-warehouse `_ 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 000000000..2fb88af91 --- /dev/null +++ b/stock_orderpoint_move_link/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2019 Eficent Business and IT Consulting Services, 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 000000000..5ff801968 --- /dev/null +++ b/stock_orderpoint_move_link/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2019 Eficent Business and IT Consulting Services, 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": "13.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/stock-logistics-warehouse", + "author": "Eficent, 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/stock_orderpoint_move_link.pot b/stock_orderpoint_move_link/i18n/stock_orderpoint_move_link.pot new file mode 100644 index 000000000..c24c5ac86 --- /dev/null +++ b/stock_orderpoint_move_link/i18n/stock_orderpoint_move_link.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_move_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.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 000000000..fe6b4513b --- /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 000000000..7f2c64d3c --- /dev/null +++ b/stock_orderpoint_move_link/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Eficent Business and IT Consulting Services, 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 000000000..50a22d73c --- /dev/null +++ b/stock_orderpoint_move_link/models/stock.py @@ -0,0 +1,34 @@ +# Copyright 2019 Eficent Business, IT Consulting Services, 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 "orderpoint_id" in values: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] + elif "orderpoint_ids" in values: + 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 000000000..3ed7e6cfb --- /dev/null +++ b/stock_orderpoint_move_link/models/stock_move.py @@ -0,0 +1,22 @@ +# Copyright 2019 Eficent Business, IT Consulting Services, 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 000000000..b5836b77d --- /dev/null +++ b/stock_orderpoint_move_link/models/stock_warehouse_orderpoint.py @@ -0,0 +1,21 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.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): + action = self.env.ref("stock.action_picking_tree_all") + result = action.read()[0] + result["context"] = {} + picking_ids = ( + self.env["stock.move"] + .search([("orderpoint_ids", "in", self.id)]) + .mapped("picking_id") + ) + result["domain"] = "[('id','in',%s)]" % picking_ids.ids + return result diff --git a/stock_orderpoint_move_link/readme/CONTRIBUTORS.rst b/stock_orderpoint_move_link/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..1d856de5f --- /dev/null +++ b/stock_orderpoint_move_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Jordi Ballester Alomar +* Kitti Upariphutthiphong +* Héctor Villarreal Ortega +* Guewen Baconnier diff --git a/stock_orderpoint_move_link/readme/DESCRIPTION.rst b/stock_orderpoint_move_link/readme/DESCRIPTION.rst new file mode 100644 index 000000000..b6b601955 --- /dev/null +++ b/stock_orderpoint_move_link/readme/DESCRIPTION.rst @@ -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 000000000..3a0328b51 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 000000000..32315d858 --- /dev/null +++ b/stock_orderpoint_move_link/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +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 000000000..bc24fd9a5 --- /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 000000000..58f8d67a6 --- /dev/null +++ b/stock_orderpoint_move_link/tests/test_stock_orderpoint_move_link.py @@ -0,0 +1,116 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import ast + +from odoo.tests.common import SavepointCase + + +class TestStockOrderpointMoveLink(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + 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.location.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_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_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.assertTrue(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.assertEquals(sp_orderpoint, sp_action) 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 000000000..d592a569a --- /dev/null +++ b/stock_orderpoint_move_link/views/stock_move_views.xml @@ -0,0 +1,35 @@ + + + + + + stock.move.form + stock.move + + + + + + + + + + stock.warehouse.orderpoint.move.form + stock.warehouse.orderpoint + + +
+
+ +
+
+
+
+ +