From adc49e4446b98eff2709942cf2da46023dbaa180 Mon Sep 17 00:00:00 2001 From: JulioSerna Date: Tue, 5 Jan 2016 20:49:12 +0000 Subject: [PATCH] set pull rule of customer location like split_procurement to allow when warehouse is two/three steps delivery propagate move by mts-mto in pick/pack/out --- stock_mts_mto_rule/model/warehouse.py | 26 ++++++++++++++++++- .../tests/test_mto_mts_route.py | 10 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/stock_mts_mto_rule/model/warehouse.py b/stock_mts_mto_rule/model/warehouse.py index 6f06ada0f..0c10b17aa 100644 --- a/stock_mts_mto_rule/model/warehouse.py +++ b/stock_mts_mto_rule/model/warehouse.py @@ -70,6 +70,26 @@ class Warehouse(models.Model): 'picking_type_id': warehouse.mto_pull_id.picking_type_id.id, } + @api.model + def _get_push_pull_rules(self, warehouse, active, values, new_route_id): + pull_obj = self.env['procurement.rule'] + res = super(Warehouse, self)._get_push_pull_rules( + warehouse, active, values, new_route_id) + customer_location = warehouse._get_partner_locations() + location_id = customer_location[0].id + if warehouse.mto_mts_management: + for pull in res[1]: + if pull['location_id'] == location_id: + pull_mto_mts = pull.copy() + pull_mto_mts_id = pull_obj.create(pull_mto_mts) + pull.update({ + 'action': 'split_procurement', + 'mto_rule_id': pull_mto_mts_id.id, + 'mts_rule_id': pull_mto_mts_id.id, + 'sequence': 10 + }) + return res + @api.multi def create_routes(self, warehouse): pull_model = self.env['procurement.rule'] @@ -94,7 +114,11 @@ class Warehouse(models.Model): for warehouse in self: if warehouse.mts_mto_rule_id: warehouse.mts_mto_rule_id.unlink() - return super(Warehouse, self).write(vals) + res = super(Warehouse, self).write(vals) + if 'mto_mts_management' in vals: + self.with_context({'active_test': False}).change_route( + warehouse, new_delivery_step=warehouse.delivery_steps) + return res @api.model def get_all_routes_for_wh(self, warehouse): 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 bc38de754..eacf3c3e4 100644 --- a/stock_mts_mto_rule/tests/test_mto_mts_route.py +++ b/stock_mts_mto_rule/tests/test_mto_mts_route.py @@ -34,12 +34,15 @@ class TestMtoMtsRoute(TransactionCase): def test_standard_mts_route(self): self.procurement.run() + procurement_id = self.procurement_obj.search([ + ('group_id', '=', self.procurement.group_id.id), + ('move_ids', '!=', False)], limit=1) self.assertEqual('make_to_stock', - self.procurement.move_ids[0].procure_method) + procurement_id.move_ids[0].procure_method) self.assertEqual(self.procurement.product_qty, - self.procurement.move_ids[0].product_uom_qty) + procurement_id.move_ids[0].product_uom_qty) self.assertEqual('confirmed', - self.procurement.move_ids[0].state) + procurement_id.move_ids[0].state) def test_mts_mto_route_split(self): mto_mts_route = self.env.ref('stock_mts_mto_rule.route_mto_mts') @@ -81,6 +84,7 @@ class TestMtoMtsRoute(TransactionCase): self.warehouse.mto_mts_management = True self.product = self.env.ref('product.product_product_4') self.company_partner = self.env.ref('base.main_partner') + self.procurement_obj = self.env['procurement.order'] self.group = self.env['procurement.group'].create({ 'name': 'test', })