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.

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