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.

71 lines
3.1 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 odoo.tests.common import SavepointCase
  5. class TestPartnerSaleRisk(SavepointCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestPartnerSaleRisk, cls).setUpClass()
  9. cls.env.user.groups_id |= cls.env.ref('account.group_account_manager')
  10. cls.partner = cls.env['res.partner'].create({
  11. 'name': 'Partner test',
  12. 'customer': True,
  13. })
  14. cls.product = cls.env.ref('product.product_product_2')
  15. cls.product.invoice_policy = 'order'
  16. cls.sale_order = cls.env['sale.order'].create({
  17. 'partner_id': cls.partner.id,
  18. 'pricelist_id': cls.env.ref('product.list0').id,
  19. 'order_line': [(0, 0, {
  20. 'name': cls.product.name,
  21. 'product_id': cls.product.id,
  22. 'product_uom_qty': 1,
  23. 'product_uom': cls.product.uom_id.id,
  24. 'price_unit': 100.0})],
  25. })
  26. cls.env.user.lang = 'en_US'
  27. def test_sale_order(self):
  28. self.sale_order.action_confirm()
  29. self.assertAlmostEqual(self.partner.risk_sale_order, 100.0)
  30. self.assertFalse(self.partner.risk_exception)
  31. self.partner.risk_sale_order_limit = 99.0
  32. self.assertTrue(self.partner.risk_exception)
  33. sale_order2 = self.sale_order.copy()
  34. wiz_dic = sale_order2.action_confirm()
  35. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  36. self.assertEqual(wiz.exception_msg, "Financial risk exceeded.\n")
  37. self.partner.risk_sale_order_limit = 150.0
  38. wiz_dic = sale_order2.action_confirm()
  39. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  40. self.assertEqual(wiz.exception_msg,
  41. "This sale order exceeds the sales orders risk.\n")
  42. self.partner.risk_sale_order_limit = 0.0
  43. self.partner.risk_sale_order_include = True
  44. self.partner.credit_limit = 100.0
  45. wiz_dic = sale_order2.action_confirm()
  46. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  47. self.assertEqual(wiz.exception_msg,
  48. "This sale order exceeds the financial risk.\n")
  49. self.assertTrue(self.partner.risk_allow_edit)
  50. wiz.button_continue()
  51. self.assertAlmostEqual(self.partner.risk_sale_order, 200.0)
  52. def test_invoice_amount(self):
  53. self.sale_order.action_confirm()
  54. self.assertAlmostEqual(self.sale_order.invoice_pending_amount, 100.0)
  55. self.assertAlmostEqual(self.sale_order.invoice_amount, 0.0)
  56. wizard = self.env['sale.advance.payment.inv'].with_context({
  57. 'active_id': self.sale_order.id,
  58. 'active_ids': [self.sale_order.id],
  59. 'active_model': 'sale.order',
  60. }).create({
  61. 'advance_payment_method': 'percentage',
  62. 'amount': 80,
  63. })
  64. wizard.create_invoices()
  65. self.assertAlmostEqual(self.sale_order.invoice_pending_amount, 20.0)
  66. self.assertAlmostEqual(self.sale_order.invoice_amount, 80.0)