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.

87 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # Copyright 2017 Pesol (<http://pesol.es>)
  4. # Copyright 2017 Angel Moya <angel.moya@pesol.es>
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  6. from odoo.exceptions import ValidationError
  7. from odoo.tests.common import TransactionCase
  8. class TestContractInvoice(TransactionCase):
  9. # Use case : Prepare some data for current test case
  10. def setUp(self):
  11. super(TestContractInvoice, self).setUp()
  12. self.partner = self.env.ref('base.res_partner_2')
  13. self.product = self.env.ref('product.product_product_2')
  14. self.product.taxes_id += self.env['account.tax'].search(
  15. [('type_tax_use', '=', 'sale')], limit=1)
  16. self.product.description_sale = 'Test description sale'
  17. self.template_vals = {
  18. 'recurring_rule_type': 'yearly',
  19. 'recurring_interval': 1,
  20. 'name': 'Test Contract Template',
  21. 'type': 'invoice'
  22. }
  23. self.template = self.env['account.analytic.contract'].create(
  24. self.template_vals,
  25. )
  26. self.contract = self.env['account.analytic.account'].create({
  27. 'name': 'Test Contract',
  28. 'partner_id': self.partner.id,
  29. 'pricelist_id': self.partner.property_product_pricelist.id,
  30. 'recurring_invoices': True,
  31. 'date_start': '2016-02-15',
  32. 'recurring_next_date': '2016-02-29',
  33. })
  34. self.contract.contract_template_id = self.template
  35. self.contract._onchange_contract_template_id()
  36. self.contract_line = self.env['account.analytic.invoice.line'].create({
  37. 'analytic_account_id': self.contract.id,
  38. 'product_id': self.product.id,
  39. 'name': 'Services from #START# to #END#',
  40. 'quantity': 1,
  41. 'uom_id': self.product.uom_id.id,
  42. 'price_unit': 100,
  43. 'discount': 50,
  44. })
  45. def test_check_discount(self):
  46. with self.assertRaises(ValidationError):
  47. self.contract_line.write({'discount': 120})
  48. def test_contract(self):
  49. self.assertAlmostEqual(self.contract_line.price_subtotal, 50.0)
  50. res = self.contract_line._onchange_product_id()
  51. self.assertIn('uom_id', res['domain'])
  52. self.contract_line.price_unit = 100.0
  53. self.contract.partner_id = False
  54. with self.assertRaises(ValidationError):
  55. self.contract.recurring_create_invoice()
  56. self.contract.partner_id = self.partner.id
  57. self.contract.recurring_create_invoice()
  58. self.invoice_monthly = self.env['account.invoice'].search(
  59. [('contract_id', '=', self.contract.id)])
  60. self.assertTrue(self.invoice_monthly)
  61. self.assertEqual(self.contract.recurring_next_date, '2017-02-28')
  62. self.inv_line = self.invoice_monthly.invoice_line_ids[0]
  63. self.assertTrue(self.inv_line.invoice_line_tax_ids)
  64. self.assertAlmostEqual(self.inv_line.price_subtotal, 50.0)
  65. self.assertEqual(self.contract.partner_id.user_id,
  66. self.invoice_monthly.user_id)
  67. def test_onchange_contract_template_id(self):
  68. """ It should change the contract values to match the template. """
  69. self.contract.contract_template_id = self.template
  70. self.contract._onchange_contract_template_id()
  71. res = {
  72. 'recurring_rule_type': self.contract.recurring_rule_type,
  73. 'recurring_interval': self.contract.recurring_interval,
  74. 'type': 'invoice'
  75. }
  76. del self.template_vals['name']
  77. self.assertDictEqual(res, self.template_vals)