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.

156 lines
5.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
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
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
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. # Copyright - 2004-2010 Tiny SPRL http://tiny.be
  3. # Copyright - 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
  4. # http://www.camptocamp.at
  5. # Copyright - Antiun Ingenieria, SL (Madrid, Spain)
  6. # http://www.antiun.com
  7. # Antonio Espinosa <antonioea@antiun.com>
  8. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  9. # pylint: disable=invalid-name,missing-docstring,too-many-arguments
  10. # pylint: disable=protectec-access,unused-argument
  11. from openerp.osv import orm, fields
  12. from openerp.exceptions import ValidationError
  13. from openerp.tools.translate import _
  14. class ResPartner(orm.Model):
  15. """Base class to support identification fields.
  16. The base class provides for the registration of categories of
  17. identification and a list of those id numbers related to a partner.
  18. Inheriting modules can dd specific fields, to enable easy entry and search
  19. on those fields. An example of souch a field follows here:
  20. Example:
  21. .. code-block:: python
  22. _columns = {
  23. 'social_security': fields.function(
  24. _compute_identification,
  25. arg='SSN',
  26. fcnt_inv=_inverse_identification,
  27. fcnt_inv_arg='SSN',
  28. type='char',
  29. fcnt_search=_search_identification,
  30. method= True, store=True,
  31. ),
  32. }
  33. The field attributes arg and fnct_inv_arg must be set to a valid
  34. category code, to be provided by the module data of the module
  35. adding the field.
  36. """
  37. _inherit = 'res.partner'
  38. _columns = {
  39. 'id_numbers': fields.one2many(
  40. 'res.partner.id_number',
  41. 'partner_id',
  42. "Identification Numbers"
  43. ),
  44. }
  45. def _compute_identification(
  46. self, cr, uid, ids, field_name, category_code, context=None):
  47. """ Compute the field that indicate a certain ID type.
  48. Use this on a field that represents a certain ID type. It will compute
  49. the desired field as that ID(s).
  50. This ID can be worked with as if it were a Char field, but it will
  51. be relating back to a ``res.partner.id_number`` instead.
  52. Args:
  53. field_name (str): Name of field to set.
  54. category_code (str): Category code of the Identification type.
  55. """
  56. res = {}
  57. for record in self.browse(cr, uid, ids, context=context):
  58. res[record.id] = False
  59. if not record.id_numbers:
  60. continue
  61. id_numbers = record.id_numbers.filtered(
  62. lambda r: r.category_id.code == category_code
  63. )
  64. if not id_numbers:
  65. continue
  66. value = id_numbers[0].name
  67. record[field_name] = value
  68. def _inverse_identification(self, field_name, category_code):
  69. """ Inverse for an identification field.
  70. This method will create a new record, or modify the existing one
  71. in order to allow for the associated field to work like a Char.
  72. If a category does not exist of the correct code, it will be created
  73. using `category_code` as both the `name` and `code` values.
  74. If the value of the target field is unset, the associated ID will
  75. be deactivated in order to preserve history.
  76. Args:
  77. field_name (str): Name of field to set.
  78. category_code (str): Category code of the Identification type.
  79. """
  80. for record in self:
  81. id_number = record.id_numbers.filtered(
  82. lambda r: r.category_id.code == category_code
  83. )
  84. record_len = len(id_number)
  85. # Record for category is not existent.
  86. if record_len == 0:
  87. name = record[field_name]
  88. if not name:
  89. # No value to set
  90. continue
  91. category = self.env['res.partner.id_category'].search([
  92. ('code', '=', category_code),
  93. ])
  94. if not category:
  95. category = self.env['res.partner.id_category'].create({
  96. 'code': category_code,
  97. 'name': category_code,
  98. })
  99. self.env['res.partner.id_number'].create({
  100. 'partner_id': record.id,
  101. 'category_id': category.id,
  102. 'name': name,
  103. })
  104. # There was an identification record singleton found.
  105. elif record_len == 1:
  106. value = record[field_name]
  107. if value:
  108. id_number.name = value
  109. else:
  110. id_number.active = False
  111. # Guard against writing wrong records.
  112. else:
  113. raise ValidationError(_(
  114. 'This %s has multiple IDs of this type (%s), so a write '
  115. 'via the %s field is not possible. In order to fix this, '
  116. 'please use the IDs tab.',
  117. ) % (
  118. record._name, category_code, field_name,
  119. ))
  120. def _search_identification(self, category_code, operator, value):
  121. """ Search method for an identification field.
  122. Args:
  123. category_code (str): Category code of the Identification type.
  124. operator (str): Operator of domain.
  125. value (str): Value to search for.
  126. Returns:
  127. list: Domain to search with.
  128. """
  129. id_numbers = self.env['res.partner.id_number'].search([
  130. ('name', operator, value),
  131. ('category_id.code', '=', category_code),
  132. ])
  133. return [
  134. ('id_numbers.id', 'in', id_numbers.ids),
  135. ]