diff --git a/stock_orderpoint_uom/__manifest__.py b/stock_orderpoint_uom/__manifest__.py index a3e5cb516..aef50e657 100644 --- a/stock_orderpoint_uom/__manifest__.py +++ b/stock_orderpoint_uom/__manifest__.py @@ -1,12 +1,11 @@ -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Stock Orderpoint UoM", "summary": "Allows to create procurement orders in the UoM indicated in " "the orderpoint", - "version": "12.0.1.1.0", - "author": "Eficent, " "Odoo Community Association (OCA)", + "version": "13.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", "depends": ["purchase_stock"], diff --git a/stock_orderpoint_uom/models/procurement_group.py b/stock_orderpoint_uom/models/procurement_group.py index b3f3d3722..e56f759eb 100644 --- a/stock_orderpoint_uom/models/procurement_group.py +++ b/stock_orderpoint_uom/models/procurement_group.py @@ -1,5 +1,6 @@ # Copyright (C) 2018 - TODAY, Open Source Integrators -# (http://www.opensourceintegrators.com) +# (http://www.opensourceintegrators.com) +# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, models @@ -9,16 +10,40 @@ 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") - if orderpoint.procure_uom_id and product_uom != orderpoint.procure_uom_id: - product_qty = product_uom._compute_quantity( - product_qty, orderpoint.procure_uom_id - ) - product_uom = orderpoint.procure_uom_id - return super(ProcurementGroup, self).run( - product_id, product_qty, product_uom, location_id, name, origin, values - ) + def run(self, procurements): + # 'Procurement' is a 'namedtuple', which is not editable. + # The 'procurement' which needs to be edited is created new + # and the previous one is deleted. + Proc = self.env["procurement.group"].Procurement + indexes_to_pop = [] + new_procs = [] + for i, procurement in enumerate(procurements): + if "orderpoint_id" in procurement.values: + orderpoint = procurement.values.get("orderpoint_id") + if ( + orderpoint.procure_uom_id + and procurement.product_uom != orderpoint.procure_uom_id + ): + new_product_qty = procurement.product_uom._compute_quantity( + procurement.product_qty, orderpoint.procure_uom_id + ) + new_product_uom = orderpoint.procure_uom_id + new_procs.append( + Proc( + procurement.product_id, + new_product_qty, + new_product_uom, + procurement.location_id, + procurement.name, + procurement.origin, + procurement.company_id, + procurement.values, + ) + ) + indexes_to_pop.append(i) + if new_procs: + indexes_to_pop.reverse() + for index in indexes_to_pop: + procurements.pop(index) + procurements.extend(new_procs) + return super(ProcurementGroup, self).run(procurements) diff --git a/stock_orderpoint_uom/models/product_template.py b/stock_orderpoint_uom/models/product_template.py index d81ae6d9d..2081973bf 100644 --- a/stock_orderpoint_uom/models/product_template.py +++ b/stock_orderpoint_uom/models/product_template.py @@ -1,5 +1,4 @@ -# Copyright 2018 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import _, api, models diff --git a/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py index ed474b718..fe60ea664 100644 --- a/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_uom/models/stock_warehouse_orderpoint.py @@ -1,9 +1,8 @@ -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import _, api, fields, models -from odoo.exceptions import UserError +from odoo.exceptions import ValidationError class Orderpoint(models.Model): @@ -20,7 +19,7 @@ class Orderpoint(models.Model): != orderpoint.procure_uom_id.category_id for orderpoint in self ): - raise UserError( + raise ValidationError( _( "Error: The product default Unit of Measure and " "the procurement Unit of Measure must be in the " diff --git a/stock_orderpoint_uom/readme/CONTRIBUTORS.rst b/stock_orderpoint_uom/readme/CONTRIBUTORS.rst index 2e04b89ae..62f6df667 100644 --- a/stock_orderpoint_uom/readme/CONTRIBUTORS.rst +++ b/stock_orderpoint_uom/readme/CONTRIBUTORS.rst @@ -1,4 +1,5 @@ -* Jordi Ballester Alomar -* Lois Rilo +* Jordi Ballester Alomar +* Lois Rilo * Bhavesh Odedra * Kitti Upariphutthiphong +* Joan Sisquella 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 ae9be69af..a05886d59 100644 --- a/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py +++ b/stock_orderpoint_uom/tests/test_stock_orderpoint_procure_uom.py @@ -1,5 +1,4 @@ -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# (http://www.eficent.com) +# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import odoo.tests.common as common @@ -46,7 +45,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase): } ) - def test_stock_orderpoint_procure_uom(self): + def test_01_stock_orderpoint_procure_uom(self): orderpoint = self.env["stock.warehouse.orderpoint"].create( { @@ -72,7 +71,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase): self.assertEqual(purchase_line.product_uom, self.uom_dozen) self.assertEqual(purchase_line.product_qty, 2) - def test_stock_orderpoint_wrong_uom(self): + def test_02_stock_orderpoint_wrong_uom(self): with mute_logger("openerp.sql_db"): with self.assertRaises(ValidationError): @@ -87,7 +86,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase): } ) - def test_regenerate_po(self): + def test_03_regenerate_po(self): def _assert_purchase_generated(self, supplier, product): purchase = self.purchase_model.search([("partner_id", "=", supplier.id)]) self.assertEquals(len(purchase), 1) @@ -99,7 +98,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase): return purchase supplier = self.env["res.partner"].create( - {"name": "Brewery Inc", "is_company": True, "supplier": True} + {"name": "Brewery Inc", "is_company": True} ) product = self.env["product.product"].create( diff --git a/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml b/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml index 68214d35d..6c7396558 100644 --- a/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml +++ b/stock_orderpoint_uom/views/stock_warehouse_orderpoint_view.xml @@ -19,9 +19,11 @@ - - + + + + +

Quantity Multiple is applied to the base UoM.