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. # Copyright 2019 Creu Blanca
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests import common
  4. from odoo.tests.common import TransactionCase
  5. from odoo.exceptions import UserError
  6. @common.at_install(False)
  7. @common.post_install(True)
  8. class TestDocumentQuickAccess(TransactionCase):
  9. def setUp(self):
  10. super().setUp()
  11. self.model = 'res.partner'
  12. self.model_id = self.env.ref('base.model_res_partner')
  13. self.rule = self.env['document.quick.access.rule'].create({
  14. 'model_id': self.model_id.id,
  15. 'name': 'PARTNER',
  16. 'priority': 1,
  17. 'barcode_format': 'standard',
  18. })
  19. self.partner = self.env['res.partner'].create({
  20. 'name': 'Partner test',
  21. })
  22. def test_generation(self):
  23. code = self.partner.get_quick_access_code()
  24. self.assertTrue(code)
  25. partner = self.env['document.quick.access.rule'].read_code(code)
  26. self.assertEqual(partner, self.partner)
  27. action = self.env['document.quick.access.rule'].read_code_action(code)
  28. self.assertEqual(action['res_model'], partner._name)
  29. self.assertEqual(action['res_id'], partner.id)
  30. def test_not_found(self):
  31. code = self.partner.get_quick_access_code()
  32. self.assertTrue(code)
  33. self.rule.toggle_active()
  34. with self.assertRaises(UserError):
  35. self.env['document.quick.access.rule'].read_code(code)
  36. action = self.env['document.quick.access.rule'].read_code_action(code)
  37. self.assertEqual(action['res_model'], 'barcode.action')
  38. def test_no_code(self):
  39. self.rule.toggle_active()
  40. self.assertFalse(self.partner.get_quick_access_code())
  41. def test_generation_b64(self):
  42. self.rule.barcode_format = 'b64_standard'
  43. self.test_generation()
  44. def test_not_found_b64(self):
  45. self.rule.barcode_format = 'b64_standard'
  46. self.test_not_found()