From c4da89b808dc0c491381d65f26e72f98a528319b Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Tue, 11 Nov 2014 19:18:52 +0100 Subject: [PATCH 1/5] Set price of agreement when sourcing with a framework --- framework_agreement_sourcing/model/logistic_requisition.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework_agreement_sourcing/model/logistic_requisition.py b/framework_agreement_sourcing/model/logistic_requisition.py index c725a9da..a359124e 100644 --- a/framework_agreement_sourcing/model/logistic_requisition.py +++ b/framework_agreement_sourcing/model/logistic_requisition.py @@ -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' From d17630dc1119f5b0cc766b8c93088400fd2069c1 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 17 Nov 2014 13:38:04 +0100 Subject: [PATCH 2/5] provide more meaningful test failure messages --- .../tests/test_agreement_souce_line_to_po.py | 9 +++++---- ...test_logistic_order_line_to_source_line.py | 20 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py b/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py index 01b3bc4c..701d2936 100644 --- a/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py +++ b/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py @@ -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 = [] @@ -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') @@ -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, {}, @@ -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 diff --git a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py index cff73171..8b94c34b 100644 --- a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py +++ b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py @@ -32,12 +32,13 @@ 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') @@ -53,12 +54,13 @@ 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') @@ -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 @@ -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 From 5aac2fcd231d868dc706544a9d784049b87ab78c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 17 Nov 2014 13:42:25 +0100 Subject: [PATCH 3/5] rename test method --- .../tests/test_logistic_order_line_to_source_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py index 8b94c34b..2fda8baa 100644 --- a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py +++ b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py @@ -104,7 +104,7 @@ def test_03_not_enough_qty_on_high_agreement(self): self.assertEqual(low_line.proposed_qty, 400) self.assertAlmostEqual(low_line.unit_cost, 0.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 From 125e6a97ac3f9dba9ffa6faa6ba2e21a08c60414 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 17 Nov 2014 13:45:21 +0100 Subject: [PATCH 4/5] update the test the PR is about setting the price from the FA on sourcing line, and the tests were correct in the previous version when this was not the case. --- .../tests/test_logistic_order_line_to_source_line.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py index 2fda8baa..d277816b 100644 --- a/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py +++ b/framework_agreement_sourcing/tests/test_logistic_order_line_to_source_line.py @@ -42,7 +42,7 @@ def test_01_enough_qty_on_first_agr(self): 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): @@ -64,7 +64,7 @@ def test_02_enough_qty_on_high_agr(self): 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): @@ -93,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 @@ -102,7 +102,7 @@ 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_04_not_enough_qty_on_all_agreements(self): """Test that we have generate correct line when not enough qty on all @@ -134,7 +134,7 @@ def test_04_not_enough_qty_on_all_agreements(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 @@ -143,7 +143,7 @@ def test_04_not_enough_qty_on_all_agreements(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 From 964e0b24344f2240825fed41227056f5e4802b64 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Wed, 19 Nov 2014 11:03:31 +0100 Subject: [PATCH 5/5] Remove assert message to keep default explicit message --- .../tests/test_agreement_souce_line_to_po.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py b/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py index 701d2936..09f98d15 100644 --- a/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py +++ b/framework_agreement_sourcing/tests/test_agreement_souce_line_to_po.py @@ -45,8 +45,7 @@ def setUp(self): lid = self.requisition_line_model._generate_source_line( cr, uid, line) source_ids += lid - self.assertEqual(len(source_ids), 2, - 'wrong number of source lines') + self.assertEqual(len(source_ids), 2) 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')