Skip to content

Commit

Permalink
Merge 033c96c into d1361fe
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Nov 17, 2014
2 parents d1361fe + 033c96c commit 3fb44a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
7 changes: 5 additions & 2 deletions framework_agreement_sourcing/model/logistic_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def _prepare_line_source(self, cr, uid, line,
if not agreement.product_id.id == line.product_id.id:
raise ValueError(
"Product mismatch for agreement and requisition line")
res['framework_agreement_id'] = agreement.id
res['procurement_method'] = 'fw_agreement'
res.update({
'framework_agreement_id': agreement.id,
'procurement_method': 'fw_agreement',
'unit_cost': agreement.get_price(qty, line.currency_id),
})
else:
if line.product_id.type == 'product':
res['procurement_method'] = 'procurement'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
if line.product_id == self.cheap_on_low_agreement.product_id:
agr_line = line
break
self.assertTrue(agr_line)
self.assertTrue(agr_line, 'no agr line found')
agr_line.write({'requested_qty': 400})
agr_line.refresh()
source_ids = []
Expand All @@ -45,7 +45,8 @@ def setUp(self):
lid = self.requisition_line_model._generate_source_line(
cr, uid, line)
source_ids += lid
self.assertTrue(len(source_ids) == 2)
self.assertEqual(len(source_ids), 2,
'wrong number of source lines')
self.source_lines = self.source_line_model.browse(cr, uid, source_ids)
self.lta_source = next(x for x in self.source_lines
if x.procurement_method == 'fw_agreement')
Expand All @@ -55,7 +56,7 @@ def setUp(self):
def test_01_transform_source_to_agreement(self):
"""Test transformation of an agreement source line into PO"""
cr, uid = self.cr, self.uid
self.assertTrue(self.lta_source)
self.assertTrue(self.lta_source, 'no lta source found')
self.lta_source.refresh()
active_ids = [x.id for x in self.source_lines]
wiz_id = self.wiz_model.create(self.cr, self.uid, {},
Expand All @@ -64,7 +65,7 @@ def test_01_transform_source_to_agreement(self):
po_id = self.wiz_model.action_create_agreement_po_requisition(
cr, uid, [wiz_id], context={'active_ids': active_ids}
)['res_id']
self.assertTrue(po_id)
self.assertTrue(po_id, "no PO created")
supplier = self.lta_source.framework_agreement_id.supplier_id
add = self.lta_source.requisition_id.consignee_shipping_id
consignee = self.lta_source.requisition_id.consignee_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ def test_01_enough_qty_on_first_agr(self):
if line.product_id == self.cheap_on_low_agreement.product_id:
agr_line = line
break
self.assertTrue(agr_line)
self.assertTrue(agr_line, 'no agr line found')
agr_line.write({'requested_qty': 400})
agr_line.refresh()
to_validate_ids = self.requisition_line_model._generate_source_line(
cr, uid, agr_line)
self.assertTrue(len(to_validate_ids) == 1)
self.assertEqual(len(to_validate_ids), 1,
'wrong number of source line to validate')
to_validate = self.source_line_model.browse(
cr, uid, to_validate_ids[0])
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 0.0)
self.assertAlmostEqual(to_validate.unit_cost, 50.0)
self.assertEqual(to_validate.proposed_qty, 400)

def test_02_enough_qty_on_high_agr(self):
Expand All @@ -53,16 +54,17 @@ def test_02_enough_qty_on_high_agr(self):
if line.product_id == self.cheap_on_high_agreement.product_id:
agr_line = line
break
self.assertTrue(agr_line)
self.assertTrue(agr_line, 'no agr line found')
agr_line.write({'requested_qty': 1500})
agr_line.refresh()
to_validate_ids = self.requisition_line_model._generate_source_line(
cr, uid, agr_line)
self.assertTrue(len(to_validate_ids) == 1)
self.assertEqual(len(to_validate_ids), 1,
'wrong number of source line to validate')
to_validate = self.source_line_model.browse(
cr, uid, to_validate_ids[0])
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 0.0)
self.assertAlmostEqual(to_validate.unit_cost, 30.0)
self.assertEqual(to_validate.proposed_qty, 1500)

def test_03_not_enough_qty_on_high_agreement(self):
Expand All @@ -74,12 +76,13 @@ def test_03_not_enough_qty_on_high_agreement(self):
if line.product_id == self.cheap_on_high_agreement.product_id:
agr_line = line
break
self.assertTrue(agr_line)
self.assertTrue(agr_line, 'no agr line found')
agr_line.write({'requested_qty': 2400})
agr_line.refresh()
to_validate_ids = self.requisition_line_model._generate_source_line(
cr, uid, agr_line)
self.assertTrue(len(to_validate_ids) == 2)
self.assertEqual(len(to_validate_ids), 2,
'wrong number of source line to validate')
# We validate generated line
to_validates = self.source_line_model.browse(cr, uid, to_validate_ids)
# high_line
Expand All @@ -90,7 +93,7 @@ def test_03_not_enough_qty_on_high_agreement(self):
self.assertTrue(high_line, msg="High agreement was not used")
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 0.0)
self.assertAlmostEqual(high_line.unit_cost, 30.0)

# low_line
low_line = next((x for x in to_validates
Expand All @@ -99,9 +102,9 @@ def test_03_not_enough_qty_on_high_agreement(self):
self.assertTrue(low_line, msg="Low agreement was not used")
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 400)
self.assertAlmostEqual(low_line.unit_cost, 0.0)
self.assertAlmostEqual(low_line.unit_cost, 50.0)

def test_03_not_enough_qty_on_all_agreemenst(self):
def test_04_not_enough_qty_on_all_agreements(self):
"""Test that we have generate correct line when not enough qty on all
agreements
Expand All @@ -114,12 +117,13 @@ def test_03_not_enough_qty_on_all_agreemenst(self):
if line.product_id == self.cheap_on_high_agreement.product_id:
agr_line = line
break
self.assertTrue(agr_line)
self.assertTrue(agr_line, 'no agr line found')
agr_line.write({'requested_qty': 5000})
agr_line.refresh()
to_validate_ids = self.requisition_line_model._generate_source_line(
cr, uid, agr_line)
self.assertTrue(len(to_validate_ids) == 3)
self.assertEqual(len(to_validate_ids), 3,
'wrong number of source line to validate')
# We validate generated line
to_validates = self.source_line_model.browse(cr, uid, to_validate_ids)
# high_line
Expand All @@ -130,7 +134,7 @@ def test_03_not_enough_qty_on_all_agreemenst(self):
self.assertTrue(high_line, msg="High agreement was not used")
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 0.0)
self.assertAlmostEqual(high_line.unit_cost, 30.0)

# low_line
low_line = next((x for x in to_validates
Expand All @@ -139,7 +143,7 @@ def test_03_not_enough_qty_on_all_agreemenst(self):
self.assertTrue(low_line, msg="Low agreement was not used")
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 1200)
self.assertAlmostEqual(low_line.unit_cost, 0.0)
self.assertAlmostEqual(low_line.unit_cost, 45.0)

# Tender line
tender_line = next((x for x in to_validates
Expand Down

0 comments on commit 3fb44a0

Please sign in to comment.