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.

48 lines
1.9 KiB

  1. # Copyright 2020 Creu Blanca
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  3. from odoo.tests.common import TransactionCase, Form
  4. from odoo.exceptions import ValidationError
  5. class PartnerCase(TransactionCase):
  6. def setUp(self, *args, **kwargs):
  7. super(PartnerCase, self).setUp(*args, **kwargs)
  8. self.agrolait = self.env.ref("base.res_partner_2")
  9. self.template = self.env['custom.info.template'].create({
  10. 'name': 'TEST Template',
  11. 'model_id': self.env.ref('base.model_res_partner').id,
  12. 'property_ids': [(0, 0, {
  13. 'name': 'Property',
  14. 'widget': 'char',
  15. 'required': True,
  16. })]
  17. })
  18. def test_required_form_failure(self):
  19. with Form(self.agrolait) as f:
  20. self.assertFalse(f.custom_info_template_id)
  21. self.assertFalse(f.custom_info_ids)
  22. f.custom_info_template_id = self.template
  23. self.assertTrue(f.custom_info_ids)
  24. with self.assertRaises(AssertionError):
  25. f.save()
  26. f.custom_info_template_id = self.env['custom.info.template']
  27. self.assertFalse(f.custom_info_ids)
  28. def test_required_failure(self):
  29. self.assertFalse(self.agrolait.custom_info_template_id)
  30. self.assertFalse(self.agrolait.custom_info_ids)
  31. self.agrolait.custom_info_template_id = self.template
  32. with self.assertRaises(ValidationError):
  33. self.agrolait._onchange_custom_info_template_id()
  34. def test_required(self):
  35. with Form(self.agrolait) as f:
  36. self.assertFalse(f.custom_info_template_id)
  37. self.assertFalse(f.custom_info_ids)
  38. f.custom_info_template_id = self.template
  39. self.assertEqual(1, len(f.custom_info_ids))
  40. with f.custom_info_ids.edit(0) as info:
  41. info.value_str = 'HELLO'
  42. self.assertTrue(self.agrolait.custom_info_ids.value)