diff --git a/stock_orderpoint_purchase_link/README.rst b/stock_orderpoint_purchase_link/README.rst new file mode 100644 index 000000000..fae74a31d --- /dev/null +++ b/stock_orderpoint_purchase_link/README.rst @@ -0,0 +1,76 @@ +============================== +Stock Orderpoint Purchase 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/12.0/stock_orderpoint_purchase_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-12-0/stock-logistics-warehouse-12-0-stock_orderpoint_purchase_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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds to purchase order lines a direct link to the reordering rules +that created them. In chained moves, the reordering rule is propagated +from stock moves to the purchase order line. + +**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 +* Kitti Upariphutthiphong. (http://ecosoft.co.th) + +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_purchase_link/__init__.py b/stock_orderpoint_purchase_link/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_orderpoint_purchase_link/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_orderpoint_purchase_link/__manifest__.py b/stock_orderpoint_purchase_link/__manifest__.py new file mode 100644 index 000000000..1492487a0 --- /dev/null +++ b/stock_orderpoint_purchase_link/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Orderpoint Purchase Link", + "summary": "Link Reordering rules to purchase orders", + "version": "13.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "category": "Warehouse Management", + "depends": ["stock_orderpoint_move_link", "purchase_stock"], + "data": ["views/purchase_order_views.xml"], + "installable": True, + "auto_install": True, +} diff --git a/stock_orderpoint_purchase_link/i18n/stock_orderpoint_purchase_link.pot b/stock_orderpoint_purchase_link/i18n/stock_orderpoint_purchase_link.pot new file mode 100644 index 000000000..0500e16f2 --- /dev/null +++ b/stock_orderpoint_purchase_link/i18n/stock_orderpoint_purchase_link.pot @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_purchase_link +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_purchase_order_line__orderpoint_ids +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_purchase_link.purchase_order_form +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_purchase_link.purchase_order_line_form2 +msgid "Orderpoints" +msgstr "" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_stock_warehouse_orderpoint__purchase_line_ids +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_stock_warehouse_orderpoint_template__purchase_line_ids +msgid "Purchase Order Lines" +msgstr "" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_stock_rule +msgid "Stock Rule" +msgstr "" + diff --git a/stock_orderpoint_purchase_link/i18n/zh_CN.po b/stock_orderpoint_purchase_link/i18n/zh_CN.po new file mode 100644 index 000000000..949d43d4b --- /dev/null +++ b/stock_orderpoint_purchase_link/i18n/zh_CN.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_purchase_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_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_stock_warehouse_orderpoint +msgid "Minimum Inventory Rule" +msgstr "最小库存规则" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_purchase_order_line__orderpoint_ids +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_purchase_link.purchase_order_form +#: model_terms:ir.ui.view,arch_db:stock_orderpoint_purchase_link.purchase_order_line_form2 +msgid "Orderpoints" +msgstr "订货点" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "采购订单行" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_stock_warehouse_orderpoint__purchase_line_ids +#: model:ir.model.fields,field_description:stock_orderpoint_purchase_link.field_stock_warehouse_orderpoint_template__purchase_line_ids +msgid "Purchase Order Lines" +msgstr "采购订单行" + +#. module: stock_orderpoint_purchase_link +#: model:ir.model,name:stock_orderpoint_purchase_link.model_stock_rule +msgid "Stock Rule" +msgstr "库存规则" diff --git a/stock_orderpoint_purchase_link/models/__init__.py b/stock_orderpoint_purchase_link/models/__init__.py new file mode 100644 index 000000000..87cace991 --- /dev/null +++ b/stock_orderpoint_purchase_link/models/__init__.py @@ -0,0 +1,3 @@ +from . import purchase_order_line +from . import stock_rule +from . import stock_warehouse_orderpoint diff --git a/stock_orderpoint_purchase_link/models/purchase_order_line.py b/stock_orderpoint_purchase_link/models/purchase_order_line.py new file mode 100644 index 000000000..5399625f1 --- /dev/null +++ b/stock_orderpoint_purchase_link/models/purchase_order_line.py @@ -0,0 +1,15 @@ +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + orderpoint_ids = fields.Many2many( + comodel_name="stock.warehouse.orderpoint", + string="Orderpoints", + copy=False, + readonly=True, + ) diff --git a/stock_orderpoint_purchase_link/models/stock_rule.py b/stock_orderpoint_purchase_link/models/stock_rule.py new file mode 100644 index 000000000..b595034f8 --- /dev/null +++ b/stock_orderpoint_purchase_link/models/stock_rule.py @@ -0,0 +1,35 @@ +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) +# 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 _prepare_purchase_order_line( + self, product_id, product_qty, product_uom, company_id, values, po + ): + vals = super()._prepare_purchase_order_line( + product_id, product_qty, product_uom, company_id, values, po + ) + # If the procurement was run directly by a reordering rule. + if "orderpoint_id" in values and values["orderpoint_id"].id: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] + # If the procurement was run by a stock move. + elif "orderpoint_ids" in values: + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] + return vals + + def _update_purchase_order_line( + self, product_id, product_qty, product_uom, company_id, values, line + ): + vals = super()._update_purchase_order_line( + product_id, product_qty, product_uom, company_id, values, line + ) + if "orderpoint_id" in values and values["orderpoint_id"].id: + vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)] + # If the procurement was run by a stock move. + elif "orderpoint_ids" in values: + vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]] + return vals diff --git a/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py b/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py new file mode 100644 index 000000000..6b4621eee --- /dev/null +++ b/stock_orderpoint_purchase_link/models/stock_warehouse_orderpoint.py @@ -0,0 +1,15 @@ +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class StockWarehouseOrderpoint(models.Model): + _inherit = "stock.warehouse.orderpoint" + + purchase_line_ids = fields.Many2many( + comodel_name="purchase.order.line", + string="Purchase Order Lines", + copy=False, + readonly=True, + ) diff --git a/stock_orderpoint_purchase_link/readme/CONTRIBUTORS.rst b/stock_orderpoint_purchase_link/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..767f5b23d --- /dev/null +++ b/stock_orderpoint_purchase_link/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester +* Kitti Upariphutthiphong. (http://ecosoft.co.th) diff --git a/stock_orderpoint_purchase_link/readme/DESCRIPTION.rst b/stock_orderpoint_purchase_link/readme/DESCRIPTION.rst new file mode 100644 index 000000000..4921c935b --- /dev/null +++ b/stock_orderpoint_purchase_link/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module adds to purchase order lines a direct link to the reordering rules +that created them. In chained moves, the reordering rule is propagated +from stock moves to the purchase order line. diff --git a/stock_orderpoint_purchase_link/static/description/icon.png b/stock_orderpoint_purchase_link/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_orderpoint_purchase_link/static/description/icon.png differ diff --git a/stock_orderpoint_purchase_link/static/description/index.html b/stock_orderpoint_purchase_link/static/description/index.html new file mode 100644 index 000000000..680b6101e --- /dev/null +++ b/stock_orderpoint_purchase_link/static/description/index.html @@ -0,0 +1,422 @@ + + + + + + +Stock Orderpoint Purchase Link + + + + + + diff --git a/stock_orderpoint_purchase_link/tests/__init__.py b/stock_orderpoint_purchase_link/tests/__init__.py new file mode 100644 index 000000000..b88d2929f --- /dev/null +++ b/stock_orderpoint_purchase_link/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_orderpoint_purchase_link diff --git a/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py b/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py new file mode 100644 index 000000000..1ae049be4 --- /dev/null +++ b/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py @@ -0,0 +1,83 @@ +# Copyright 2018-20 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). + +from odoo.tests import common + + +class TestOrderpointPurchaseLink(common.TransactionCase): + def setUp(self): + super(TestOrderpointPurchaseLink, self).setUp() + + self.product_obj = self.env["product.product"] + self.partner_obj = self.env["res.partner"] + self.pol_obj = self.env["purchase.order.line"] + self.location_obj = self.env["stock.location"] + self.orderpoint_obj = self.env["stock.warehouse.orderpoint"] + self.route_obj = self.env["stock.location.route"] + self.rule_obj = self.env["stock.rule"] + self.group_obj = self.env["procurement.group"] + + # WH and routes: + self.warehouse = self.env.ref("stock.warehouse0") + self.stock_location = self.warehouse.lot_stock_id + self.test_location = self.location_obj.create( + {"name": "Test", "location_id": self.warehouse.view_location_id.id} + ) + route_buy = self.env.ref("purchase_stock.route_warehouse0_buy").id + route_test = self.route_obj.create({"name": "Stock to Test"}).id + self.rule_obj.create( + { + "name": "Stock to Test", + "action": "pull", + "procure_method": "make_to_order", + "location_id": self.test_location.id, + "location_src_id": self.stock_location.id, + "route_id": route_test, + "picking_type_id": self.warehouse.int_type_id.id, + "warehouse_id": self.warehouse.id, + "group_propagation_option": "none", + } + ) + # Partners: + vendor1 = self.partner_obj.create({"name": "Vendor 1"}) + + # Create products: + self.tp1 = self.product_obj.create( + { + "name": "Test Product 1", + "type": "product", + "list_price": 150.0, + "route_ids": [(6, 0, [route_buy, route_test])], + "seller_ids": [(0, 0, {"name": vendor1.id, "price": 20.0})], + } + ) + + # Create Orderpoints: + self.op1 = self.orderpoint_obj.create( + { + "product_id": self.tp1.id, + "location_id": self.stock_location.id, + "product_min_qty": 5.0, + "product_max_qty": 20.0, + } + ) + self.op2 = self.orderpoint_obj.create( + { + "product_id": self.tp1.id, + "location_id": self.test_location.id, + "product_min_qty": 5.0, + "product_max_qty": 20.0, + } + ) + + def test_01_po_line_from_orderpoints(self): + """Test that a PO line created/updated by two orderpoints keeps + the link with both of them.""" + self.group_obj.run_scheduler() + po_line = self.env["purchase.order.line"].search( + [("product_id", "=", self.tp1.id)] + ) + self.assertTrue(po_line) + # Each orderpoint must have required 20.0 units: + self.assertEqual(po_line.product_qty, 40.0) + self.assertEqual(len(po_line.orderpoint_ids), 2) diff --git a/stock_orderpoint_purchase_link/views/purchase_order_views.xml b/stock_orderpoint_purchase_link/views/purchase_order_views.xml new file mode 100644 index 000000000..a4652cd69 --- /dev/null +++ b/stock_orderpoint_purchase_link/views/purchase_order_views.xml @@ -0,0 +1,35 @@ + + + + + purchase.order.form + purchase.order + + + + + + + + + + + + + + + purchase.order.line.form2 + purchase.order.line + + + + + + + + + +