From cd38204fc34b87bc22042b73851eaa550144717a Mon Sep 17 00:00:00 2001 From: jbeficent Date: Tue, 12 Apr 2016 10:44:31 +0200 Subject: [PATCH] stock_mts_mto_rule --- stock_mts_mto_rule/README.rst | 2 - stock_mts_mto_rule/__manifest__.py | 4 +- stock_mts_mto_rule/model/procurement.py | 24 ++++-------- .../tests/test_mto_mts_route.py | 37 ++++++++++--------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/stock_mts_mto_rule/README.rst b/stock_mts_mto_rule/README.rst index 91c13ea9c..c17580cff 100644 --- a/stock_mts_mto_rule/README.rst +++ b/stock_mts_mto_rule/README.rst @@ -70,8 +70,6 @@ stock-logistics-warehouse/issues/new?body=module:%20 stock_mts_mto_rule%0Aversion:%20 8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. -Note: In order to see this option, you must enable "Manage advanced routes for your warehouse" under Settings -> Configuration -> Warehouse. - Credits ======= diff --git a/stock_mts_mto_rule/__manifest__.py b/stock_mts_mto_rule/__manifest__.py index bb2d0911a..67640dd6b 100644 --- a/stock_mts_mto_rule/__manifest__.py +++ b/stock_mts_mto_rule/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################## {'name': 'Stock MTS+MTO Rule', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'license': 'AGPL-3', @@ -34,5 +34,5 @@ 'view/pull_rule.xml', 'view/warehouse.xml', ], - 'installable': False, + 'installable': True, } diff --git a/stock_mts_mto_rule/model/procurement.py b/stock_mts_mto_rule/model/procurement.py index 2a8586c57..14d66b2cf 100644 --- a/stock_mts_mto_rule/model/procurement.py +++ b/stock_mts_mto_rule/model/procurement.py @@ -19,7 +19,7 @@ # along with this program. If not, see . # ############################################################################### -from openerp import models, api, fields +from openerp import api, fields, models class ProcurementOrder(models.Model): @@ -52,14 +52,13 @@ class ProcurementOrder(models.Model): return self.product_qty @api.model - def _get_mts_mto_procurement(self, proc, rule, qty, uos_qty): + def _get_mts_mto_procurement(self, proc, rule, qty): origin = (proc.group_id and (proc.group_id.name + ":") or "") + \ (proc.rule_id and proc.rule_id.name or proc.origin or "/") return { 'name': proc.name, 'origin': origin, 'product_qty': qty, - 'product_uos_qty': uos_qty, 'rule_id': rule.id, 'mts_mto_procurement_id': proc.id, } @@ -94,37 +93,28 @@ class ProcurementOrder(models.Model): procurement.rule_id.action == 'split_procurement': if procurement.mts_mto_procurement_ids: return super(ProcurementOrder, self)._run(procurement) - uom_obj = self.env['product.uom'] needed_qty = procurement.get_mto_qty_to_order() rule = procurement.rule_id if needed_qty == 0.0: mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, procurement.product_qty, - procurement.product_uos_qty) + procurement, rule.mts_rule_id, procurement.product_qty) mts_proc = procurement.copy(mts_vals) mts_proc.run() elif needed_qty == procurement.product_qty: mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, procurement.product_qty, - procurement.product_uos_qty) + procurement, rule.mto_rule_id, procurement.product_qty) mto_proc = procurement.copy(mto_vals) mto_proc.run() else: mts_qty = procurement.product_qty - needed_qty - mts_uos_qty = uom_obj._compute_qty( - procurement.product_uom.id, - mts_qty, - procurement.product_uos.id) mts_vals = self._get_mts_mto_procurement( - procurement, rule.mts_rule_id, mts_qty, mts_uos_qty) + procurement, rule.mts_rule_id, mts_qty) mts_proc = procurement.copy(mts_vals) mts_proc.run() - uos_qty = procurement.product_uos_qty mto_vals = self._get_mts_mto_procurement( - procurement, rule.mto_rule_id, needed_qty, - uos_qty - mts_uos_qty) - + procurement, rule.mto_rule_id, needed_qty) mto_proc = procurement.copy(mto_vals) mto_proc.run() + return super(ProcurementOrder, self)._run(procurement) diff --git a/stock_mts_mto_rule/tests/test_mto_mts_route.py b/stock_mts_mto_rule/tests/test_mto_mts_route.py index eacf3c3e4..838c3a0c3 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -19,10 +19,24 @@ from datetime import datetime class TestMtoMtsRoute(TransactionCase): + def _procurement_create(self): + self.procurement = self.env['procurement.order'].create({ + 'location_id': self.env.ref('stock.stock_location_customers').id, + 'product_id': self.product.id, + 'product_qty': 2.0, + 'product_uom': 1, + 'warehouse_id': self.warehouse.id, + 'priority': '1', + 'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + 'name': self.product.name, + 'origin': 'test', + 'group_id': self.group.id, + }) + def test_standard_mto_route(self): mto_route = self.env.ref('stock.route_warehouse0_mto') self.product.route_ids = [(6, 0, [mto_route.id])] - self.procurement.run() + self._procurement_create() self.assertEqual(self.warehouse.mto_pull_id, self.procurement.rule_id) self.assertEqual('make_to_order', @@ -33,7 +47,7 @@ class TestMtoMtsRoute(TransactionCase): self.procurement.move_ids[0].state) def test_standard_mts_route(self): - self.procurement.run() + self._procurement_create() procurement_id = self.procurement_obj.search([ ('group_id', '=', self.procurement.group_id.id), ('move_ids', '!=', False)], limit=1) @@ -48,7 +62,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 1.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(2, len(moves)) @@ -58,7 +72,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 0.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(1, len(moves)) @@ -70,7 +84,7 @@ class TestMtoMtsRoute(TransactionCase): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') self.product.route_ids = [(6, 0, [mto_mts_route.id])] self.quant.qty = 3.0 - self.procurement.run() + self._procurement_create() moves = self.env['stock.move'].search( [('group_id', '=', self.group.id)]) self.assertEqual(1, len(moves)) @@ -88,18 +102,7 @@ class TestMtoMtsRoute(TransactionCase): self.group = self.env['procurement.group'].create({ 'name': 'test', }) - self.procurement = self.env['procurement.order'].create({ - 'location_id': self.env.ref('stock.stock_location_customers').id, - 'product_id': self.product.id, - 'product_qty': 2.0, - 'product_uom': 1, - 'warehouse_id': self.warehouse.id, - 'priority': '1', - 'date_planned': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - 'name': self.product.name, - 'origin': 'test', - 'group_id': self.group.id, - }) + self.quant = self.env['stock.quant'].create({ 'owner_id': self.company_partner.id, 'location_id': self.env.ref('stock.stock_location_stock').id,