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

Proposed by Luis Falcon - Thymbra
Status: Rejected
Rejected by: Fabien (Open ERP)
Proposed branch: lp:~openerp-community/openobject-addons/meanmicio_base_vat6
Merge into: lp:openobject-addons
Diff against target: 131 lines (+71/-9)
2 files modified
base_vat/base_vat.py (+66/-6)
base_vat/base_vat_view.xml (+5/-3)
To merge this branch: bzr merge lp:~openerp-community/openobject-addons/meanmicio_base_vat6
Reviewer Review Type Date Requested Status
qdp (OpenERP) Needs Information
Review via email: mp+41852@code.launchpad.net
To post a comment you must log in.
Revision history for this message
qdp (OpenERP) (qdp) wrote :

Hello Luis,

i checked this branch and i have a doubt on the utility of splitting the vat number in two parts: i don't see the added value of such a thing. Also i'm not sure we want the avoid verification feature in core module. For this, maybe an extra module would do the trick.

For the argentinian vat validation algorithm, i'd be glad to add it but could you please provide an example of a valid argentinian vat number in the _ref_vat dictionary? This could be usefull for tests but it is also used to display an accurate message when the encoded vat number is not correct.

review: Needs Information
Revision history for this message
qdp (OpenERP) (qdp) wrote :

i changed the status back to "work in progress" for the sake of clarity in LP.

Thanks for your contribution,
Quentin

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

Hello,

I changed the status to Rejected. You can do a new merge proposal once it's updated.

Unmerged revisions

3958. By lfm <lfm@beastie>

Add the following functionality
- Add Argentinian VAT number verification algorithm
- The VAT is calculated depending on the country.
- No need to insert the two letter code in the VAT number, since it's
not part of it anyways. Now the function will be calculated from the
country code taken from the VAT country name
- Added a verification flag, so you can avoid the verification if you want.
- Change the name of the file "base_vat_data.xml" to "base_vat_view.xml"

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_vat/base_vat.py'
2--- base_vat/base_vat.py 2010-11-10 08:12:44 +0000
3+++ base_vat/base_vat.py 2010-11-25 11:21:20 +0000
4@@ -48,19 +48,39 @@
5 class res_partner(osv.osv):
6 _inherit = 'res.partner'
7
8- def _split_vat(self, vat):
9- vat_country, vat_number = vat[:2].lower(), vat[2:].replace(' ', '')
10+ def _split_vat(self, vat_country_code, vat):
11+ vat_country, vat_number = vat_country_code.lower(), vat.replace(' ', '')
12 return vat_country, vat_number
13
14 def check_vat(self, cr, uid, ids):
15 '''
16 Check the VAT number depending of the country.
17 http://sima-pc.com/nif.php
18- '''
19+
20+ => Developers: make sure to add the country ISO 3166 code in the current_country_codes variable for each new vat code verification function
21+ For more info about country ISO codes :
22+ http://www.iso.org/iso/english_country_names_and_code_elements
23+
24+ Note that UK is just an alias for GB. Once it gets fixed on the global country code lists it should be removed.
25+ '''
26+
27+ 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"]
28+
29 for partner in self.browse(cr, uid, ids):
30 if not partner.vat:
31 continue
32- vat_country, vat_number = self._split_vat(partner.vat)
33+
34+ if not partner.vat_country:
35+ continue
36+
37+ if not partner.verify_vat:
38+ continue
39+
40+ if not partner.vat_country.code in current_country_codes:
41+ continue
42+
43+ vat_country, vat_number = self._split_vat(partner.vat_country, partner.vat)
44+
45 if not hasattr(self, 'check_vat_' + vat_country):
46 return False
47 check = getattr(self, 'check_vat_' + vat_country)
48@@ -72,7 +92,9 @@
49 return {'value': {'vat_subjected': bool(value)}}
50
51 _columns = {
52- '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.")
53+ '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."),
54+ 'vat_country':fields.many2one('res.country','VAT Country',help="Country corresponding to this VAT number"),
55+ '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"),
56 }
57
58 def _construct_constraint_msg(self, cr, uid, ids):
59@@ -81,7 +103,8 @@
60 # it starts with 2 letters
61 # has more than 3 characters
62 return cn[0] in string.ascii_lowercase and cn[1] in string.ascii_lowercase
63- vat_country, vat_number = self._split_vat(self.browse(cr, uid, ids)[0].vat)
64+ partner_obj = self.browse(cr, uid, ids)[0]
65+ vat_country, vat_number = self._split_vat(partner_obj.vat_country, partner_obj.vat)
66 if default_vat_check(vat_country, vat_number):
67 vat_no = vat_country in _ref_vat and _ref_vat[vat_country] or 'Country Code + Vat Number'
68 return _('The Vat does not seems to be correct. You should have entered something like this %s'), (vat_no)
69@@ -91,6 +114,43 @@
70
71 # code from the following methods come from Tryton (B2CK)
72 # http://www.tryton.org/hgwebdir.cgi/modules/relationship/file/544d1de586d9/party.py
73+
74+ def check_vat_ar(self, vat):
75+ '''
76+ Check VAT (CUIT) for Argentina - Thymbra.
77+ '''
78+
79+ cstr = str (vat)
80+ salt=str (5432765432)
81+ n=0
82+ sum=0
83+
84+ if not vat.isdigit:
85+ return False
86+
87+ if (len (vat) <> 11):
88+ return False
89+
90+ while (n < 10):
91+ sum = sum + int (salt[n]) * int (cstr[n])
92+ n=n+1
93+
94+ op1 = sum % 11
95+ op2 = 11 - op1
96+
97+ codigo_verificador = op2
98+
99+ if ( op2 == 11 or op2 == 10):
100+ if ( op2 == 11 ):
101+ codigo_verificador = 0
102+ else:
103+ codigo_verificador = 9
104+
105+ if ( codigo_verificador == int (cstr[10]) ):
106+ return True
107+ else:
108+ return False
109+
110 def check_vat_at(self, vat):
111 '''
112 Check Austria VAT number.
113
114=== modified file 'base_vat/base_vat_view.xml'
115--- base_vat/base_vat_view.xml 2010-05-25 14:01:13 +0000
116+++ base_vat/base_vat_view.xml 2010-11-25 11:21:20 +0000
117@@ -8,9 +8,11 @@
118 <field name="inherit_id" ref="account.view_partner_property_form"/>
119 <field name="arch" type="xml">
120 <field name="property_account_payable" position="after">
121- <group colspan="2" col="6">
122- <field name="vat" on_change="vat_change(vat)" colspan="4" />
123- <field name="vat_subjected" colspan="1"/>
124+ <group colspan="2" col="4">
125+ <field name="vat_country" select="2"/>
126+ <field name="vat" on_change="vat_change(vat)" colspan="4" />
127+ <field name="vat_subjected" colspan="1"/>
128+ <field name="verify_vat"/>
129 </group>
130 </field>
131 </field>

Subscribers

People subscribed via source and target branches

to all changes: