Merge lp:~team-cluster/openerp-venezuela-localization/ovl70-fiscal-requirements-eochoa-vat into lp:openerp-venezuela-localization

Proposed by Eduardo Ochoa - Cluster Brands
Status: Superseded
Proposed branch: lp:~team-cluster/openerp-venezuela-localization/ovl70-fiscal-requirements-eochoa-vat
Merge into: lp:openerp-venezuela-localization
Diff against target: 140 lines (+27/-57)
2 files modified
l10n_ve_fiscal_requirements/model/partner.py (+12/-3)
l10n_ve_fiscal_requirements/model/seniat_url.py (+15/-54)
To merge this branch: bzr merge lp:~team-cluster/openerp-venezuela-localization/ovl70-fiscal-requirements-eochoa-vat
Reviewer Review Type Date Requested Status
hbto [Vauxoo] http://www.vauxoo.com Needs Fixing
Nhomar - Vauxoo Pending
Review via email: mp+170369@code.launchpad.net

This proposal has been superseded by a proposal from 2013-06-27.

Description of the change

Reengineering l10nve_fiscal_requirements module to improve the response time on requests to SENIAT

To post a comment you must log in.
Revision history for this message
hbto [Vauxoo] http://www.vauxoo.com (humbertoarocha) wrote :

Hello Eduardo, I am reviewing your merge proposal,

Changing Method
def _get_valid_digit(self, cr, uid, ids, vat, context=None):

by
def _complete_vat(self,vat):

gives same result.

In Section

        elif re.search(r'^([VE][0-9]{1,8})$', vat):
            '''Checked vat is an ID'''
            vat = vat[0] + vat[1:].rjust(8,'0')
            vat = vat+self._complete_vat(vat)
            return self._get_rif(cr, uid, vat, url1, url2, context=context)

Changing

vat = vat+self._complete_vat(vat)

by

vat = self._validate_rif(cr, uid, ids, vat, context=context)

would render same result.

BTW, _validate_rif method has gotten replaced with _complete_vat method of yours

Though I do _not_ agree with this concept of _always_ given to a vat of 8 chars
the ninth char, the validating digit, thus we are agreeing that all 8 chars people are Tax Payers, and there are chance that 8 chars people are non-tax payers,

In the event that we are validating this with SENIAT portal, we would be falling
into a loop which would lead to not allowing non-tax payers to be recorded within Partners.

Regarding to added method:

    def vies_vat_check(self, cr, uid, country_code, vat_number, context=None):

        if country_code != "ve":

The country_code should be upper-cased, to avoid mistakes when code be [VE,vE,Ve]
and the method should have a minimum docstring (Copy & Paste from base_vat :D )

You have renamed method

def button_check_vat(self, cr, uid, ids, context=None):

to def check_vat(self, cr, uid, ids, context=None):

And it could look good to me, but

you have forgotten to change the name attribute of button used in the view in res.partner
which uses that same method name

<button name="button_check_vat" string="Check Validity" type="object" icon="gtk-execute" class="oe_inline"/>

Thanks in advance for your contribution

Hbto

review: Needs Fixing
888. By Eduardo Ochoa - Cluster Brands

[REF]
-upper-cased country-code param in the method check_vies
-changed check_vat method from button_check_vat method

889. By Eduardo Ochoa - Cluster Brands

[REF]
-added docstring to check_vies method

890. By Eduardo Ochoa - Cluster Brands

[IMP]
-Added check_rif method to seniat.url class to query a vat
without creating an object

891. By Eduardo Ochoa - Cluster Brands

[REF]
      -Restored the methods _get_valid_digit and _validate_rif
      -Refactored _dom_giver method to remove redundant validations
      that are already on the function _validate_rif

892. By Eduardo Ochoa - Cluster Brands

