diff --git a/stock_orderpoint_purchase_link/__manifest__.py b/stock_orderpoint_purchase_link/__manifest__.py index 5301a80b..0950f40b 100644 --- a/stock_orderpoint_purchase_link/__manifest__.py +++ b/stock_orderpoint_purchase_link/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Stock Orderpoint Purchase Link", "summary": "Link Reordering rules to purchase orders", - "version": "11.0.1.0.1", + "version": "11.0.1.0.2", "license": "LGPL-3", "website": "https://github.com/stock-logistics-warehouse", "author": "Eficent, " 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 00000000..e02276da --- /dev/null +++ b/stock_orderpoint_purchase_link/i18n/stock_orderpoint_purchase_link.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_orderpoint_purchase_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_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:ir.ui.view,arch_db:stock_orderpoint_purchase_link.purchase_order_form +#: model: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_procurement_rule +msgid "Procurement Rule" +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 +msgid "Purchase Order Lines" +msgstr "" + diff --git a/stock_orderpoint_purchase_link/models/procurement_rule.py b/stock_orderpoint_purchase_link/models/procurement_rule.py index 244d0251..27c7da61 100644 --- a/stock_orderpoint_purchase_link/models/procurement_rule.py +++ b/stock_orderpoint_purchase_link/models/procurement_rule.py @@ -28,4 +28,8 @@ def _update_purchase_order_line(self, product_id, product_qty, product_uom, if 'orderpoint_id' in values: 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/tests/__init__.py b/stock_orderpoint_purchase_link/tests/__init__.py new file mode 100644 index 00000000..b88d2929 --- /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 00000000..accd6e31 --- /dev/null +++ b/stock_orderpoint_purchase_link/tests/test_stock_orderpoint_purchase_link.py @@ -0,0 +1,77 @@ +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# 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['procurement.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.route_warehouse0_buy').id + route_test = self.route_obj.create({ + 'name': 'Stock to Test', + }).id + self.rule_obj.create({ + 'name': 'Stock to Test', + 'action': 'move', + '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)