Skip to content

Commit

Permalink
[FIX]remove dependency to sale_sourced_by_line
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Dec 4, 2018
1 parent 9993432 commit 8e9f443
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
11 changes: 2 additions & 9 deletions sale_procurement_group_by_requested_date/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})

Expand All @@ -62,66 +55,60 @@ 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:
if group.name == g_name:
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)

0 comments on commit 8e9f443

Please sign in to comment.