← Back to team overview

openerp-community team mailing list archive

[Merge] lp:~openerp-community/openobject-addons/meanmicio_base_vat6 into lp:openobject-addons

 

Luis Falcon has proposed merging lp:~openerp-community/openobject-addons/meanmicio_base_vat6 into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

-- 
https://code.launchpad.net/~openerp-community/openobject-addons/meanmicio_base_vat6/+merge/41852
Your team OpenERP Community is subscribed to branch lp:~openerp-community/openobject-addons/meanmicio_base_vat6.
=== modified file 'base_vat/base_vat.py'
--- base_vat/base_vat.py	2010-11-10 08:12:44 +0000
+++ base_vat/base_vat.py	2010-11-25 11:21:20 +0000
@@ -48,19 +48,39 @@
 class res_partner(osv.osv):
     _inherit = 'res.partner'
 
-    def _split_vat(self, vat):
-        vat_country, vat_number = vat[:2].lower(), vat[2:].replace(' ', '')
+    def _split_vat(self, vat_country_code, vat):
+        vat_country, vat_number = vat_country_code.lower(), vat.replace(' ', '')
         return vat_country, vat_number
 
     def check_vat(self, cr, uid, ids):
         '''
         Check the VAT number depending of the country.
         http://sima-pc.com/nif.php
-        '''
+        
+        => Developers: make sure to add the country ISO 3166 code in the current_country_codes variable for each new vat code verification function 
+        For more info about country ISO codes :
+        http://www.iso.org/iso/english_country_names_and_code_elements
+        
+        Note that UK is just an alias for GB. Once it gets fixed on the global country code lists it should be removed.
+         '''
+        
+        current_country_codes = ["AR","AT","BE","BG","CY","CZ","DE","DK","EE","EL","ES","FI","FR","GB","GR","HU","IE","IT","LT","LU","LV","MT","NL","PL","PT","RO","SE","SI","SK","UK"]
+        
         for partner in self.browse(cr, uid, ids):
             if not partner.vat:
                 continue
-            vat_country, vat_number = self._split_vat(partner.vat)
+
+            if not partner.vat_country:
+                continue
+
+            if not partner.verify_vat:
+                continue
+
+            if not partner.vat_country.code in current_country_codes:
+                continue
+                                
+            vat_country, vat_number = self._split_vat(partner.vat_country, partner.vat)
+            
             if not hasattr(self, 'check_vat_' + vat_country):
                 return False
             check = getattr(self, 'check_vat_' + vat_country)
@@ -72,7 +92,9 @@
         return {'value': {'vat_subjected': bool(value)}}
 
     _columns = {
-        'vat_subjected': fields.boolean('VAT Legal Statement', help="Check this box if the partner is subjected to the VAT. It will be used for the VAT legal statement.")
+        'vat_subjected': fields.boolean('VAT Legal Statement', help="Check this box if the partner is subjected to the VAT. It will be used for the VAT legal statement."),
+        'vat_country':fields.many2one('res.country','VAT Country',help="Country corresponding to this VAT number"),
+        'verify_vat': fields.boolean('Check VAT', help="Check this box if you want to check the validity of the VAT number. In that case, make sure you enter the Country Name of the partner and the correspondant VAT number"),
     }
 
     def _construct_constraint_msg(self, cr, uid, ids):
@@ -81,7 +103,8 @@
             #  it starts with 2 letters
             #  has more than 3 characters
             return cn[0] in string.ascii_lowercase and cn[1] in string.ascii_lowercase
-        vat_country, vat_number = self._split_vat(self.browse(cr, uid, ids)[0].vat)
+        partner_obj = self.browse(cr, uid, ids)[0]
+        vat_country, vat_number = self._split_vat(partner_obj.vat_country, partner_obj.vat)
         if default_vat_check(vat_country, vat_number):
             vat_no = vat_country in _ref_vat and _ref_vat[vat_country] or 'Country Code + Vat Number'
             return _('The Vat does not seems to be correct. You should have entered something like this %s'), (vat_no)
@@ -91,6 +114,43 @@
 
     # code from the following methods come from Tryton (B2CK)
     # http://www.tryton.org/hgwebdir.cgi/modules/relationship/file/544d1de586d9/party.py
+    
+    def check_vat_ar(self, vat):
+        '''
+        Check VAT (CUIT) for Argentina - Thymbra.
+        '''
+
+        cstr = str (vat)
+        salt=str (5432765432)
+        n=0
+        sum=0
+        
+        if not vat.isdigit:
+            return False
+        
+        if (len (vat) <> 11):
+            return  False
+
+        while (n < 10):
+            sum = sum + int (salt[n]) * int (cstr[n])
+            n=n+1
+
+        op1 = sum % 11
+        op2 = 11 - op1
+
+        codigo_verificador = op2
+
+        if ( op2 == 11 or op2 == 10):
+            if ( op2 == 11 ):
+                codigo_verificador = 0
+            else:
+                codigo_verificador = 9
+
+        if ( codigo_verificador == int (cstr[10]) ):
+            return True                
+        else:
+            return False
+
     def check_vat_at(self, vat):
         '''
         Check Austria VAT number.

=== modified file 'base_vat/base_vat_view.xml'
--- base_vat/base_vat_view.xml	2010-05-25 14:01:13 +0000
+++ base_vat/base_vat_view.xml	2010-11-25 11:21:20 +0000
@@ -8,9 +8,11 @@
       <field name="inherit_id" ref="account.view_partner_property_form"/>
       <field name="arch" type="xml">
         <field name="property_account_payable" position="after">
-            <group colspan="2" col="6">
-              <field name="vat" on_change="vat_change(vat)" colspan="4" />
-              <field name="vat_subjected" colspan="1"/>
+            <group colspan="2" col="4">
+				<field name="vat_country" select="2"/>
+            	<field name="vat" on_change="vat_change(vat)" colspan="4" />
+            	<field name="vat_subjected" colspan="1"/>
+				<field name="verify_vat"/>            	
             </group>
         </field>
       </field>


Follow ups