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.

73 lines
2.7 KiB

FIX pylint (cherry picked from commit eadcae217103fd8f2f8d3db87c6fb659e048812b) Conflicts: partner_identification/__openerp__.py Set version to 8.0.1.0.0. Remove dependency on sales_team, as the relevant change is not in 8.0. Change emails to the new ones (cherry picked from commit 3455ae614e28d7807fc19d7be54512cbe59d44ec) Update new name (cherry picked from commit 5b592d7562fddac0cf48c71e6607cf17c009e993) [FIX] try me on runbot link (cherry picked from commit bd587b6058a17814cee5496a0ed3c126600f6fd6) Conflicts: partner_identification/README.rst Changed runbot to 8.0 [IMP] partner_identification: Add context override (#373) Allow for context override of validations using ``id_no_validate`` (cherry picked from commit 76c2e7b784916cdca0753a46a7b2be75edc1d70d) [10.0][IMP] partner_identification: Add field computation and inverses (#419) * [IMP] partner_identification: Add field computation and inverses * Add methods to allow for computation and inverse of an ID field of a specific category type * [IMP] partner_identification: Add search option (cherry picked from commit 19c5fb6de2a710dd50248fd843465f454de887bf) [FIX] partner_identification: Infinite loop in search (#436) (cherry picked from commit fa9b390dc62f66ef33acd7aacdfb3b79912ebc28) [FIX] partner-contact CI interactions (cherry picked from commit bc93e7bbc3e0f059b228970f0a05e57f0efba310) [ADD][8.0] Backport of the 9.0 module. (cherry picked from commit a42540381d448c3a62fabf69043ed23bf1aeca3e) [8.0][MIG] partner_identification backport
8 years ago
  1. # -*- coding: utf-8 -*-
  2. #
  3. # © 2004-2010 Tiny SPRL http://tiny.be
  4. # © 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
  5. # http://www.camptocamp.at
  6. # © 2015 Antiun Ingenieria, SL (Madrid, Spain)
  7. # http://www.antiun.com
  8. # Antonio Espinosa <antonioea@antiun.com>
  9. # © 2016 ACSONE SA/NV (<http://acsone.eu>)
  10. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  11. from openerp import api, models, fields
  12. from openerp.exceptions import ValidationError, Warning as UserError
  13. from openerp.tools.safe_eval import safe_eval
  14. from openerp.tools.translate import _
  15. class ResPartnerIdCategory(models.Model):
  16. _name = "res.partner.id_category"
  17. _order = "name"
  18. def _default_validation_code(self):
  19. return _("\n# Python code. Use failed = True to specify that the id "
  20. "number is not valid.\n"
  21. "# You can use the following variables :\n"
  22. "# - self: browse_record of the current ID Category "
  23. "browse_record\n"
  24. "# - id_number: browse_record of ID number to validate")
  25. code = fields.Char(
  26. string="Code", size=16, required=True,
  27. help="Abbreviation or acronym of this ID type. For example, "
  28. "'driver_license'")
  29. name = fields.Char(
  30. string="ID name", required=True, translate=True,
  31. help="Name of this ID type. For example, 'Driver License'")
  32. active = fields.Boolean(string="Active", default=True)
  33. validation_code = fields.Text(
  34. 'Python validation code',
  35. help="Python code called to validate an id number.",
  36. default=_default_validation_code)
  37. @api.multi
  38. def _validation_eval_context(self, id_number):
  39. self.ensure_one()
  40. return {'self': self,
  41. 'id_number': id_number,
  42. }
  43. @api.multi
  44. def validate_id_number(self, id_number):
  45. """Validate the given ID number
  46. The method raises an openerp.exceptions.ValidationError if the eval of
  47. python validation code fails
  48. """
  49. self.ensure_one()
  50. if self.env.context.get('id_no_validate'):
  51. return
  52. eval_context = self._validation_eval_context(id_number)
  53. try:
  54. safe_eval(self.validation_code,
  55. eval_context,
  56. mode='exec',
  57. nocopy=True)
  58. except Exception as e:
  59. raise UserError(
  60. _('Error when evaluating the id_category validation code:'
  61. ':\n %s \n(%s)') % (self.name, e))
  62. if eval_context.get('failed', False):
  63. raise ValidationError(
  64. _("%s is not a valid %s identifier") % (
  65. id_number.name, self.name))