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.

169 lines
6.6 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
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. # Copyright - 2019 Therp BV <https://therp.nl>.
  9. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  10. # pylint: disable=invalid-name,missing-docstring,too-many-arguments
  11. # pylint: disable=protected-access,unused-argument,no-self-use
  12. from openerp.osv import orm, fields
  13. from openerp.tools.translate import _
  14. from openerp.osv.expression import is_leaf, AND
  15. class ResPartner(orm.Model):
  16. """Base class to support identification fields.
  17. The base class provides for the registration of categories of
  18. identification and a list of those id numbers related to a partner.
  19. Inheriting modules can have specific fields, to enable easy entry and
  20. search on those fields. An example of souch a field follows here:
  21. Example:
  22. .. code-block:: python
  23. _columns = {
  24. 'social_security': fields.function(
  25. lambda self, *args, **kwargs:
  26. self._compute_identification(*args, **kwargs),
  27. arg='SSN',
  28. fnct_inv=lambda self, *args, **kwargs:
  29. self._inverse_identification(*args, **kwargs),
  30. fnct_inv_arg='SSN',
  31. type='char',
  32. fnct_search=lambda self, *args, **kwargs:
  33. self._search_identification(*args, **kwargs),
  34. method=True, readonly=False,
  35. string='Social Security Number',
  36. ),
  37. }
  38. The field attributes arg and fnct_inv_arg must be set to a valid
  39. category code, to be provided by the module data of the module
  40. adding the field.
  41. """
  42. _inherit = 'res.partner'
  43. _columns = {
  44. 'id_numbers': fields.one2many(
  45. 'res.partner.id_number',
  46. 'partner_id',
  47. "Identification Numbers"
  48. ),
  49. }
  50. def _compute_identification(
  51. self, cr, uid, ids, field_name, category_code, context=None):
  52. """ Compute the field that indicate a certain ID type.
  53. Use this on a field that represents a certain ID type. It will compute
  54. the desired field as that ID(s).
  55. This ID can be worked with as if it were a Char field, but it will
  56. be relating back to a ``res.partner.id_number`` instead.
  57. Args:
  58. field_name (str): Name of field to set.
  59. category_code (str): Category code of the Identification type.
  60. """
  61. res = {}
  62. for record in self.browse(cr, uid, ids, context=context):
  63. res[record.id] = False
  64. if not record.id_numbers:
  65. continue
  66. for id_number in record.id_numbers:
  67. if id_number.category_id.code != category_code:
  68. continue
  69. res[record.id] = id_number.name
  70. return res
  71. def _inverse_identification(
  72. self, cr, uid, ids, field_name, field_value, category_code,
  73. context=None):
  74. """ Inverse for an identification field.
  75. This method will create a new record, or modify the existing one
  76. in order to allow for the associated field to work like a Char.
  77. If a category does not exist of the correct code, it will be created
  78. using `category_code` as both the `name` and `code` values.
  79. If the value of the target field is unset, the associated ID will
  80. be deactivated in order to preserve history.
  81. Args:
  82. field_name (str): Name of field to set.
  83. category_code (str): Category code of the Identification type.
  84. """
  85. # For the moment do nothing with empty value.
  86. if not field_name or not field_value:
  87. return
  88. # Check, and if needed autocreate, category:
  89. category_id = self._get_create_category(
  90. cr, uid, category_code, context=context)
  91. id_model = self.pool['res.partner.id_number']
  92. for record in self.browse(cr, uid, ids, context=context):
  93. # Search all records with the right category.
  94. id_number_ids = id_model.search(
  95. cr, uid, [
  96. ('partner_id', '=', record.id),
  97. ('category_id', '=', category_id)],
  98. context=context)
  99. if len(id_number_ids) > 1:
  100. # Guard against writing wrong records.
  101. raise orm.except_orm(
  102. _('Error'),
  103. _('This %s has multiple IDs of this type (%s), so a write'
  104. ' via the %s field is not possible.\n'
  105. 'In order to fix this, please use the IDs tab.') % (
  106. record._name, category_code, field_name))
  107. if len(id_number_ids) < 1:
  108. id_model.create(
  109. cr, uid, {
  110. 'partner_id': record.id,
  111. 'category_id': category_id,
  112. 'name': field_value},
  113. context=context)
  114. return
  115. # There was an identification record singleton found.
  116. id_model.write(
  117. cr, uid, id_number_ids, {'name': field_value}, context=context)
  118. def _search_identification(
  119. self, cr, uid, dummy_obj, field_name, args, context=None):
  120. """ Search method for an identification field.
  121. Args:
  122. category_code (str): Category code of the Identification type.
  123. operator (str): Operator of domain.
  124. value (str): Value to search for.
  125. Returns:
  126. list: Domain to search with.
  127. """
  128. category_code = self._columns[field_name]._arg
  129. category_id = self._get_create_category(
  130. cr, uid, category_code, context=context)
  131. result = [('id_numbers.category_id.id', '=', category_id)]
  132. for arg in args:
  133. if is_leaf(arg) and arg[0] == field_name:
  134. result = AND([result, [('id_numbers.name', arg[1], arg[2])]])
  135. return result
  136. def _get_create_category(self, cr, uid, category_code, context=None):
  137. """Get category for code, create if not exists."""
  138. category_model = self.pool['res.partner.id_category']
  139. category_ids = category_model.search(
  140. cr, uid, [('code', '=', category_code)], context=context)
  141. if category_ids:
  142. return category_ids[0]
  143. category = category_model.create(
  144. cr, uid, {
  145. 'code': category_code,
  146. 'name': category_code},
  147. context=context)
  148. return category.id