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.

75 lines
2.3 KiB

  1. # Copyright 2019 Camptocamp SA
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests import common
  4. class TestAgreementPropagation(common.SavepointCase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super().setUpClass()
  8. cls.agreement_type = cls.env['agreement.type'].create(
  9. {'code': 'TST', 'name': 'test'}
  10. )
  11. cls.agreement = cls.env['agreement'].create(
  12. {'name': 'Test Agreement Template',
  13. 'code': 'TST',
  14. 'is_template': 1,
  15. 'agreement_type_id': cls.agreement_type.id,
  16. }
  17. )
  18. cls.product = cls.env['product.product'].create(
  19. {'name': 'test product',
  20. 'type': 'consu',
  21. 'uom_id': 1,
  22. }
  23. )
  24. cls.partner = cls.env['res.partner'].create(
  25. {
  26. 'name': 'Test Customer',
  27. 'customer': True,
  28. }
  29. )
  30. cls.sale = cls.env['sale.order'].create(
  31. {
  32. 'partner_id': cls.partner.id,
  33. 'agreement_type_id': cls.agreement_type.id,
  34. 'order_line': [
  35. (0, 0, {
  36. 'product_id': cls.product.id,
  37. 'product_uom': cls.product.uom_id.id,
  38. 'product_uom_qty': 1,
  39. 'price_unit': 10,
  40. }
  41. )
  42. ],
  43. }
  44. )
  45. def test_default_agreement(self):
  46. self.assertEqual(self.agreement_type.default_agreement_id,
  47. self.agreement)
  48. def test_sale_order_confirm(self):
  49. sale = self.sale
  50. sale.onchange_agreement_type()
  51. self.assertEqual(
  52. sale.agreement_id.agreement_type_id,
  53. sale.agreement_type_id
  54. )
  55. self.assertNotEqual(
  56. sale.agreement_id,
  57. sale.agreement_type_id.default_agreement_id
  58. )
  59. self.assertEqual(
  60. sale.agreement_id.partner_id,
  61. sale.partner_id
  62. )
  63. self.assertTrue(sale.agreement_id.is_sale_agreement)
  64. def test_agreement_propagation_to_procurement_group(self):
  65. sale = self.sale
  66. sale.action_confirm()
  67. self.assertEqual(
  68. sale.agreement_id,
  69. sale.procurement_group_id.agreement_id
  70. )