From 8e9f4439ffe0fa2d12d7b2da215e86a4eb20573e Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 13 Apr 2018 15:01:42 +0200 Subject: [PATCH] [FIX]remove dependency to sale_sourced_by_line --- .../models/sale_order.py | 11 +---- ...ale_procurement_group_by_requested_date.py | 47 +++++++------------ 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/sale_procurement_group_by_requested_date/models/sale_order.py b/sale_procurement_group_by_requested_date/models/sale_order.py index d0a2e300ec84..f7e1846762de 100644 --- a/sale_procurement_group_by_requested_date/models/sale_order.py +++ b/sale_procurement_group_by_requested_date/models/sale_order.py @@ -16,10 +16,7 @@ def _prepare_procurement_group_by_line(self, line): req_datetime = fields.Datetime.from_string(line.requested_date) req_date = fields.Date.to_string(req_datetime) if line._get_procurement_group_key()[0] == 12: - if line.requested_date and line.warehouse_id: - vals['name'] = '/'.join([vals['name'], line.warehouse_id.name, - req_date]) - elif line.requested_date and not line.warehouse_id: + if line.requested_date: vals['name'] = '/'.join([vals['name'], req_date]) return vals @@ -52,10 +49,6 @@ def _get_procurement_group_key(self): return key req_datetime = fields.Datetime.from_string(self.requested_date) req_date = fields.Date.to_string(req_datetime) - if self.warehouse_id and not req_date: - return (priority, self.warehouse_id.id) - if req_date and not self.warehouse_id: + if req_date: return (priority, str(req_date)) - if self.warehouse_id and req_date: - key = '/'.join([str(self.warehouse_id.id), req_date]) return (priority, key) diff --git a/sale_procurement_group_by_requested_date/tests/test_sale_procurement_group_by_requested_date.py b/sale_procurement_group_by_requested_date/tests/test_sale_procurement_group_by_requested_date.py index 9d39c8c8a165..d29405357ec8 100644 --- a/sale_procurement_group_by_requested_date/tests/test_sale_procurement_group_by_requested_date.py +++ b/sale_procurement_group_by_requested_date/tests/test_sale_procurement_group_by_requested_date.py @@ -19,9 +19,6 @@ def setUp(self): sale_obj = self.env['sale.order'] order_line = self.env['sale.order.line'] Product = self.env['product.product'] - Warehouse = self.env['stock.warehouse'] - self.wh1 = Warehouse.create({'name': 'wh1', 'code': 'wh1'}) - self.wh2 = Warehouse.create({'name': 'wh2', 'code': 'wh2'}) p1 = Product.create({'name': 'p1', 'type': 'product'}).id today = datetime.datetime.now() self.dt1 = today @@ -32,28 +29,24 @@ def setUp(self): 'product_id': p1, 'name': 'cool product', 'order_id': self.sale1.id, - 'warehouse_id': self.wh1.id, 'requested_date': self.dt1 }) self.sale_line2 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale1.id, - 'warehouse_id': self.wh1.id, 'requested_date': self.dt2 }) self.sale_line3 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale1.id, - 'warehouse_id': self.wh2.id, 'requested_date': self.dt1 }) self.sale_line4 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale1.id, - 'warehouse_id': self.wh2.id, 'requested_date': self.dt2 }) @@ -62,54 +55,45 @@ def setUp(self): 'product_id': p1, 'name': 'cool product', 'order_id': self.sale2.id, - 'warehouse_id': self.wh1.id, 'requested_date': self.dt1 }) self.sale_line6 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale2.id, - 'warehouse_id': self.wh1.id, - 'requested_date': self.dt2 + 'requested_date': self.dt1 }) self.sale_line7 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale2.id, - 'warehouse_id': self.wh1.id, 'requested_date': self.dt1 }) self.sale_line8 = order_line.create({ 'product_id': p1, 'name': 'cool product', 'order_id': self.sale2.id, - 'warehouse_id': self.wh1.id, - 'requested_date': self.dt2 + 'requested_date': self.dt1 }) def test_number_of_groups(self): """True when the number of groups created matches the result of multiply the different warehouses with the different requested dates""" - ok = False self.sale1.action_confirm() req_date = fields.Date.to_string(self.dt1) - g_name = self.sale1.name + '/' + self.wh1.name + '/' + req_date + g_name = self.sale1.name + '/' + req_date groups = self.env['procurement.group'].search([('name', '=', g_name)]) for group in groups: if group.name == g_name: procurements = self.env['procurement.order'].search([ ('group_id', '=', group.id)]) - self.assertEqual(len(procurements), 1) - self.assertEqual(len(group), 1) - ok = True - self.assertTrue(ok) + self.assertEqual(len(procurements), 2) + self.assertEqual(len(groups), 1) - ok = False - self.sale2.action_confirm() - req_date = fields.Date.to_string(self.dt2) - g_name = self.sale2.name + '/' + self.wh1.name + '/' + req_date + req_date2 = fields.Date.to_string(self.dt2) + g_name = self.sale1.name + '/' + req_date2 groups = self.env['procurement.group'].search([('name', '=', g_name)]) for group in groups: @@ -117,11 +101,14 @@ def test_number_of_groups(self): procurements = self.env['procurement.order'].search([ ('group_id', '=', group.id)]) self.assertEqual(len(procurements), 2) - self.assertEqual(len(group), 1) - ok = True self.assertEqual(len(groups), 1) - g_name = self.sale2.name + '/' + self.wh1.name + '/' - groups = self.env['procurement.group'].search([('name', 'ilike', - g_name)]) - self.assertEqual(len(groups), 2) - self.assertTrue(ok) + + self.sale2.action_confirm() + g_name = self.sale2.name + '/' + req_date + groups = self.env['procurement.group'].search([('name', '=', g_name)]) + for group in groups: + if group.name == g_name: + procurements = self.env['procurement.order'].search([ + ('group_id', '=', group.id)]) + self.assertEqual(len(procurements), 4) + self.assertEqual(len(groups), 1)