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.

78 lines
3.3 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 import fields
  5. from openerp.exceptions import UserError
  6. from openerp.tests.common import TransactionCase
  7. class TestPartnerFinancialRisk(TransactionCase):
  8. def setUp(self):
  9. super(TestPartnerFinancialRisk, self).setUp()
  10. self.partner = self.env['res.partner'].create({
  11. 'name': 'Partner test',
  12. 'customer': True,
  13. })
  14. self.product = self.env.ref('product.product_product_2')
  15. self.product.invoice_policy = 'order'
  16. self.journal = self.env['account.journal'].create({
  17. 'type': 'sale',
  18. 'name': 'Test Sales',
  19. 'code': 'TSALE',
  20. })
  21. self.prod_account = self.env.ref('account.demo_coffee_machine_account')
  22. self.inv_account = self.env.ref('account.demo_sale_of_land_account')
  23. self.sale_order = self.env['sale.order'].create({
  24. 'partner_id': self.partner.id,
  25. 'pricelist_id': self.env.ref('product.list0').id,
  26. 'order_line': [(0, 0, {
  27. 'name': self.product.name,
  28. 'product_id': self.product.id,
  29. 'product_uom_qty': 1,
  30. 'product_uom': self.product.uom_id.id,
  31. 'price_unit': 100.0})],
  32. })
  33. self.invoice = self.env['account.invoice'].create({
  34. 'journal_id': self.journal.id,
  35. # 'account_id': self.inv_account.id,
  36. 'company_id': self.env.user.company_id.id,
  37. 'currency_id': self.env.user.company_id.currency_id.id,
  38. 'partner_id': self.partner.id,
  39. 'invoice_line_ids': [(0, 0, {
  40. 'account_id': self.prod_account.id,
  41. 'name': 'Test line',
  42. 'price_unit': 50,
  43. 'quantity': 10,
  44. })]
  45. })
  46. def test_sale_order(self):
  47. self.sale_order.action_confirm()
  48. self.assertAlmostEqual(self.partner.risk_sale_order, 100.0)
  49. invoice_so_id = self.sale_order.action_invoice_create()
  50. self.assertAlmostEqual(self.partner.risk_invoice_draft, 600.0)
  51. invoice_so = self.invoice.browse(invoice_so_id)
  52. invoice_so.date_due = fields.Date.today()
  53. invoice_so.signal_workflow('invoice_open')
  54. self.assertAlmostEqual(self.partner.risk_invoice_open, 100.0)
  55. self.partner.risk_invoice_open_include = True
  56. self.assertAlmostEqual(self.partner.risk_total, 100.0)
  57. self.assertTrue(self.partner.risk_exception)
  58. self.partner.credit_limit = 100.0
  59. self.assertFalse(self.partner.risk_exception)
  60. def test_invoices(self):
  61. self.partner.risk_invoice_draft_include = True
  62. self.assertAlmostEqual(self.partner.risk_invoice_draft, 500.0)
  63. self.assertAlmostEqual(self.partner.risk_total, 500.0)
  64. self.invoice.signal_workflow('invoice_open')
  65. self.assertAlmostEqual(self.partner.risk_invoice_draft, 0.0)
  66. self.assertFalse(self.invoice.date_due)
  67. self.partner.risk_invoice_unpaid_include = True
  68. self.assertAlmostEqual(self.partner.risk_total, 500.0)
  69. self.partner.risk_total = 100.0
  70. with self.assertRaises(UserError):
  71. self.sale_order.action_confirm()