Hello, I updated party.py from the party module to include the Mexican's 
tax number RFC (VAT code equivalent). It requires python-stdnum v1.3.

*** /tmp/ediff27895fd    2016-07-11 09:17:23.966602026 -0500
--- /usr/lib/python2.7/dist-packages/trytond/modules/party/party.py    
2016-07-09 21:15:31.914255012 -0500
***************
*** 3,8 ****
--- 3,9 ----
  from itertools import groupby
  
  import stdnum.eu.vat as vat
+ import stdnum.mx.rfc as rfc
  import stdnum.exceptions
  from sql import Null
  from sql.functions import CharLength
***************
*** 126,132 ****
  
      @classmethod
      def _vat_types(cls):
!         return ['eu_vat']
  
      def get_vat_code(self, name):
          types = self._vat_types()
--- 127,133 ----
  
      @classmethod
      def _vat_types(cls):
!         return ['eu_vat', 'mx_rfc']
  
      def get_vat_code(self, name):
          types = self._vat_types()
***************
*** 266,271 ****
--- 267,274 ----
                  type = None
                  if vat.is_valid(code):
                      type = 'eu_vat'
+                 if rfc.is_valid(code):
+                     type = 'mx_rfc'
                  identifiers.append(
                      cls(party=party_id, code=code, type=type))
              cls.save(identifiers)
***************
*** 276,281 ****
--- 279,285 ----
      def get_types(cls):
          return [
              (None, ''),
+             ('mx_rfc', 'RFC'),
              ('eu_vat', 'VAT'),
              ]
  
***************
*** 286,301 ****
                  return vat.compact(self.code)
              except stdnum.exceptions.ValidationError:
                  pass
          return self.code
  
      def pre_validate(self):
          super(PartyIdentifier, self).pre_validate()
          self.check_code()
  
      def check_code(self):
          if self.type == 'eu_vat':
              if not vat.is_valid(self.code):
!                 if self.party.id > 0:
                      party = self.party.rec_name
                  else:
                      party = ''
--- 290,323 ----
                  return vat.compact(self.code)
              except stdnum.exceptions.ValidationError:
                  pass
+ 
+         if self.type == 'mx_rfc':
+             try:
+                 return rfc.compact(self.code)
+             except stdnum.exceptions.ValidationError:
+                 pass
          return self.code
  
      def pre_validate(self):
          super(PartyIdentifier, self).pre_validate()
          self.check_code()
  
+     @fields.depends('type', 'party', 'code')
      def check_code(self):
          if self.type == 'eu_vat':
              if not vat.is_valid(self.code):
!                 if self.party and self.party.id > 0:
!                     party = self.party.rec_name
!                 else:
!                     party = ''
!                 self.raise_user_error('invalid_vat', {
!                         'code': self.code,
!                         'party': party,
!                          })
! 
!         if self.type == 'mx_rfc':
!             if not rfc.is_valid(self.code):
!                 if self.party and self.party.id > 0:
                      party = self.party.rec_name
                  else:
                      party = ''
***************
*** 345,350 ****
--- 367,379 ----
          parties = Party.browse(Transaction().context.get('active_ids'))
          for party in parties:
              for identifier in party.identifiers:
+                 if identifier.type == 'mx_rfc':
+                     if not rfc.is_valid(identifier.code):
+                         parties_failed.append(party.id)
+                     else:
+                         parties_succeed.append(party.id)
+                     continue
+ 
                  if identifier.type != 'eu_vat':
                      continue
                  try:

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-contrib" group.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/tryton-contrib/76129784-09ec-4cf3-87ed-6bbcbcb313af%40googlegroups.com.

Reply via email to