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.

44 lines
1.6 KiB

  1. # Copyright 2017 LasLabs Inc.
  2. # Copyright 2019 Rubén Bravo <rubenred18@gmail.com>
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from odoo.tests.common import TransactionCase
  5. from odoo.exceptions import ValidationError
  6. class TestResLang(TransactionCase):
  7. def setUp(self):
  8. super(TestResLang, self).setUp()
  9. self.lang = self.env.ref('base.lang_en')
  10. self.env.user.lang = self.lang.code
  11. self.uom = self.env.ref('uom.product_uom_dozen')
  12. self.lang.default_uom_ids = [(6, 0, self.uom.ids)]
  13. def test_check_default_uom_ids_fail(self):
  14. """It should not allow multiple UoMs of the same category."""
  15. with self.assertRaises(ValidationError):
  16. self.lang.default_uom_ids = [
  17. (4, self.env.ref('uom.product_uom_unit').id),
  18. ]
  19. def test_check_default_uom_ids_pass(self):
  20. """It should allow multiple UoMs of different categories."""
  21. self.lang.default_uom_ids = [
  22. (4, self.env.ref('uom.product_uom_kgm').id),
  23. ]
  24. self.assertEqual(len(self.lang.default_uom_ids), 2)
  25. def test_default_uom_by_category_exist(self):
  26. """It should return the default UoM if existing."""
  27. self.assertEqual(
  28. self.env['res.lang'].default_uom_by_category('Unit'),
  29. self.uom,
  30. )
  31. def test_default_uom_by_category_no_exist(self):
  32. """It should return empty recordset when no default UoM."""
  33. self.assertEqual(
  34. self.env['res.lang'].default_uom_by_category('Volume'),
  35. self.env['uom.uom'].browse(),
  36. )