|
|
@ -6,6 +6,7 @@ from openerp.tests.common import TransactionCase |
|
|
|
|
|
|
|
|
|
|
|
class TestPartnerSaleRisk(TransactionCase): |
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
super(TestPartnerSaleRisk, self).setUp() |
|
|
|
self.env.user.groups_id |= self.env.ref('base.group_sale_manager') |
|
|
@ -25,29 +26,122 @@ class TestPartnerSaleRisk(TransactionCase): |
|
|
|
'product_uom': self.product.uom_id.id, |
|
|
|
'price_unit': 100.0})], |
|
|
|
}) |
|
|
|
self.wizard = self.env[ |
|
|
|
"sale.advance.payment.inv"] |
|
|
|
|
|
|
|
def test_sale_order(self): |
|
|
|
self.sale_order.action_confirm() |
|
|
|
self.assertAlmostEqual(self.partner.risk_sale_order, 100.0) |
|
|
|
self.assertFalse(self.partner.risk_exception) |
|
|
|
self.partner.risk_sale_order_limit = 99.0 |
|
|
|
self.assertTrue(self.partner.risk_exception) |
|
|
|
sale_order2 = self.sale_order.copy() |
|
|
|
wiz_dic = sale_order2.action_confirm() |
|
|
|
def test_sale_order_1(self): |
|
|
|
""" |
|
|
|
Scenario: |
|
|
|
* 1 sale order @ 100 EUR |
|
|
|
* Manual invoice policy |
|
|
|
* Invoice all |
|
|
|
* Risk sale order not include |
|
|
|
* No invoice risk |
|
|
|
|
|
|
|
Expected result: |
|
|
|
* Sale order can be confirm |
|
|
|
* Invoice can be validate |
|
|
|
""" |
|
|
|
self.sale_order.action_button_confirm() |
|
|
|
self.assertEqual( |
|
|
|
self.sale_order.state, |
|
|
|
"manual") |
|
|
|
wizard = self.wizard.with_context({ |
|
|
|
"active_ids": [self.sale_order.id]}).\ |
|
|
|
create({ |
|
|
|
"advance_payment_method": "all"}) |
|
|
|
wizard.create_invoices() |
|
|
|
self.sale_order.invoice_ids.signal_workflow("invoice_open") |
|
|
|
|
|
|
|
def test_sale_order_2(self): |
|
|
|
""" |
|
|
|
Scenario: |
|
|
|
* 1 sale order @ 100 EUR |
|
|
|
* Manual invoice policy |
|
|
|
* Invoice all |
|
|
|
* Sale Order Limit == 75 EUR |
|
|
|
* Risk sale order not include |
|
|
|
* No invoice risk |
|
|
|
|
|
|
|
Expected result: |
|
|
|
* Sale order exceeds the sale order risk raised |
|
|
|
""" |
|
|
|
|
|
|
|
self.partner.write({ |
|
|
|
"risk_sale_order_limit": 75.0, |
|
|
|
"credit_limit": 150.0, |
|
|
|
}) |
|
|
|
wiz_dic = self.sale_order.action_button_confirm() |
|
|
|
wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id']) |
|
|
|
self.assertEqual(wiz.exception_msg, "Financial risk exceeded.\n") |
|
|
|
self.partner.risk_sale_order_limit = 150.0 |
|
|
|
wiz_dic = sale_order2.action_confirm() |
|
|
|
self.assertEqual( |
|
|
|
wiz.exception_msg, |
|
|
|
"This sale order exceeds the sales orders risk.\n") |
|
|
|
|
|
|
|
def test_sale_order_3(self): |
|
|
|
""" |
|
|
|
Scenario: |
|
|
|
* 1 sale order @ 100 EUR |
|
|
|
* Manual invoice policy |
|
|
|
* Invoice all |
|
|
|
* Sale Order Limit == 100 EUR |
|
|
|
* Credit Limit == 75 EUR |
|
|
|
* Risk sale order include |
|
|
|
* No invoice risk |
|
|
|
|
|
|
|
Expected result: |
|
|
|
* Sale order exceeds the financial risk raised |
|
|
|
""" |
|
|
|
|
|
|
|
self.partner.write({ |
|
|
|
"risk_sale_order_limit": 115.0, |
|
|
|
"credit_limit": 75.0, |
|
|
|
"risk_sale_order_include": True, |
|
|
|
}) |
|
|
|
wiz_dic = self.sale_order.action_button_confirm() |
|
|
|
wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id']) |
|
|
|
self.assertEqual(wiz.exception_msg, |
|
|
|
"This sale order exceeds the sales orders risk.\n") |
|
|
|
self.partner.risk_sale_order_limit = 0.0 |
|
|
|
self.partner.risk_sale_order_include = True |
|
|
|
self.partner.credit_limit = 100.0 |
|
|
|
wiz_dic = sale_order2.action_confirm() |
|
|
|
self.assertEqual( |
|
|
|
wiz.exception_msg, |
|
|
|
"This sale order exceeds the financial risk.\n") |
|
|
|
|
|
|
|
def test_sale_order_4(self): |
|
|
|
""" |
|
|
|
Scenario: |
|
|
|
* Sale Order Limit == 100 EUR |
|
|
|
* Credit Limit == 75 EUR |
|
|
|
* Risk sale order include |
|
|
|
* Invoice draft include |
|
|
|
* Sale order #1 @ 100 EUR |
|
|
|
* Manual invoice policy |
|
|
|
* Invoice percentace 0.75 |
|
|
|
* Sale order #2 @ 100 EUR |
|
|
|
* Confirm using bypass risk |
|
|
|
* Sale order #3 @ 100 EUR |
|
|
|
* Confirm using bypass risk |
|
|
|
|
|
|
|
Expected result: |
|
|
|
* Financial risk exceeded raised |
|
|
|
""" |
|
|
|
|
|
|
|
self.partner.write({ |
|
|
|
"risk_sale_order_limit": 150.0, |
|
|
|
"credit_limit": 100.0, |
|
|
|
"risk_sale_order_include": True, |
|
|
|
"risk_invoice_draft_include": True, |
|
|
|
}) |
|
|
|
self.sale_order.action_button_confirm() |
|
|
|
self.assertEqual( |
|
|
|
self.sale_order.state, |
|
|
|
"manual") |
|
|
|
sale_order2 = self.sale_order.copy() |
|
|
|
sale_order2.order_line[0].write({'price_unit': 10.0}) |
|
|
|
sale_order2.with_context(bypass_risk=True).action_button_confirm() |
|
|
|
self.assertTrue( |
|
|
|
self.sale_order.partner_id.risk_exception) |
|
|
|
sale_order3 = self.sale_order.copy() |
|
|
|
sale_order3.order_line[0].write({'price_unit': 10.0}) |
|
|
|
wiz_dic = sale_order3.with_context( |
|
|
|
bypass_risk=False).action_button_confirm() |
|
|
|
wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id']) |
|
|
|
self.assertEqual(wiz.exception_msg, |
|
|
|
"This sale order exceeds the financial risk.\n") |
|
|
|
self.assertTrue(self.partner.risk_allow_edit) |
|
|
|
wiz.button_continue() |
|
|
|
self.assertAlmostEqual(self.partner.risk_sale_order, 200.0) |
|
|
|
self.assertEqual( |
|
|
|
wiz.exception_msg, |
|
|
|
"Financial risk exceeded.\n") |