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.

94 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests.common import TransactionCase
  5. from odoo.exceptions import ValidationError
  6. class TestSaleOrder(TransactionCase):
  7. def setUp(self):
  8. super(TestSaleOrder, self).setUp()
  9. self.product1 = self.env.ref('product.product_product_1')
  10. self.product2 = self.env.ref('product.product_product_2')
  11. self.sale = self.env.ref('sale.sale_order_2')
  12. self.contract_template1 = self.env['account.analytic.contract'].create(
  13. {'name': 'Template 1'}
  14. )
  15. self.contract_template2 = self.env['account.analytic.contract'].create(
  16. {'name': 'Template 2'}
  17. )
  18. self.product1.write(
  19. {
  20. 'is_contract': True,
  21. 'contract_template_id': self.contract_template1.id,
  22. }
  23. )
  24. self.product2.write(
  25. {
  26. 'is_contract': True,
  27. 'contract_template_id': self.contract_template2.id,
  28. }
  29. )
  30. self.order_line1 = self.sale.order_line.filtered(
  31. lambda l: l.product_id == self.product1
  32. )
  33. def test_compute_is_contract(self):
  34. """Sale Order should have is_contract true if one of its lines is
  35. contract"""
  36. self.assertTrue(self.sale.is_contract)
  37. def test_action_confirm(self):
  38. """ It should create a contract for each contract template used in
  39. order_line """
  40. self.sale.action_confirm()
  41. contracts = self.sale.order_line.mapped('contract_id')
  42. self.assertEqual(len(contracts), 2)
  43. self.assertEqual(
  44. self.order_line1.contract_id.contract_template_id,
  45. self.contract_template1,
  46. )
  47. def test_sale_contract_count(self):
  48. """It should count contracts as many different contract template used
  49. in order_line"""
  50. self.sale.action_confirm()
  51. self.assertEqual(self.sale.contract_count, 2)
  52. def test_onchange_product(self):
  53. """ It should get recurrence invoicing info to the sale line from
  54. its product """
  55. self.assertEqual(
  56. self.order_line1.recurring_rule_type,
  57. self.product1.recurring_rule_type,
  58. )
  59. self.assertEqual(
  60. self.order_line1.recurring_interval,
  61. self.product1.recurring_interval,
  62. )
  63. self.assertEqual(
  64. self.order_line1.recurring_invoicing_type,
  65. self.product1.recurring_invoicing_type,
  66. )
  67. def test_check_contract_sale_partner(self):
  68. contract2 = self.env['account.analytic.account'].create(
  69. {
  70. 'name': 'Contract',
  71. 'contract_template_id': self.contract_template2.id,
  72. 'partner_id': self.sale.partner_id.id,
  73. }
  74. )
  75. with self.assertRaises(ValidationError):
  76. self.order_line1.contract_id = contract2
  77. def test_check_contract_sale_contract_template(self):
  78. contract1 = self.env['account.analytic.account'].create(
  79. {
  80. 'name': 'Contract',
  81. 'contract_template_id': self.contract_template1.id,
  82. }
  83. )
  84. with self.assertRaises(ValidationError):
  85. self.order_line1.contract_id = contract1