[REF]
-Fixed slice for vat country code
-Raised exception when the validator digit don't match

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_ve_fiscal_requirements/model/partner.py'
2--- l10n_ve_fiscal_requirements/model/partner.py 2013-06-04 03:15:49 +0000
3+++ l10n_ve_fiscal_requirements/model/partner.py 2013-06-27 13:10:36 +0000
4@@ -205,7 +205,7 @@
5 def _validate(self, cr, uid, ids, context=None):
6 """ Validates the fields
7 """
8-
9+
10 #In the original orm.py openerp does not allow using
11 #context within the constraint because we have to yield
12 # the same result always,
13@@ -279,6 +279,15 @@
14 return True
15 return False
16
17+ def vies_vat_check(self, cr, uid, country_code, vat_number, context=None):
18+ """
19+ Validate against VAT Information Exchange System (VIES)
20+ """
21+ if country_code.upper() != "VE":
22+ return super(res_partner, self).vies_vat_check(cr, uid, country_code, vat_number,context=context)
23+ else:
24+ return super(res_partner, self).simple_vat_check(cr, uid, country_code, vat_number, context=context)
25+
26 def update_rif(self, cr, uid, ids, context=None):
27 """ Load the rif and name of the partner from the database seniat
28 """
29@@ -293,11 +302,11 @@
30 """
31 if context is None: context = {}
32 context.update({'update_fiscal_information':True})
33- super(res_partner, self).button_check_vat(cr, uid, ids, context=context)
34+ super(res_partner, self).check_vat(cr, uid, ids, context=context)
35 user_company = self.pool.get('res.users').browse(cr, uid, uid).company_id
36 if user_company.vat_check_vies:
37 # force full VIES online check
38 self.update_rif(cr, uid, ids, context=context)
39- return True
40+ return True
41 res_partner()
42 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
43
44=== modified file 'l10n_ve_fiscal_requirements/model/seniat_url.py'
45--- l10n_ve_fiscal_requirements/model/seniat_url.py 2013-06-03 21:24:15 +0000
46+++ l10n_ve_fiscal_requirements/model/seniat_url.py 2013-06-27 13:10:36 +0000
47@@ -54,56 +54,18 @@
48 }
49
50 # Update Partner Information
51-
52- def _get_valid_digit(self, cr, uid, ids, vat, context=None):
53+
54+ def _complete_vat(self,vat):
55 '''
56 @param vat: string
57 returns validating digit
58 '''
59- divisor = 11
60- vat_type = {'V':1, 'E':2, 'J':3, 'P':4, 'G':5}
61- mapper = {1:3, 2:2, 3:7, 4:6, 5:5, 6:4, 7:3, 8:2}
62- valid_digit = None
63-
64- vat_type = vat_type.get(vat[0].upper())
65- if vat_type:
66- sum = vat_type * 4
67- for i in range(8):
68- sum += int(vat[i+1]) * mapper[i+1]
69-
70- valid_digit = divisor - sum%divisor
71- if valid_digit >= 10:
72- valid_digit = 0
73- return valid_digit
74-
75- def _validate_rif(self, cr, uid, ids, vat, context=None):
76- '''validates if the VE VAT NUMBER is right
77- @param vat: string: Vat number to Check
78- returns vat when right otherwise returns False
79-
80- '''
81- if not vat:
82- return False
83-
84- if 'VE' in vat:
85- vat = vat[:2]
86-
87- if re.search(r'^[VJEGP][0-9]{9}$', vat):
88- valid_digit = self._get_valid_digit(cr, uid, ids, vat,
89- context=context)
90- if valid_digit is None:
91- return False
92- if int(vat[9])==valid_digit:
93- return vat
94- else:
95- return False
96- elif re.search(r'^([VE][0-9]{1,8})$', vat):
97- vat = vat[0] + vat[1:].rjust(8, '0')
98- valid_digit = self._get_valid_digit(cr, uid, ids, vat,
99- context=context)
100- vat += str(valid_digit)
101- return vat
102- return False
103+ diff = {'V':1,'E':2,'J':3,'P':4,'G':5}
104+ sum = int(vat[1])*3+int(vat[2])*2+int(vat[3])*7+int(vat[4])*6 + \
105+ int(vat[5])*5+int(vat[6])*4+int(vat[7])*3+int(vat[8])*2 + \
106+ diff[vat[0]]*4
107+ ret = 11-sum % 11;
108+ return (ret >= 10) and "0" or str(ret)
109
110 def _load_url(self, retries, url):
111 """ Check that the seniat url is loaded correctly
112@@ -179,6 +141,10 @@
113 if not self._eval_seniat_data(xml_data, vat, context=context):
114 dom = parseString(xml_data)
115 return self._parse_dom(cr, uid, dom, vat, url2, context=context)
116+
117+ def check_rif(self, cr, uid, vat, context=None):
118+ context = context or {}
119+ return self._dom_giver(cr, uid, vat, context=context)
120
121 def _dom_giver(self, cr, uid, vat, context=None):
122 """ Check and validates that the vat is a passport,
123@@ -204,14 +170,9 @@
124
125 elif re.search(r'^([VE][0-9]{1,8})$', vat):
126 '''Checked vat is an ID'''
127- xml_data = self._load_url(3, url3 % str(int(vat[1:])))
128- vat = vat[1:].rjust(8, '0')
129- match2 = re.search(r'[VE]' + vat + '[0-9]{1}', xml_data)
130- if re.search(r'No existe el contribuyente solicitado', xml_data):
131- return False
132- elif match2:
133- vat = match2.group(0)
134- return self._get_rif(cr, uid, vat, url1, url2, context=context)
135+ vat = vat[0] + vat[1:].rjust(8,'0')
136+ vat = vat+self._complete_vat(vat)
137+ return self._get_rif(cr, uid, vat, url1, url2, context=context)
138
139 def _update_partner(self, cr, uid, id, context=None):
140 """ Indicates that the partner was updated with information provided by seniat