You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. class TestPartnerSaleRisk(TransactionCase):
  6. def setUp(self):
  7. super(TestPartnerSaleRisk, self).setUp()
  8. self.env.user.groups_id |= self.env.ref('base.group_sale_manager')
  9. self.partner = self.env['res.partner'].create({
  10. 'name': 'Partner test',
  11. 'customer': True,
  12. })
  13. self.product = self.env.ref('product.product_product_2')
  14. self.product.invoice_policy = 'order'
  15. self.sale_order = self.env['sale.order'].create({
  16. 'partner_id': self.partner.id,
  17. 'pricelist_id': self.env.ref('product.list0').id,
  18. 'order_line': [(0, 0, {
  19. 'name': self.product.name,
  20. 'product_id': self.product.id,
  21. 'product_uom_qty': 1,
  22. 'product_uom': self.product.uom_id.id,
  23. 'price_unit': 100.0})],
  24. })
  25. self.wizard = self.env[
  26. "sale.advance.payment.inv"]
  27. def test_sale_order_1(self):
  28. """
  29. Scenario:
  30. * 1 sale order @ 100 EUR
  31. * Manual invoice policy
  32. * Invoice all
  33. * Risk sale order not include
  34. * No invoice risk
  35. Expected result:
  36. * Sale order can be confirm
  37. * Invoice can be validate
  38. """
  39. self.sale_order.action_button_confirm()
  40. self.assertEqual(
  41. self.sale_order.state,
  42. "manual")
  43. wizard = self.wizard.with_context({
  44. "active_ids": [self.sale_order.id]}).\
  45. create({
  46. "advance_payment_method": "all"})
  47. wizard.create_invoices()
  48. self.sale_order.invoice_ids.signal_workflow("invoice_open")
  49. def test_sale_order_2(self):
  50. """
  51. Scenario:
  52. * 1 sale order @ 100 EUR
  53. * Manual invoice policy
  54. * Invoice all
  55. * Sale Order Limit == 75 EUR
  56. * Risk sale order not include
  57. * No invoice risk
  58. Expected result:
  59. * Sale order exceeds the sale order risk raised
  60. """
  61. self.partner.write({
  62. "risk_sale_order_limit": 75.0,
  63. "credit_limit": 150.0,
  64. })
  65. wiz_dic = self.sale_order.action_button_confirm()
  66. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  67. self.assertEqual(
  68. wiz.exception_msg,
  69. "This sale order exceeds the sales orders risk.\n")
  70. def test_sale_order_3(self):
  71. """
  72. Scenario:
  73. * 1 sale order @ 100 EUR
  74. * Manual invoice policy
  75. * Invoice all
  76. * Sale Order Limit == 100 EUR
  77. * Credit Limit == 75 EUR
  78. * Risk sale order include
  79. * No invoice risk
  80. Expected result:
  81. * Sale order exceeds the financial risk raised
  82. """
  83. self.partner.write({
  84. "risk_sale_order_limit": 115.0,
  85. "credit_limit": 75.0,
  86. "risk_sale_order_include": True,
  87. })
  88. wiz_dic = self.sale_order.action_button_confirm()
  89. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  90. self.assertEqual(
  91. wiz.exception_msg,
  92. "This sale order exceeds the financial risk.\n")
  93. def test_sale_order_4(self):
  94. """
  95. Scenario:
  96. * Sale Order Limit == 100 EUR
  97. * Credit Limit == 75 EUR
  98. * Risk sale order include
  99. * Invoice draft include
  100. * Sale order #1 @ 100 EUR
  101. * Manual invoice policy
  102. * Invoice percentace 0.75
  103. * Sale order #2 @ 100 EUR
  104. * Confirm using bypass risk
  105. * Sale order #3 @ 100 EUR
  106. * Confirm using bypass risk
  107. Expected result:
  108. * Financial risk exceeded raised
  109. """
  110. self.partner.write({
  111. "risk_sale_order_limit": 150.0,
  112. "credit_limit": 100.0,
  113. "risk_sale_order_include": True,
  114. "risk_invoice_draft_include": True,
  115. })
  116. self.sale_order.action_button_confirm()
  117. self.assertEqual(
  118. self.sale_order.state,
  119. "manual")
  120. sale_order2 = self.sale_order.copy()
  121. sale_order2.order_line[0].write({'price_unit': 10.0})
  122. sale_order2.with_context(bypass_risk=True).action_button_confirm()
  123. self.assertTrue(
  124. self.sale_order.partner_id.risk_exception)
  125. sale_order3 = self.sale_order.copy()
  126. sale_order3.order_line[0].write({'price_unit': 10.0})
  127. wiz_dic = sale_order3.with_context(
  128. bypass_risk=False).action_button_confirm()
  129. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  130. self.assertEqual(
  131. wiz.exception_msg,
  132. "Financial risk exceeded.\n")