From ca5484203222fd5bd85b35d7a56379f84e8b19ce Mon Sep 17 00:00:00 2001 From: Bhavesh Odedra Date: Tue, 27 Feb 2018 21:21:23 +0530 Subject: [PATCH] [MIG] stock_orderpoint_uom: Migration to 11.0 --- stock_orderpoint_uom/README.rst | 11 ++++---- stock_orderpoint_uom/__init__.py | 1 - stock_orderpoint_uom/__manifest__.py | 6 ++--- stock_orderpoint_uom/demo/product.xml | 10 +++++++ stock_orderpoint_uom/models/__init__.py | 2 +- .../models/procurement_group.py | 20 ++++++++++++++ .../models/product_template.py | 1 - .../models/stock_warehouse_orderpoint.py | 12 --------- stock_orderpoint_uom/tests/__init__.py | 1 - .../test_stock_orderpoint_procure_uom.py | 27 ++++++++++++++----- 10 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 stock_orderpoint_uom/demo/product.xml create mode 100644 stock_orderpoint_uom/models/procurement_group.py diff --git a/stock_orderpoint_uom/README.rst b/stock_orderpoint_uom/README.rst index 156b1d7ab..de6ce80fd 100644 --- a/stock_orderpoint_uom/README.rst +++ b/stock_orderpoint_uom/README.rst @@ -19,19 +19,18 @@ Configuration ============= To configure this module, you need to 'Inventory > Configuration > Settings' -and enable 'Some products may be sold/purchased in different unit of measures -(advanced)' option. +and enable 'Sell and purchase products in different units of measure' option. Usage ===== -Go to 'Inventory > Inventory Control > Reordering Rules' and indicate a -Procurement UoM. +Go to 'Inventory > Master Data > Reordering Rules' and indicate a Procurement +UoM. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/153/10.0 + :target: https://runbot.odoo-community.org/runbot/153/11.0 Bug Tracker =========== @@ -54,7 +53,7 @@ Contributors * Jordi Ballester Alomar * Lois Rilo - +* Bhavesh Odedra Maintainer ---------- diff --git a/stock_orderpoint_uom/__init__.py b/stock_orderpoint_uom/__init__.py index b24d567fe..b52a76e1a 100644 --- a/stock_orderpoint_uom/__init__.py +++ b/stock_orderpoint_uom/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-17 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). diff --git a/stock_orderpoint_uom/__manifest__.py b/stock_orderpoint_uom/__manifest__.py index bafbbca54..145ec2cee 100644 --- a/stock_orderpoint_uom/__manifest__.py +++ b/stock_orderpoint_uom/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-17 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). @@ -6,12 +5,13 @@ "name": "Stock Orderpoint UoM", "summary": "Allows to create procurement orders in the UoM indicated in " "the orderpoint", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Eficent, " "Odoo Community Association (OCA)", "website": "https://www.odoo-community.org", "category": "Warehouse Management", - "depends": ["stock"], + "depends": ["purchase", "stock"], + "demo": ["demo/product.xml"], "data": ["views/stock_warehouse_orderpoint_view.xml"], "license": "AGPL-3", 'installable': True, diff --git a/stock_orderpoint_uom/demo/product.xml b/stock_orderpoint_uom/demo/product.xml new file mode 100644 index 000000000..a2831566c --- /dev/null +++ b/stock_orderpoint_uom/demo/product.xml @@ -0,0 +1,10 @@ + + + + + + 3 + 1 + 72 + + diff --git a/stock_orderpoint_uom/models/__init__.py b/stock_orderpoint_uom/models/__init__.py index ec739420c..128caa2a3 100644 --- a/stock_orderpoint_uom/models/__init__.py +++ b/stock_orderpoint_uom/models/__init__.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import stock_warehouse_orderpoint from . import product_template +from . import procurement_group diff --git a/stock_orderpoint_uom/models/procurement_group.py b/stock_orderpoint_uom/models/procurement_group.py new file mode 100644 index 000000000..0325ee452 --- /dev/null +++ b/stock_orderpoint_uom/models/procurement_group.py @@ -0,0 +1,20 @@ +# Copyright (C) 2018 - TODAY, Open Source Integrators +# (http://www.opensourceintegrators.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ProcurementGroup(models.Model): + _inherit = "procurement.group" + + @api.model + def run(self, product_id, product_qty, product_uom, location_id, name, + origin, values): + if 'orderpoint_id' in values: + orderpoint = values.get('orderpoint_id') + product_qty = orderpoint.product_uom._compute_quantity( + product_qty, orderpoint.procure_uom_id) + return super(ProcurementGroup, self).run(product_id, product_qty, + product_uom, location_id, + name, origin, values) diff --git a/stock_orderpoint_uom/models/product_template.py b/stock_orderpoint_uom/models/product_template.py index 78ca59ec4..12e097db3 100644 --- a/stock_orderpoint_uom/models/product_template.py +++ b/stock_orderpoint_uom/models/product_template.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 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). diff --git a/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py index 9127f6c98..8be67a254 100644 --- a/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-17 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). @@ -25,14 +24,3 @@ class Orderpoint(models.Model): 'the procurement Unit of Measure must be in the ' 'same category.')) return True - - @api.model - def _prepare_procurement_values(self, product_qty, - date=False, group=False): - res = super(Orderpoint, self)._prepare_procurement_values( - product_qty, date, group) - if self.procure_uom_id: - res['product_qty'] = self.product_uom._compute_quantity( - product_qty, self.procure_uom_id) - res['product_uom'] = self.procure_uom_id.id - return res diff --git a/stock_orderpoint_uom/tests/__init__.py b/stock_orderpoint_uom/tests/__init__.py index 09e60ed30..039371258 100644 --- a/stock_orderpoint_uom/tests/__init__.py +++ b/stock_orderpoint_uom/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-17 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). diff --git a/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py b/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py index 06862ff53..7d15a02eb 100644 --- a/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py +++ b/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016-17 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). @@ -12,7 +11,14 @@ class TestStockOrderpointProcureUom(common.TransactionCase): def setUp(self): super(TestStockOrderpointProcureUom, self).setUp() + # Refs + self.vendor = self.env.ref( + 'stock_orderpoint_uom.product_supplierinfo_product_7') + + # Get required Model productObj = self.env['product.product'] + self.purchase_model = self.env['purchase.order'] + self.purchase_line_model = self.env['purchase.order.line'] self.warehouse = self.env.ref('stock.warehouse0') self.location_stock = self.env.ref('stock.stock_location_stock') self.uom_unit = self.env.ref('product.product_uom_unit') @@ -25,24 +31,31 @@ class TestStockOrderpointProcureUom(common.TransactionCase): 'type': 'product', 'uom_id': self.uom_unit.id, 'default_code': 'A', + 'variant_seller_ids': [(6, 0, [self.vendor.id])], }) def test_stock_orderpoint_procure_uom(self): - self.env['stock.warehouse.orderpoint'].create({ + orderpoint = self.env['stock.warehouse.orderpoint'].create({ 'warehouse_id': self.warehouse.id, 'location_id': self.location_stock.id, 'product_id': self.productA.id, 'product_max_qty': 24, 'product_min_qty': 12, + 'product_uom': self.uom_unit.id, 'procure_uom_id': self.uom_dozen.id, }) - sched = self.env['procurement.order'] - sched.run_scheduler() - proc = sched.search([('product_id', '=', self.productA.id)]) - self.assertEqual(proc.product_uom, self.uom_dozen) - self.assertEqual(proc.product_qty, 2) + self.env['procurement.group'].run_scheduler() + # As per route configuration, it will create Purchase order + purchase = self.purchase_model.search( + [('origin', 'ilike', orderpoint.name)]) + self.assertEquals(len(purchase), 1) + purchase_line = self.purchase_line_model.search( + [('orderpoint_id', '=', orderpoint.id), + ('order_id', '=', purchase.id)]) + self.assertEquals(len(purchase_line), 1) + self.assertEqual(purchase_line.product_qty, 2.0) def test_stock_orderpoint_wrong_uom(self):