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.

149 lines
5.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # -*- encoding: utf-8 -*-
  2. # #############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) Odoo Colombia (Community).
  6. # Author David Arnold (devCO)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields, api # , _
  23. class ResPartner(models.Model):
  24. _inherit = 'res.partner'
  25. dom = "[ '|', " \
  26. " ('on_company', '=', is_company), " \
  27. " ('on_contact', '!=', is_company) ]"
  28. fiscal_id_type = fields.Many2one(
  29. 'res.partner.idtype',
  30. string=u'Document Type',
  31. domain=dom,
  32. compute='validateformatcopy',
  33. )
  34. fiscal_id = fields.Char(string=u'Document ID')
  35. fiscal_id_doc = fields.Binary(
  36. string=u'Document Scan',
  37. help="Upload the supporting Document "
  38. "preferably as size-optimized PDF. "
  39. "This might "
  40. "help save disk space and PDF allows "
  41. "you to concatenate multiple documents."
  42. )
  43. @api.one
  44. @api.depends(
  45. 'fiscal_id_type',
  46. 'fiscal_id',
  47. 'is_company',
  48. )
  49. def validateformatcopy(self):
  50. # CASE: Current ID Type is not applicable on company
  51. if self.is_company and not self.fiscal_id_type.on_company:
  52. # Get the first valid ID type (remember: ordered by sequence)
  53. self.fiscal_id_type = self.env['res.partner.idtype'].search(
  54. [('on_company', '=', True)], limit=1).id
  55. self.fiscal_id = None # Reset ID value
  56. # CASE: Current ID Type is not applicable on contact
  57. if not self.is_company and not self.fiscal_id_type.on_contact:
  58. # Get the first valid ID type (remember: ordered by sequence)
  59. self.fiscal_id_type = self.env['res.partner.idtype'].search(
  60. [('on_contact', '=', True)], limit=1).id
  61. self.fiscal_id = None # Reset ID value
  62. # If everything is fine, call subclasses
  63. if self.fiscal_id_type and self.fiscal_id:
  64. # Function for String Operations
  65. res = self._validateandformatid(self)
  66. if res['output_type'] and res['output_id']:
  67. self.fiscal_id_type, self.fiscal_id = res['output_type'], res[
  68. 'output_id']
  69. # Procedure for Copying
  70. _copyid(self)
  71. def _validateandformatid(self):
  72. """
  73. Hook method to be inherited for custom validation methods.
  74. :param input_type: the value of the field fiscal_id_type (id); passed
  75. on by onchange decorator
  76. :param input_id: the value of the field fiscal_id (string); passed on
  77. by onchange decorator
  78. :return: must return a dict with validated and formatted values
  79. Hint:
  80. you might not alter the output_type unless you might want to build
  81. some kind of fiscal_id_type recognition
  82. based on the input pattern into your hook method. CO###.###.###-#
  83. CO-VAT (NIT) for example.
  84. Find below a suggested basic outline.
  85. """
  86. """
  87. f_type = self.fiscal_id_type
  88. f_id = self.fiscal_id
  89. is_company = self.is_company
  90. def default():
  91. return {'output_type': f_type, 'output_id': f_id}
  92. return {
  93. # Define your cases
  94. # The index to match is self.fiscal_id_type.code
  95. # Note: You can change this index below.
  96. # Example assignation using two functions
  97. # {'output_type': func_type1(), 'output_id': funct_id1()}
  98. 'CODE1': { "put your assignation here" },
  99. 'CODE2': { "put your assignation here" },
  100. }.get(self.fiscal_id_type.code, default())
  101. """
  102. def _copyid(self):
  103. """
  104. Hook Method to be inherited for custom copy methods based on the
  105. document type (id)
  106. Example Use Case: Copy some local VAT number into the VAT-Field in
  107. it's international format for compatibility.
  108. :return: It is a Procedure and therefore has no return value.
  109. Find below a suggested basic outline.
  110. """
  111. """
  112. f_type = self.fiscal_id_type
  113. f_id = self.fiscal_id
  114. is_company = self.is_company
  115. def stringop_def(s): return s
  116. def stringop_1(s): return re.match('\\d|\\w*', s)
  117. # Define other Docstringoperatios if necessary
  118. def default():
  119. self.vat_subjected = True
  120. # self.vat is a Boolean until base_vat is installed.
  121. # self.vat = self.country_id.code + sringop_def(f_id)
  122. {
  123. # Some examples to consider...
  124. # seld.vat_subjected: True,
  125. # self.vat: self.country_id.code + stringop_1(f_id)
  126. 'CODE1': { "put your statments here" },
  127. 'CODE2': { "put your statments here" },
  128. }.get(self.fiscal_id_type.code, default())
  129. """