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.

79 lines
3.6 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. from openerp import fields
  6. class TestPartnerFinancialRisk(TransactionCase):
  7. def setUp(self):
  8. super(TestPartnerFinancialRisk, self).setUp()
  9. self.env.user.groups_id |= self.env.ref('base.group_sale_manager')
  10. self.partner = self.env['res.partner'].create({
  11. 'name': 'Partner test',
  12. 'customer': True,
  13. })
  14. self.journal = self.env['account.journal'].create({
  15. 'type': 'sale',
  16. 'name': 'Test Sales',
  17. 'code': 'TSALE',
  18. })
  19. self.prod_account = self.env.ref('account.demo_coffee_machine_account')
  20. self.inv_account = self.env.ref('account.demo_sale_of_land_account')
  21. self.invoice = self.env['account.invoice'].create({
  22. 'journal_id': self.journal.id,
  23. 'company_id': self.env.user.company_id.id,
  24. 'currency_id': self.env.user.company_id.currency_id.id,
  25. 'partner_id': self.partner.id,
  26. 'invoice_line_ids': [(0, 0, {
  27. 'account_id': self.prod_account.id,
  28. 'name': 'Test line',
  29. 'price_unit': 50,
  30. 'quantity': 10,
  31. })]
  32. })
  33. def test_invoices(self):
  34. self.partner.risk_invoice_draft_include = True
  35. self.assertAlmostEqual(self.partner.risk_invoice_draft, 500.0)
  36. self.assertAlmostEqual(self.partner.risk_total, 500.0)
  37. self.invoice.signal_workflow('invoice_open')
  38. self.assertAlmostEqual(self.partner.risk_invoice_draft, 0.0)
  39. self.assertFalse(self.invoice.date_due)
  40. self.partner.risk_invoice_unpaid_include = True
  41. self.assertAlmostEqual(self.partner.risk_total, 500.0)
  42. self.partner.credit_limit = 100.0
  43. self.assertTrue(self.partner.risk_exception)
  44. self.partner.credit_limit = 1000.0
  45. self.assertFalse(self.partner.risk_exception)
  46. self.partner.risk_invoice_unpaid_limit = 499.0
  47. self.assertTrue(self.partner.risk_exception)
  48. invoice2 = self.invoice.copy()
  49. wiz_dic = invoice2.invoice_open()
  50. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  51. self.assertEqual(wiz.exception_msg, "Financial risk exceeded.\n")
  52. self.partner.risk_invoice_unpaid_limit = 0.0
  53. self.assertFalse(self.partner.risk_exception)
  54. self.partner.risk_invoice_open_limit = 300.0
  55. invoice2.date_due = fields.Date.today()
  56. wiz_dic = invoice2.invoice_open()
  57. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  58. self.assertEqual(wiz.exception_msg,
  59. "This invoice exceeds the open invoices risk.\n")
  60. self.partner.risk_invoice_open_limit = 0.0
  61. self.partner.risk_invoice_draft_include = False
  62. self.partner.risk_invoice_open_include = True
  63. self.partner.credit_limit = 900.0
  64. wiz_dic = invoice2.invoice_open()
  65. wiz = self.env[wiz_dic['res_model']].browse(wiz_dic['res_id'])
  66. self.assertEqual(wiz.exception_msg,
  67. "This invoice exceeds the financial risk.\n")
  68. self.assertAlmostEqual(self.partner.risk_invoice_open, 0.0)
  69. wiz.button_continue()
  70. self.assertAlmostEqual(self.partner.risk_invoice_open, 500.0)
  71. self.assertTrue(self.partner.risk_allow_edit)
  72. self.partner.process_unpaid_invoices()
  73. self.assertEqual(self.env['ir.config_parameter'].get_param(
  74. 'partner_financial_risk.last_check'),
  75. fields.Date.today())