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.

54 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Grupo ESOC Ingeniería de servicios, S.L. - Jairo Llopis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.addons.base_vat.base_vat import _ref_vat
  6. from openerp import exceptions as ex
  7. class CommonCase(TransactionCase):
  8. """Test common cases, independent to the country of the VAT code."""
  9. def setUp(self):
  10. super(CommonCase, self).setUp()
  11. self.partner = self.env["res.partner"].create({
  12. "name": __file__,
  13. "is_company": False,
  14. })
  15. def test_empty(self):
  16. """Remove a VAT from a contact."""
  17. # First, set a good VAT to have no errors
  18. self.partner.contact_vat = "ES00000001R"
  19. # Then remove it
  20. self.partner.contact_vat = False
  21. # Nothing special should happen
  22. self.assertEqual(self.partner.contact_vat, False)
  23. def test_company_to_partner(self):
  24. """Set a wrong contact VAT to a company and convert it to person."""
  25. self.partner.is_company = True
  26. # Set a wrong contact_vat, but no errors because it is a company
  27. self.partner.contact_vat = "ES00000001W"
  28. # Now say it's a person
  29. with self.assertRaises(ex.ValidationError):
  30. self.partner.is_company = False
  31. def test_vat_without_country_code(self):
  32. """Set a VAT without the country code prefix."""
  33. with self.assertRaises(ex.ValidationError):
  34. self.partner.contact_vat = "00000001R"
  35. def test_wrong_format_hint(self):
  36. """Ensure the format hint is given to user."""
  37. try:
  38. # Set a wrong VAT
  39. self.partner.with_context(lang="en_US").contact_vat = "ES00000001W"
  40. except ex.ValidationError as error:
  41. self.assertIn(_ref_vat.get("es"), error.value)
  42. self.assertEqual(error.value, error.args[1])