From 323aa0e8ad1f932be0d2f1b8eecdcf99b4b600d8 Mon Sep 17 00:00:00 2001 From: skh Date: Wed, 11 May 2011 14:48:38 +0530 Subject: [PATCH 01/55] [IMP] base_vat: Validate the VAT Number using the python.vatnumber Library => remove the method to check vat numbers bzr revid: skh@tinyerp.com-20110511091838-jb4j7w5t29bpv04h --- addons/base_vat/base_vat.py | 1028 +---------------------------------- 1 file changed, 6 insertions(+), 1022 deletions(-) diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 69b312ee62f..5e2712fc6fb 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -20,32 +20,9 @@ # ############################################################################## import string - from osv import osv, fields from tools.translate import _ - -_ref_vat = { - 'be': 'BE0477472701', 'at': 'ATU12345675', - 'bg': 'BG1234567892', 'cy': 'CY12345678F', - 'cz': 'CZ12345679', 'de': 'DE123456788', - 'dk': 'DK12345674', 'ee': 'EE123456780', - 'es': 'ESA12345674', 'fi': 'FI12345671', - 'fr': 'FR32123456789', 'gb': 'GB123456782', - 'gr': 'GR12345670', 'hu': 'HU12345676', - 'ie': 'IE1234567T', 'it': 'IT12345670017', - 'lt': 'LT123456715', 'lu': 'LU12345613', - 'lv': 'LV41234567891', 'mt': 'MT12345634', - 'nl': 'NL123456782B90', 'pl': 'PL1234567883', - 'pt': 'PT123456789', 'ro': 'RO1234567897', - 'se': 'SE123456789701', 'si': 'SI12345679', - 'sk': 'SK0012345675', 'el': 'EL12345670', - 'mx': 'MXABC123456T1B' - - } - -def mult_add(i, j): - """Sum each digits of the multiplication of i and j.""" - return reduce(lambda x, y: x + int(y), str(i*j), 0) +import vatnumber #User should install "python-vatnumber" package from the Synaptic Package Manager to check valid VAT NUMBER class res_partner(osv.osv): _inherit = 'res.partner' @@ -59,19 +36,15 @@ class res_partner(osv.osv): Check the VAT number depending of the country. http://sima-pc.com/nif.php ''' - country_obj = self.pool.get('res.country') for partner in self.browse(cr, uid, ids, context=context): if not partner.vat: continue vat_country, vat_number = self._split_vat(partner.vat) - if not hasattr(self, 'check_vat_' + vat_country): - #We didn't find the validation method for the country code. If that country code can be found in openerp, this means that it is a valid country code - #and we simply didn't have implemented that function. In that case we continue. - if country_obj.search(cr, uid, [('code', 'ilike', vat_country)], context=context): + if not hasattr(vatnumber, 'check_vat_' + vat_country): + if vat_country.upper() in vatnumber.countries(): continue - #Otherwise, it means that the country code isn't valid and we return False. return False - check = getattr(self, 'check_vat_' + vat_country) + check = getattr(vatnumber, 'check_vat_' + vat_country) if not check(vat_number): return False return True @@ -85,1004 +58,15 @@ class res_partner(osv.osv): def _construct_constraint_msg(self, cr, uid, ids, context=None): def default_vat_check(cn, vn): - # by default, a VAT number is valid if: - # 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) 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' + vat_no = vat_country in vatnumber.countries() and vatnumber.countries() or 'Country Code + Vat Number' return _('The Vat does not seems to be correct. You should have entered something like this %s'), (vat_no) return _('The VAT is invalid, It should begin with the country code'), () _constraints = [(check_vat, _construct_constraint_msg, ["vat"])] - - # code from the following methods come from Tryton (B2CK) - # http://www.tryton.org/hgwebdir.cgi/modules/relationship/file/544d1de586d9/party.py - def check_vat_at(self, vat): - ''' - Check Austria VAT number. - ''' - if len(vat) != 9: - return False - if vat[0] != 'U': - return False - num = vat[1:] - try: - int(num) - except: - return False - sum = int(num[0]) + mult_add(2, int(num[1])) + \ - int(num[2]) + mult_add(2, int(num[3])) + \ - int(num[4]) + mult_add(2, int(num[5])) + \ - int(num[6]) - check = 10 - ((sum + 4) % 10) - if check == 10: - check = 0 - if int(vat[-1:]) != check: - return False - return True - - def check_vat_be(self, vat): - ''' - Check Belgium VAT number. - ''' - if len(vat) != 10: - return False - try: - int(vat) - except: - return False - if int(vat[-2:]) != \ - 97 - (int(vat[:8]) % 97): - return False - return True - - def check_vat_bg(self, vat): - ''' - Check Bulgaria VAT number. - ''' - if len(vat) not in [9,10]: - return False - try: - int(vat) - except: - return False - if int(vat[0]) in (2, 3) and \ - int(vat[1:2]) != 22: - return False - sum = 4 * int(vat[0]) + 3 * int(vat[1]) + 2 * int(vat[2]) + \ - 7 * int(vat[3]) + 6 * int(vat[4]) + 5 * int(vat[5]) + \ - 4 * int(vat[6]) + 3 * int(vat[7]) + 2 * int(vat[8]) - check = 11 - (sum % 11) - if check == 11: - check = 0 - return True - - def check_vat_cy(self, vat): - ''' - Check Cyprus VAT number. - ''' - if len(vat) != 9: - return False - try: - int(vat[:8]) - except: - return False - n0 = int(vat[0]) - n1 = int(vat[1]) - n2 = int(vat[2]) - n3 = int(vat[3]) - n4 = int(vat[4]) - n5 = int(vat[5]) - n6 = int(vat[6]) - n7 = int(vat[7]) - - def conv(x): - if x == 0: - return 1 - elif x == 1: - return 0 - elif x == 2: - return 5 - elif x == 3: - return 7 - elif x == 4: - return 9 - elif x == 5: - return 13 - elif x == 6: - return 15 - elif x == 7: - return 17 - elif x == 8: - return 19 - elif x == 9: - return 21 - return x - n0 = conv(n0) - n2 = conv(n2) - n4 = conv(n4) - n6 = conv(n6) - - sum = n0 + n1 + n2 + n3 + n4 + n5 + n6 + n7 - check = chr(sum % 26 + 65) - if check != vat[8]: - return False - return True - - def check_vat_cz(self, vat): - ''' - Check Czech Republic VAT number. - ''' - if len(vat) not in (8, 9, 10): - return False - try: - int(vat) - except: - return False - - if len(vat) == 8: - if int(vat[0]) not in (0, 1, 2, 3, 4, 5, 6, 7, 8): - return False - sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \ - 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \ - 2 * int(vat[6]) - check = 11 - (sum % 11) - if check == 10: - check = 0 - if check == 11: - check = 1 - if check != int(vat[7]): - return False - elif len(vat) == 9 and int(vat[0]) == 6: - sum = 8 * int(vat[1]) + 7 * int(vat[2]) + 6 * int(vat[3]) + \ - 5 * int(vat[4]) + 4 * int(vat[5]) + 3 * int(vat[6]) + \ - 2 * int(vat[7]) - check = 9 - ((11 - (sum % 11)) % 10) - if check != int(vat[8]): - return False - elif len(vat) == 9: - if int(vat[0:2]) > 53 and int(vat[0:2]) < 80: - return False - if int(vat[2:4]) < 1: - return False - if int(vat[2:4]) > 12 and int(vat[2:4]) < 51: - return False - if int(vat[2:4]) > 62: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0: - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 28: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0: - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 29: - return False - if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61): - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 30: - return False - if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12, 51, - 53, 55, 57, 58, 60, 62): - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 31: - return False - elif len(vat) == 10: - if int(vat[0:2]) < 54: - return False - if int(vat[2:4]) < 1: - return False - if int(vat[2:4]) > 12 and int(vat[2:4]) < 51: - return False - if int(vat[2:4]) > 62: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0: - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 28: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0: - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 29: - return False - if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61): - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 30: - return False - if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12, 51, - 53, 55, 57, 58, 60, 62): - if int(vat[4:6]) < 1: - return False - if int(vat[4:6]) > 31: - return False - if (int(vat[0:2]) + int(vat[2:4]) + int(vat[4:6]) + int(vat[6:8]) + - int(vat[8:10])) % 11 != 0: - return False - if int(vat[0:10]) % 11 != 0: - return False - return True - - def check_vat_de(self, vat): - ''' - Check Germany VAT number. - ''' - if len(vat) != 9: - return False - try: - int(vat) - except: - return False - if int(vat[0:7]) <= 0: - return False - sum = 0 - for i in range(8): - sum = (2 * ((int(vat[i]) + sum + 9) % 10 + 1)) % 11 - check = 11 - sum - if check == 10: - check = 0 - if int(vat[8]) != check: - return False - return True - - def check_vat_dk(self, vat): - ''' - Check Denmark VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - if int(vat[0]) <= 0: - return False - sum = 2 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \ - 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \ - 2 * int(vat[6]) + int(vat[7]) - if sum % 11 != 0: - return False - return True - - def check_vat_ee(self, vat): - ''' - Check Estonia VAT number. - ''' - if len(vat) != 9: - return False - try: - int(vat) - except: - return False - sum = 3 * int(vat[0]) + 7 * int(vat[1]) + 1 * int(vat[2]) + \ - 3 * int(vat[3]) + 7 * int(vat[4]) + 1 * int(vat[5]) + \ - 3 * int(vat[6]) + 7 * int(vat[7]) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[8]): - return False - return True - - def check_vat_es(self, vat): - ''' - Check Spain VAT number. - ''' - if len(vat) != 9: - return False - - conv = { - 1: 'T', - 2: 'R', - 3: 'W', - 4: 'A', - 5: 'G', - 6: 'M', - 7: 'Y', - 8: 'F', - 9: 'P', - 10: 'D', - 11: 'X', - 12: 'B', - 13: 'N', - 14: 'J', - 15: 'Z', - 16: 'S', - 17: 'Q', - 18: 'V', - 19: 'H', - 20: 'L', - 21: 'C', - 22: 'K', - 23: 'E', - } - #Legal persons with profit aim - if vat[0] in ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'U', 'V'): - try: - int(vat[1:8]) - except: - return False - sum = mult_add(2, int(vat[1])) + int(vat[2]) + \ - mult_add(2, int(vat[3])) + int(vat[4]) + \ - mult_add(2, int(vat[5])) + int(vat[6]) + \ - mult_add(2, int(vat[7])) - check = 10 - (sum % 10) - if check == 10: - check = 0 - return True - #Legal persons with non-profit aim - elif vat[0] in ('N', 'P', 'Q', 'R', 'S', 'W'): - try: - int(vat[1:8]) - except: - return False - sum = mult_add(2, int(vat[1])) + int(vat[2]) + \ - mult_add(2, int(vat[3])) + int(vat[4]) + \ - mult_add(2, int(vat[5])) + int(vat[6]) + \ - mult_add(2, int(vat[7])) - check = 10 - (sum % 10) - check = chr(check + 64) - if check != vat[8]: - return False - return True - #Foreign natural persons, under age 14 or non-residents - elif vat[0] in ('K', 'L', 'M', 'X', 'Y', 'Z'): - if vat[0] == 'Y': - check_value = '1' + vat[1:8] - elif vat[0] == 'Z': - check_value = '2' + vat[1:8] - else: - check_value = vat[1:8] - - try: - int(check_value) - except: - return False - check = 1 + (int(check_value) % 23) - - check = conv[check] - if check != vat[8]: - return False - return True - #Spanish natural persons - else: - try: - int(vat[:8]) - except: - return False - check = 1 + (int(vat[:8]) % 23) - - check = conv[check] - if check != vat[8]: - return False - return True - - def check_vat_fi(self, vat): - ''' - Check Finland VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - sum = 7 * int(vat[0]) + 9 * int(vat[1]) + 10 * int(vat[2]) + \ - 5 * int(vat[3]) + 8 * int(vat[4]) + 4 * int(vat[5]) + \ - 2 * int(vat[6]) - check = 11 - (sum % 11) - if check == 11: - check = 0 - if check == 10: - return False - if check != int(vat[7]): - return False - return True - - def check_vat_fr(self, vat): - ''' - Check France VAT number. - ''' - if len(vat) != 11: - return False - - try: - int(vat[2:11]) - except: - return False - - system = None - try: - int(vat[0:2]) - system = 'old' - except: - system = 'new' - - if system == 'old': - check = ((int(vat[2:11]) * 100) + 12) % 97 - if check != int(vat[0:2]): - return False - return True - else: - conv = ['0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z'] - if vat[0] not in conv \ - or vat[1] not in conv: - return False - c1 = conv.index(vat[0]) - c2 = conv.index(vat[1]) - - if c1 < 10: - sum = c1 * 24 + c2 - 10 - else: - sum = c1 * 34 + c2 - 100 - - x = sum % 11 - sum = (int(sum) / 11) + 1 - y = (int(vat[2:11]) + sum) % 11 - if x != y: - return False - return True - - def check_vat_gb(self, vat): - ''' - Check United Kingdom VAT number. - ''' - - if len(vat) == 5: - try: - int(vat[2:5]) - except: - return False - - if vat[0:2] == 'GD': - if int(vat[2:5]) >= 500: - return False - return True - if vat[0:2] == 'HA': - if int(vat[2:5]) < 500: - return False - return True - return False - elif len(vat) in (9, 10): - try: - int(vat) - except: - return False - - if int(vat[0:7]) < 1: - return False - if int(vat[0:7]) > 19999 and int(vat[0:7]) < 1000000: - return False - if int(vat[7:9]) > 97: - return False - if len(vat) == 10 and int(vat[9]) != 3: - return False - - sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \ - 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \ - 2 * int(vat[6]) + 10 * int(vat[7]) + int(vat[8]) - if int(vat[0:3]) > 100: - if sum % 97 not in (0, 55, 42): - return False - else: - if sum % 97 != 0: - return False - return True - elif len(vat) in (12, 13): - try: - int(vat) - except: - return False - - if int(vat[0:3]) not in (0, 1): - return False - - if int(vat[3:10]) < 1: - return False - if int(vat[3:10]) > 19999 and int(vat[3:10]) < 1000000: - return False - if int(vat[10:12]) > 97: - return False - if len(vat) == 13 and int(vat[12]) != 3: - return False - - sum = 8 * int(vat[3]) + 7 * int(vat[4]) + 6 * int(vat[5]) + \ - 5 * int(vat[6]) + 4 * int(vat[7]) + 3 * int(vat[8]) + \ - 2 * int(vat[9]) + 10 * int(vat[10]) + int(vat[11]) - if sum % 97 != 0: - return False - return True - return False - - def check_vat_gr(self, vat): - ''' - Check Greece VAT number. - ''' - try: - int(vat) - except: - return False - if len(vat) == 8: - sum = 128 * int(vat[0]) + 64 * int(vat[1]) + 32 * int(vat[2]) + \ - 16 * int(vat[3]) + 8 * int(vat[4]) + 4 * int(vat[5]) + \ - 2 * int(vat[6]) - check = sum % 11 - if check == 10: - check = 0 - if check != int(vat[7]): - return False - return True - elif len(vat) == 9: - sum = 256 * int(vat[0]) + 128 * int(vat[1]) + 64 * int(vat[2]) + \ - 32 * int(vat[3]) + 16 * int(vat[4]) + 8 * int(vat[5]) + \ - 4 * int(vat[6]) + 2 * int(vat[7]) - check = sum % 11 - if check == 10: - check = 0 - if check != int(vat[8]): - return False - return True - return False - - def check_vat_el(self, vat): - return self.check_vat_gr(vat) - - def check_vat_hu(self, vat): - ''' - Check Hungary VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - if int(vat[0]) <= 0: - return False - sum = 9 * int(vat[0]) + 7 * int(vat[1]) + 3 * int(vat[2]) + \ - 1 * int(vat[3]) + 9 * int(vat[4]) + 7 * int(vat[5]) + \ - 3 * int(vat[6]) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[7]): - return False - return True - - def check_vat_ie(self, vat): - ''' - Check Ireland VAT number. - ''' - if len(vat) != 8: - return False - if (ord(vat[1]) >= 65 and ord(vat[1]) <= 90) \ - or vat[1] in ('+', '*'): - try: - int(vat[0]) - int(vat[2:7]) - except: - return False - - if int(vat[0]) <= 6: - return False - - sum = 7 * int(vat[2]) + 6 * int(vat[3]) + 5 * int(vat[4]) + \ - 4 * int(vat[5]) + 3 * int(vat[6]) + 2 * int(vat[0]) - check = sum % 23 - if check == 0: - check = 'W' - else: - check = chr(check + 64) - if check != vat[7]: - return False - return True - else: - try: - int(vat[0:7]) - except: - return False - - sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \ - 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \ - 2 * int(vat[6]) - check = sum % 23 - if check == 0: - check = 'W' - else: - check = chr(check + 64) - if check != vat[7]: - return False - return True - - def check_vat_it(self, vat): - ''' - Check Italy VAT number. - ''' - if len(vat) != 11: - return False - try: - int(vat) - except: - return False - if int(vat[0:7]) <= 0: - return False - if int(vat[7:10]) <= 0: - return False - if int(vat[7:10]) > 100 and int(vat[7:10]) < 120: - return False - - sum = int(vat[0]) + mult_add(2, int(vat[1])) + int(vat[2]) + \ - mult_add(2, int(vat[3])) + int(vat[4]) + \ - mult_add(2, int(vat[5])) + int(vat[6]) + \ - mult_add(2, int(vat[7])) + int(vat[8]) + \ - mult_add(2, int(vat[9])) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[10]): - return False - return True - - def check_vat_lt(self, vat): - ''' - Check Lithuania VAT number. - ''' - try: - int(vat) - except: - return False - - if len(vat) == 9: - if int(vat[7]) != 1: - return False - sum = 1 * int(vat[0]) + 2 * int(vat[1]) + 3 * int(vat[2]) + \ - 4 * int(vat[3]) + 5 * int(vat[4]) + 6 * int(vat[5]) + \ - 7 * int(vat[6]) + 8 * int(vat[7]) - if sum % 11 == 10: - sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 5 * int(vat[2]) + \ - 6 * int(vat[3]) + 7 * int(vat[4]) + 8 * int(vat[5]) + \ - 9 * int(vat[6]) + 1 * int(vat[7]) - check = sum % 11 - if check == 10: - check = 0 - if check != int(vat[8]): - return False - return True - elif len(vat) == 12: - if int(vat[10]) != 1: - return False - sum = 1 * int(vat[0]) + 2 * int(vat[1]) + 3 * int(vat[2]) + \ - 4 * int(vat[3]) + 5 * int(vat[4]) + 6 * int(vat[5]) + \ - 7 * int(vat[6]) + 8 * int(vat[7]) + 9 * int(vat[8]) + \ - 1 * int(vat[9]) + 2 * int(vat[10]) - if sum % 11 == 10: - sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 5 * int(vat[2]) + \ - 6 * int(vat[3]) + 7 * int(vat[4]) + 8 * int(vat[5]) + \ - 9 * int(vat[6]) + 1 * int(vat[7]) + 2 * int(vat[8]) + \ - 3 * int(vat[9]) + 4 * int(vat[10]) - check = sum % 11 - if check == 10: - check = 0 - if check != int(vat[11]): - return False - return True - return False - - def check_vat_lu(self, vat): - ''' - Check Luxembourg VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - if int(vat[0:6]) <= 0: - return False - check = int(vat[0:6]) % 89 - if check != int(vat[6:8]): - return False - return True - - def check_vat_lv(self, vat): - ''' - Check Latvia VAT number. - ''' - if len(vat) != 11: - return False - try: - int(vat) - except: - return False - if int(vat[0]) >= 4: - sum = 9 * int(vat[0]) + 1 * int(vat[1]) + 4 * int(vat[2]) + \ - 8 * int(vat[3]) + 3 * int(vat[4]) + 10 * int(vat[5]) + \ - 2 * int(vat[6]) + 5 * int(vat[7]) + 7 * int(vat[8]) + \ - 6 * int(vat[9]) - if sum % 11 == 4 and int(vat[0]) == 9: - sum = sum - 45 - if sum % 11 == 4: - check = 4 - (sum % 11) - elif sum % 11 > 4: - check = 14 - (sum % 11) - elif sum % 11 < 4: - check = 3 - (sum % 11) - if check != int(vat[10]): - return False - return True - else: - if int(vat[2:4]) == 2 and int(vat[4:6]) % 4 > 0: - if int(vat[0:2]) < 1 or int(vat[0:2]) > 28: - return False - if int(vat[2:4]) == 2 and int(vat[4:6]) % 4 == 0: - if int(vat[0:2]) < 1 or int(vat[0:2]) > 29: - return False - if int(vat[2:4]) in (4, 6, 9, 11): - if int(vat[0:2]) < 1 or int(vat[0:2]) > 30: - return False - if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12): - if int(vat[0:2]) < 1 or int(vat[0:2]) > 31: - return False - if int(vat[2:4]) < 1 or int(vat[2:4]) > 12: - return False - return True - - def check_vat_mt(self, vat): - ''' - Check Malta VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - - if int(vat[0:6]) < 100000: - return False - - sum = 3 * int(vat[0]) + 4 * int(vat[1]) + 6 * int(vat[2]) + \ - 7 * int(vat[3]) + 8 * int(vat[4]) + 9 * int(vat[5]) - check = 37 - (sum % 37) - if check != int(vat[6:8]): - return False - return True - - def check_vat_nl(self, vat): - ''' - Check Netherlands VAT number. - ''' - if len(vat) != 12: - return False - try: - int(vat[0:9]) - int(vat[10:12]) - except: - return False - if int(vat[0:8]) <= 0: - return False - if vat[9] != 'B': - return False - - sum = 9 * int(vat[0]) + 8 * int(vat[1]) + 7 * int(vat[2]) + \ - 6 * int(vat[3]) + 5 * int(vat[4]) + 4 * int(vat[5]) + \ - 3 * int(vat[6]) + 2 * int(vat[7]) - - check = sum % 11 - if check == 10: - return False - if check != int(vat[8]): - return False - return True - - def check_vat_pl(self, vat): - ''' - Check Poland VAT number. - ''' - if len(vat) != 10: - return False - try: - int(vat) - except: - return False - - sum = 6 * int(vat[0]) + 5 * int(vat[1]) + 7 * int(vat[2]) + \ - 2 * int(vat[3]) + 3 * int(vat[4]) + 4 * int(vat[5]) + \ - 5 * int(vat[6]) + 6 * int(vat[7]) + 7 * int(vat[8]) - check = sum % 11 - if check == 10: - return False - if check != int(vat[9]): - return False - return True - - def check_vat_pt(self, vat): - ''' - Check Portugal VAT number. - ''' - if len(vat) != 9: - return False - try: - int(vat) - except: - return False - - if int(vat[0]) <= 0: - return False - - sum = 9 * int(vat[0]) + 8 * int(vat[1]) + 7 * int(vat[2]) + \ - 6 * int(vat[3]) + 5 * int(vat[4]) + 4 * int(vat[5]) + \ - 3 * int(vat[6]) + 2 * int(vat[7]) - check = 11 - (sum % 11) - if check == 10 or check == 11: - check = 0 - return True - - def check_vat_ro(self, vat): - ''' - Check Romania VAT number. - ''' - try: - int(vat) - except: - return False - - if len(vat) >= 2 and len(vat) <= 10: - vat = (10 - len(vat)) * '0' + vat - sum = 7 * int(vat[0]) + 5 * int(vat[1]) + 3 * int(vat[2]) + \ - 2 * int(vat[3]) + 1 * int(vat[4]) + 7 * int(vat[5]) + \ - 5 * int(vat[6]) + 3 * int(vat[7]) + 2 * int(vat[8]) - check = (sum * 10) % 11 - if check == 10: - check = 0 - if check != int(vat[9]): - return False - return True - elif len(vat) == 13: - if int(vat[0]) not in (1, 2, 3, 4, 6): - return False - if int(vat[3:5]) < 1 or int(vat[3:5]) > 12: - return False - if int(vat[3:5]) == 2 and int(vat[1:3]) % 4 > 0: - if int(vat[5:7]) < 1 or int(vat[5:7]) > 28: - return False - if int(vat[3:5]) == 2 and int(vat[1:3]) % 4 == 0: - if int(vat[5:7]) < 1 or int(vat[5:7]) > 29: - return False - if int(vat[3:5]) in (4, 6, 9, 11): - if int(vat[5:7]) < 1 or int(vat[5:7]) > 30: - return False - if int(vat[3:5]) in (1, 3, 5, 7, 8, 10, 12): - if int(vat[5:7]) < 1 or int(vat[5:7]) > 31: - return False - - sum = 2 * int(vat[0]) + 7 * int(vat[1]) + 9 * int(vat[2]) + \ - 1 * int(vat[3]) + 4 * int(vat[4]) + 6 * int(vat[5]) + \ - 3 * int(vat[6]) + 5 * int(vat[7]) + 8 * int(vat[8]) + \ - 2 * int(vat[9]) + 7 * int(vat[10]) + 9 * int(vat[11]) - check = sum % 11 - if check == 10: - check = 1 - if check != int(vat[12]): - return False - return True - return False - - def check_vat_se(self, vat): - ''' - Check Sweden VAT number. - ''' - if len(vat) != 12: - return False - try: - int(vat) - except: - return False - - if int(vat[9:11]) < 0: - return False - - sum = mult_add(2, int(vat[0])) + int(vat[1]) + \ - mult_add(2, int(vat[2])) + int(vat[3]) + \ - mult_add(2, int(vat[4])) + int(vat[5]) + \ - mult_add(2, int(vat[6])) + int(vat[7]) + \ - mult_add(2, int(vat[8])) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[9]): - return False - return True - - def check_vat_si(self, vat): - ''' - Check Slovenia VAT number. - ''' - if len(vat) != 8: - return False - try: - int(vat) - except: - return False - if int(vat[0:7]) <= 999999: - return False - - sum = 8 * int(vat[0]) + 7 * int(vat[1]) + 6 * int(vat[2]) + \ - 5 * int(vat[3]) + 4 * int(vat[4]) + 3 * int(vat[5]) + \ - 2 * int(vat[6]) - check = 11 - (sum % 11) - if check == 10: - check = 0 - if check == 11: - check = 1 - if check != int(vat[7]): - return False - return True - - def check_vat_sk(self, vat): - ''' - Check Slovakia VAT number. - ''' - try: - int(vat) - except: - return False - if len(vat) not in(9, 10): - return False - - if int(vat[0:2]) in (0, 10, 20) and len(vat) == 10: - return True - - if len(vat) == 10: - if int(vat[0:2]) < 54 or int(vat[0:2]) > 99: - return False - - if len(vat) == 9: - if int(vat[0:2]) > 53 : - return False - - if int(vat[2:4]) < 1: - return False - if int(vat[2:4]) > 12 and int(vat[2:4]) < 51: - return False - if int(vat[2:4]) > 62: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 > 0: - if int(vat[4:6]) < 1 or int(vat[4:6]) > 28: - return False - if int(vat[2:4]) in (2, 52) and int(vat[0:2]) % 4 == 0: - if int(vat[4:6]) < 1 or int(vat[4:6]) > 29: - return False - if int(vat[2:4]) in (4, 6, 9, 11, 54, 56, 59, 61): - if int(vat[4:6]) < 1 or int(vat[4:6]) > 30: - return False - if int(vat[2:4]) in (1, 3, 5, 7, 8, 10, 12, - 51, 53, 55, 57, 58, 60, 62): - if int(vat[4:6]) < 1 or int(vat[4:6]) > 31: - return False - return True - - def check_vat_mx(self, vat): - ''' - Verificar RFC méxico - ''' - if not 12 <= len(vat) <= 13: - return False - elif len(vat)==12 and not vat[:3].isalpha() | vat[3:9].isdigit() | vat[-3:].isalnum(): - return False - elif len(vat)==13 and not vat[:4].isalpha() | vat[4:10].isdigit() | vat[-3:].isalnum(): - return False - return True + res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From e95c182608bfd40f72bac16e25de937c3824b951 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Wed, 18 May 2011 18:22:34 +0530 Subject: [PATCH 02/55] [FIX]procurement:Fixed:procurement scheduling report=>not Translation properly lp bug: https://launchpad.net/bugs/783135 fixed bzr revid: ron@tinyerp.com-20110518125234-9cea4larl1uub313 --- addons/procurement/schedulers.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index 3a6e3336472..8bc2fef615b 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -100,7 +100,7 @@ class procurement_order(osv.osv): report_total += 1 for proc in procurement_obj.browse(cr, uid, report_ids, context=context): if proc.state == 'exception': - report.append('PROC %d: from stock - %3.2f %-5s - %s' % \ + report.append(_('PROC %d: from stock - %3.2f %-5s - %s') % \ (proc.id, proc.product_qty, proc.product_uom.name, proc.product_id.name,)) report_except += 1 @@ -111,15 +111,15 @@ class procurement_order(osv.osv): end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') if uid: request = self.pool.get('res.request') - summary = '''Here is the procurement scheduling report. - - Start Time: %s - End Time: %s - Total Procurements processed: %d - Procurements with exceptions: %d - Skipped Procurements (scheduled date outside of scheduler range) %d - - Exceptions:\n'''% (start_date, end_date, report_total, report_except, report_later) + summary = _("Here is the procurement scheduling report. \ +\ + Start Time: %s \ + End Time: %s \ + Total Procurements processed: %d \ + Procurements with exceptions: %d \ + Skipped Procurements (scheduled date outside of scheduler range) %d \ +\ + Exceptions:\n") % (start_date, end_date, report_total, report_except, report_later) summary += '\n'.join(report) request.create(cr, uid, {'name': "Procurement Processing Report.", From db63cecdcbf119691fb8ad1767e299087fff6035 Mon Sep 17 00:00:00 2001 From: "mayur maheshwari (Open ERP)" Date: Tue, 24 May 2011 17:34:42 +0530 Subject: [PATCH 03/55] [FIX]stock_planning_:Now edit generated Sales Forecasts in Form View By wizard lp bug: https://launchpad.net/bugs/781655 fixed bzr revid: mma@tinyerp.com-20110524120442-xcvn3e0mslp5mdfo --- addons/stock_planning/wizard/stock_planning_forecast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_planning/wizard/stock_planning_forecast.py b/addons/stock_planning/wizard/stock_planning_forecast.py index 60b3de62243..cee44d7bd6f 100644 --- a/addons/stock_planning/wizard/stock_planning_forecast.py +++ b/addons/stock_planning/wizard/stock_planning_forecast.py @@ -102,7 +102,7 @@ class stock_sale_forecast_createlines(osv.osv_memory): return { 'domain': "[('id','in', ["+','.join(map(str, forecast_lines))+"])]", 'view_type': 'form', - "view_mode": 'tree, form', + "view_mode": 'tree,form', 'res_model': 'stock.sale.forecast', 'type': 'ir.actions.act_window', 'search_view_id': id['res_id'], From 9c1d85e2985de335043217caddf9e9827e73bc12 Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Mon, 30 May 2011 16:36:21 +0530 Subject: [PATCH 04/55] [FIX] method __str__ returns floating point value instead of string in report_sxw.py file lp bug: https://launchpad.net/bugs/723662 fixed bzr revid: ysa@tinyerp.com-20110530110621-2bgxi79fyx6e9y0g --- openerp/report/report_sxw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index f5e65e26766..79f4d32639f 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -86,7 +86,7 @@ class _float_format(float, _format): digits = self._field.digits[1] if hasattr(self, 'lang_obj'): return self.lang_obj.format('%.' + str(digits) + 'f', self.name, True) - return self.val + return str(self.val) class _int_format(int, _format): def __init__(self,value): From a5e9795ed1a574d7948d6da8ad888b3167b1bce0 Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Mon, 30 May 2011 17:13:50 +0530 Subject: [PATCH 05/55] [FIX] __init__ metho store value in string format in float_format class. bzr revid: ysa@tinyerp.com-20110530114350-lp27vh30y45zsmp8 --- openerp/report/report_sxw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 79f4d32639f..1ceb73e18b6 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -78,7 +78,7 @@ class _format(object): class _float_format(float, _format): def __init__(self,value): super(_float_format, self).__init__() - self.val = value + self.val = value and str(value) or str(0.0) def __str__(self): digits = 2 @@ -86,7 +86,7 @@ class _float_format(float, _format): digits = self._field.digits[1] if hasattr(self, 'lang_obj'): return self.lang_obj.format('%.' + str(digits) + 'f', self.name, True) - return str(self.val) + return self.val class _int_format(int, _format): def __init__(self,value): From f16882604442c2e7bc02f326fa2fd623937f0538 Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Mon, 30 May 2011 17:29:41 +0530 Subject: [PATCH 06/55] [IMP] improve code. bzr revid: ysa@tinyerp.com-20110530115941-kur59d11l6d4xq3h --- openerp/report/report_sxw.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 1ceb73e18b6..451e41e7032 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -78,7 +78,7 @@ class _format(object): class _float_format(float, _format): def __init__(self,value): super(_float_format, self).__init__() - self.val = value and str(value) or str(0.0) + self.val = value def __str__(self): digits = 2 @@ -86,17 +86,17 @@ class _float_format(float, _format): digits = self._field.digits[1] if hasattr(self, 'lang_obj'): return self.lang_obj.format('%.' + str(digits) + 'f', self.name, True) - return self.val + return str(self.val) class _int_format(int, _format): def __init__(self,value): super(_int_format, self).__init__() - self.val = value and str(value) or str(0) + self.val = value def __str__(self): if hasattr(self,'lang_obj'): return self.lang_obj.format('%.d', self.name, True) - return self.val + return str(self.val) class _date_format(str, _format): def __init__(self,value): From af3779a9e233270c8909c29344681ac7791f9fbd Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Mon, 30 May 2011 17:36:38 +0530 Subject: [PATCH 07/55] [IMP] improve code. bzr revid: ysa@tinyerp.com-20110530120638-g2m63j8fnrgt1q0t --- openerp/report/report_sxw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 451e41e7032..261c43fb54f 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -78,7 +78,7 @@ class _format(object): class _float_format(float, _format): def __init__(self,value): super(_float_format, self).__init__() - self.val = value + self.val = value or 0.0 def __str__(self): digits = 2 @@ -91,7 +91,7 @@ class _float_format(float, _format): class _int_format(int, _format): def __init__(self,value): super(_int_format, self).__init__() - self.val = value + self.val = value or 0 def __str__(self): if hasattr(self,'lang_obj'): From 331760830f64b9702f0f12edf1c997f646000a07 Mon Sep 17 00:00:00 2001 From: "mayur maheshwari (Open ERP)" Date: Thu, 2 Jun 2011 15:15:33 +0530 Subject: [PATCH 08/55] [FIX]stock_planning_:Now edit Sales planning lines in Form View By wizard lp bug: https://launchpad.net/bugs/781655 fixed bzr revid: mma@tinyerp.com-20110602094533-impg0p3sw69uz33i --- addons/stock_planning/wizard/stock_planning_createlines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_planning/wizard/stock_planning_createlines.py b/addons/stock_planning/wizard/stock_planning_createlines.py index 7abb15b6e7d..d5a9a0ddc74 100644 --- a/addons/stock_planning/wizard/stock_planning_createlines.py +++ b/addons/stock_planning/wizard/stock_planning_createlines.py @@ -133,7 +133,7 @@ class stock_planning_createlines(osv.osv_memory): return { 'domain': "[('id','in', ["+','.join(map(str, planning_lines))+"])]", 'view_type': 'form', - "view_mode": 'tree, form', + "view_mode": 'tree,form', 'res_model': 'stock.planning', 'type': 'ir.actions.act_window', 'search_view_id': id['res_id'], From 48871849770800f1fd7d5fe6686e543951c49e6b Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Thu, 2 Jun 2011 17:34:55 +0530 Subject: [PATCH 09/55] [IMP]procurement:Improvement in Traslation string bzr revid: ron@tinyerp.com-20110602120455-lgadptlti782btgm --- addons/procurement/schedulers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index 8bc2fef615b..0c0372660d9 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -77,7 +77,7 @@ class procurement_order(osv.osv): report_later += 1 for proc in procurement_obj.browse(cr, uid, ids, context=context): if proc.state == 'exception': - report.append('PROC %d: on order - %3.2f %-5s - %s' % \ + report.append(_('PROC %d: on order - %3.2f %-5s - %s') % \ (proc.id, proc.product_qty, proc.product_uom.name, proc.product_id.name)) report_except += 1 From bcb551f338919368265b8f5835f696fce77b22e3 Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Mon, 6 Jun 2011 15:42:33 +0530 Subject: [PATCH 10/55] [IMP]procurement:fixed=>Lines breaks in Traslation string bzr revid: ron@tinyerp.com-20110606101233-o3hi56uin99gdj60 --- addons/procurement/schedulers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index 0c0372660d9..62fcf652b47 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -111,15 +111,15 @@ class procurement_order(osv.osv): end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') if uid: request = self.pool.get('res.request') - summary = _("Here is the procurement scheduling report. \ -\ - Start Time: %s \ - End Time: %s \ - Total Procurements processed: %d \ - Procurements with exceptions: %d \ - Skipped Procurements (scheduled date outside of scheduler range) %d \ -\ - Exceptions:\n") % (start_date, end_date, report_total, report_except, report_later) + summary = _("""Here is the procurement scheduling report. \n\ +\n\ + Start Time: %s \n\ + End Time: %s \n\ + Total Procurements processed: %d \n\ + Procurements with exceptions: %d \n\ + Skipped Procurements (scheduled date outside of scheduler range) %d \n\ +\n\ + Exceptions:\n""") % (start_date, end_date, report_total, report_except, report_later) summary += '\n'.join(report) request.create(cr, uid, {'name': "Procurement Processing Report.", From fecd5e29f41132c8d9df5600ad57c0d0e95d88da Mon Sep 17 00:00:00 2001 From: "ron@tinyerp.com" <> Date: Mon, 6 Jun 2011 16:06:04 +0530 Subject: [PATCH 11/55] [IMP]procurement:improvements in lines breack code bzr revid: ron@tinyerp.com-20110606103604-gh7o9jpm5lfnc3ay --- addons/procurement/schedulers.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/procurement/schedulers.py b/addons/procurement/schedulers.py index 62fcf652b47..d72651ed55a 100644 --- a/addons/procurement/schedulers.py +++ b/addons/procurement/schedulers.py @@ -111,14 +111,14 @@ class procurement_order(osv.osv): end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') if uid: request = self.pool.get('res.request') - summary = _("""Here is the procurement scheduling report. \n\ -\n\ - Start Time: %s \n\ - End Time: %s \n\ - Total Procurements processed: %d \n\ - Procurements with exceptions: %d \n\ - Skipped Procurements (scheduled date outside of scheduler range) %d \n\ -\n\ + summary = _("""Here is the procurement scheduling report. + + Start Time: %s + End Time: %s + Total Procurements processed: %d + Procurements with exceptions: %d + Skipped Procurements (scheduled date outside of scheduler range) %d + Exceptions:\n""") % (start_date, end_date, report_total, report_except, report_later) summary += '\n'.join(report) request.create(cr, uid, From dee5a0dc6e179b5ce319893b0e58524038428ac5 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Thu, 9 Jun 2011 12:01:20 +0530 Subject: [PATCH 12/55] [FIX] chance the rete and rounding of Venezuelan currency exchange bzr revid: nco@tinyerp.com-20110609063120-vw1pqaxyhlaov0yy --- openerp/addons/base/base_data.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/base_data.xml b/openerp/addons/base/base_data.xml index 3f8208b8ec4..5f1feb8f14b 100644 --- a/openerp/addons/base/base_data.xml +++ b/openerp/addons/base/base_data.xml @@ -1088,12 +1088,12 @@ VEB Bs - 2.95 + 0.0001 4 - 2768.45 + 5.864 From 0d6ff068d2ec63126231ba18fcfa2122c54afac2 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Fri, 10 Jun 2011 15:52:03 +0530 Subject: [PATCH 13/55] change in name and symbol of Venezuelan currency lp bug: https://launchpad.net/bugs/715646 fixed bzr revid: nco@tinyerp.com-20110610102203-v1wkla7d226stfas --- openerp/addons/base/base_data.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/base_data.xml b/openerp/addons/base/base_data.xml index 5f1feb8f14b..14b00ec2aa7 100644 --- a/openerp/addons/base/base_data.xml +++ b/openerp/addons/base/base_data.xml @@ -1085,16 +1085,16 @@ - - VEB - Bs + + VEF + Bs.F 0.0001 4 - + 5.864 - + From 694693905a78a63e609b8bbd00db59d49e4ef536 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Fri, 10 Jun 2011 19:06:58 +0530 Subject: [PATCH 14/55] add yml test-case for =like and =ilike operator lp bug: https://launchpad.net/bugs/788106 fixed bzr revid: nco@tinyerp.com-20110610133658-z4avh4z60moecyde --- .../addons/base/test/test_osv_expression.yml | 26 +++++++++++++++++++ openerp/osv/expression.py | 8 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index 4916fe06203..0e88f1ac022 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -111,3 +111,29 @@ res_ids.sort() assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids +- + Check that =like expressions is working without translation field +- + !python {model: res.partner }: | + all_ids = self.search(cr, uid, [('name', '=like', 'Ax')]) + assert len(all_ids) <= 1,"with =like operator without translation field, returns" + +- + Check that =ilike expression is working without translation field +- + !python {model: res.partner }: | + all_ids = self.search(cr, uid, [('name', '=ilike', 'Ax')]) + assert len(all_ids) <= 2,"with =ilike operator without translation field, returns" +- + Check that =like expression is working with translation field +- + !python {model: res.country }: | + all_ids = self.search(cr, uid, [('name', '=like', 'Ind')]) + assert len(all_ids) <= 3,"with =like operator with translation field, returns" + +- + Check that =ilike expression is working with translation field +- + !python {model: res.country }: | + all_ids = self.search(cr, uid, [('name', '=ilike', 'Ind')]) + assert len(all_ids) <= 3,"with =ilike operator with translation field, returns" \ No newline at end of file diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 1922d5e8388..515f1390491 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -353,11 +353,10 @@ class expression(object): self.__exp[i] = tuple(self.__exp[i]) if field.translate: + operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) if operator in ('like', 'ilike', 'not like', 'not ilike'): right = '%%%s%%' % right - - operator = operator == '=like' and 'like' or operator - + query1 = '( SELECT res_id' \ ' FROM ir_translation' \ ' WHERE name = %s' \ @@ -451,8 +450,9 @@ class expression(object): query = '%s.id %s %%s' % (table._table, operator) params = right else: + operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) like = operator in ('like', 'ilike', 'not like', 'not ilike') - + op = {'=like':'like','=ilike':'ilike'}.get(operator,operator) if left in table._columns: format = like and '%s' or table._columns[left]._symbol_set[0] From 6964f67569348755e612ee2285f8f7a1997d0ad0 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Mon, 13 Jun 2011 12:23:06 +0530 Subject: [PATCH 15/55] improve the yml test-case lp bug: https://launchpad.net/bugs/788106 fixed bzr revid: nco@tinyerp.com-20110613065306-g0p5hsw84qa8bvtd --- openerp/addons/base/test/test_osv_expression.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index 0e88f1ac022..fac5454d7bb 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -116,24 +116,25 @@ - !python {model: res.partner }: | all_ids = self.search(cr, uid, [('name', '=like', 'Ax')]) - assert len(all_ids) <= 1,"with =like operator without translation field, returns" + print all_ids,' Len is : ',len(all_ids) + assert len(all_ids) <= 1,"It should have 1 record !" - Check that =ilike expression is working without translation field - !python {model: res.partner }: | all_ids = self.search(cr, uid, [('name', '=ilike', 'Ax')]) - assert len(all_ids) <= 2,"with =ilike operator without translation field, returns" + assert len(all_ids) <= 2,"It should have 2 records !" - Check that =like expression is working with translation field - !python {model: res.country }: | all_ids = self.search(cr, uid, [('name', '=like', 'Ind')]) - assert len(all_ids) <= 3,"with =like operator with translation field, returns" + assert len(all_ids) <= 3,"It should have 3 records !" - Check that =ilike expression is working with translation field - !python {model: res.country }: | all_ids = self.search(cr, uid, [('name', '=ilike', 'Ind')]) - assert len(all_ids) <= 3,"with =ilike operator with translation field, returns" \ No newline at end of file + assert len(all_ids) <= 3,"It should have 3 records !" \ No newline at end of file From e0b1e6724ebe78c4dd79b8b1c1c44e28380f81cd Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Mon, 13 Jun 2011 12:32:18 +0530 Subject: [PATCH 16/55] remove print statement lp bug: https://launchpad.net/bugs/788106 fixed bzr revid: nco@tinyerp.com-20110613070218-3uvgnpefavl95cmv --- openerp/addons/base/test/test_osv_expression.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index fac5454d7bb..3d39521a718 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -116,7 +116,6 @@ - !python {model: res.partner }: | all_ids = self.search(cr, uid, [('name', '=like', 'Ax')]) - print all_ids,' Len is : ',len(all_ids) assert len(all_ids) <= 1,"It should have 1 record !" - From 7779f83e4a1b0745e890e4cb0d5861d77f050a55 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Mon, 13 Jun 2011 18:42:02 +0530 Subject: [PATCH 17/55] Improving error messages when writing invalid values to reference/selection fields lp bug: https://launchpad.net/bugs/777472 fixed bzr revid: nco@tinyerp.com-20110613131202-30bic6891ezlnq2e --- openerp/osv/orm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 52b1dbbd017..6dd01ecbc4f 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -2511,7 +2511,7 @@ class orm(orm_template): pass if not val_id: raise except_orm(_('ValidateError'), - _('Invalid value for reference field "%s" (last part must be a non-zero integer): "%s"') % (field, value)) + _('Invalid value for reference field "%s" of table "%s" (last part must be a non-zero integer): "%s"') % (field, self._table, value)) val = val_model else: val = value @@ -2521,7 +2521,7 @@ class orm(orm_template): elif val in dict(self._columns[field].selection(self, cr, uid, context=context)): return raise except_orm(_('ValidateError'), - _('The value "%s" for the field "%s" is not in the selection') % (value, field)) + _('The value "%s" for the field "%s" of table "%s" is not in the selection') % (value, field, self._table)) def _check_removed_columns(self, cr, log=False): # iterate on the database columns to drop the NOT NULL constraints From 45ca41f9b1c166456cbf7b5f12412fe07ea5811d Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 6 Jul 2011 12:30:52 +0530 Subject: [PATCH 18/55] [IMP] base_vat: Override italian, sweden vat validate method in base_vat bzr revid: psi@tinyerp.co.in-20110706070052-ubky9wywot6rni3n --- addons/base_vat/__init__.py | 3 +- addons/base_vat/__openerp__.py | 5 ++ addons/base_vat/base_vat.py | 135 ++++++++++++++++++++++++++++-- addons/base_vat/base_vat_view.xml | 18 ++-- 4 files changed, 143 insertions(+), 18 deletions(-) diff --git a/addons/base_vat/__init__.py b/addons/base_vat/__init__.py index e1999d38b87..43dbd0c1418 100644 --- a/addons/base_vat/__init__.py +++ b/addons/base_vat/__init__.py @@ -21,5 +21,4 @@ import base_vat -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/base_vat/__openerp__.py b/addons/base_vat/__openerp__.py index 1de5a94fabd..dda64ed584d 100644 --- a/addons/base_vat/__openerp__.py +++ b/addons/base_vat/__openerp__.py @@ -18,6 +18,7 @@ # along with this program. If not, see . # ############################################################################## + { 'name': 'Base VAT', 'version': '1.0', @@ -38,5 +39,9 @@ checking the validity of VAT Number assigned to partners in European countries. 'active': False, 'certificate': '0084849360989', 'images': ['images/1_partner_vat.jpeg'], + 'external_dependencies': { + 'python' : ['vatnumber'], + } } + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 5e2712fc6fb..114620acdce 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -19,10 +19,33 @@ # along with this program. If not, see . # ############################################################################## + import string +import vatnumber +import re +import datetime + from osv import osv, fields +from tools.misc import ustr from tools.translate import _ -import vatnumber #User should install "python-vatnumber" package from the Synaptic Package Manager to check valid VAT NUMBER + +_ref_vat = { + 'be': 'BE0477472701', 'at': 'ATU12345675', + 'bg': 'BG1234567892', 'cy': 'CY12345678F', + 'cz': 'CZ12345679', 'de': 'DE123456788', + 'dk': 'DK12345674', 'ee': 'EE123456780', + 'es': 'ESA12345674', 'fi': 'FI12345671', + 'fr': 'FR32123456789', 'gb': 'GB123456782', + 'gr': 'GR12345670', 'hu': 'HU12345676', + 'ie': 'IE1234567T', 'it': 'IT12345670017', + 'lt': 'LT123456715', 'lu': 'LU12345613', + 'lv': 'LV41234567891', 'mt': 'MT12345634', + 'nl': 'NL123456782B90', 'pl': 'PL1234567883', + 'pt': 'PT123456789', 'ro': 'RO1234567897', + 'se': 'SE123456789701', 'si': 'SI12345679', + 'sk': 'SK0012345675', 'el': 'EL12345670', + 'mx': 'MXABCD831230T1B', +} class res_partner(osv.osv): _inherit = 'res.partner' @@ -36,15 +59,19 @@ class res_partner(osv.osv): Check the VAT number depending of the country. http://sima-pc.com/nif.php ''' + country_obj = self.pool.get('res.country') for partner in self.browse(cr, uid, ids, context=context): if not partner.vat: continue vat_country, vat_number = self._split_vat(partner.vat) - if not hasattr(vatnumber, 'check_vat_' + vat_country): - if vat_country.upper() in vatnumber.countries(): + if not hasattr(self, 'check_vat_' + vat_country) and not hasattr(vatnumber, 'check_vat_' + vat_country): + #We didn't find the validation method for the country code. If that country code can be found in openerp, this means that it is a valid country code + #and we simply didn't have implemented that function. In that case we continue. + if country_obj.search(cr, uid, [('code', 'ilike', vat_country)], context=context): continue + #Otherwise, it means that the country code isn't valid and we return False. return False - check = getattr(vatnumber, 'check_vat_' + vat_country) + check = getattr(self, 'check_vat_' + vat_country, False) or getattr(vatnumber, 'check_vat_' + vat_country, False) if not check(vat_number): return False return True @@ -58,15 +85,109 @@ class res_partner(osv.osv): def _construct_constraint_msg(self, cr, uid, ids, context=None): def default_vat_check(cn, vn): + # by default, a VAT number is valid if: + # 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) if default_vat_check(vat_country, vat_number): - vat_no = vat_country in vatnumber.countries() and vatnumber.countries() or 'Country Code + 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) return _('The VAT is invalid, It should begin with the country code'), () _constraints = [(check_vat, _construct_constraint_msg, ["vat"])] - + + __check_vat_mx_re = re.compile(r"(?P[A-Za-z\xd1\xf1&]{3,4})" \ + r"[ \-_]?" \ + r"(?P[0-9]{2})(?P[01][0-9])(?P[0-3][0-9])" \ + r"[ \-_]?" \ + r"(?P[A-Za-z0-9&\xd1\xf1]{3})$") + + # Mexican VAT verification is not define in vatnumber library, so we need to define it here + def check_vat_mx(self, vat): + ''' Mexican VAT verification + + Verificar RFC México + ''' + # we convert to 8-bit encoding, to help the regex parse only bytes + vat = ustr(vat).encode('iso8859-1') + m = self.__check_vat_mx_re.match(vat) + if not m: + #No valid format + return False + try: + ano = int(m.group('ano')) + if ano > 30: + ano = 1900 + ano + else: + ano = 2000 + ano + datetime.date(ano, int(m.group('mes')), int(m.group('dia'))) + except ValueError: + return False + + #Valid format and valid date + return True + + # Sweden VAT number check fails is some cases from vatnumber library..so override this check method here + def check_vat_se(self, vat): + ''' + Check Sweden VAT number. + ''' + if len(vat) != 12: + return False + try: + int(vat) + except: + return False + #if int(vat[9:11]) <= 0: Fixed in OpenERP + if int(vat[9:11]) < 0: + return False + + sum = vatnumber.mult_add(2, int(vat[0])) + int(vat[1]) + \ + vatnumber.mult_add(2, int(vat[2])) + int(vat[3]) + \ + vatnumber.mult_add(2, int(vat[4])) + int(vat[5]) + \ + vatnumber.mult_add(2, int(vat[6])) + int(vat[7]) + \ + vatnumber.mult_add(2, int(vat[8])) + check = 10 - (sum % 10) + if check == 10: + check = 0 + if check != int(vat[9]): + return False + return True + + # Italy VAT number check fails is some cases from vatnumber library..so override this check method here + def check_vat_it(self, vat): + ''' + Check Italy VAT number. + ''' + if len(vat) != 11: + return False + try: + int(vat) + except: + return False + if int(vat[0:7]) <= 0: + return False + if int(vat[7:10]) <= 0: + return False + if int(vat[7:10]) > 100 and int(vat[7:10]) < 120: + return False +# Fixed in OpenERP +# if int(vat[7:10]) > 121: +# return False + + sum = int(vat[0]) + vatnumber.mult_add(2, int(vat[1])) + int(vat[2]) + \ + vatnumber.mult_add(2, int(vat[3])) + int(vat[4]) + \ + vatnumber.mult_add(2, int(vat[5])) + int(vat[6]) + \ + vatnumber.mult_add(2, int(vat[7])) + int(vat[8]) + \ + vatnumber.mult_add(2, int(vat[9])) + check = 10 - (sum % 10) + if check == 10: + check = 0 + if check != int(vat[10]): + return False + return True + res_partner() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/base_vat/base_vat_view.xml b/addons/base_vat/base_vat_view.xml index 325c2c1ea4c..ab1d02d34ac 100644 --- a/addons/base_vat/base_vat_view.xml +++ b/addons/base_vat/base_vat_view.xml @@ -1,21 +1,21 @@ - + - res.partner.vat.inherit - res.partner - - + res.partner.vat.inherit + res.partner + + - - + + - + - + From a30138475f4f2a5d2f9ccf356ee448c0945f87b0 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 6 Jul 2011 14:44:48 +0530 Subject: [PATCH 19/55] [IMP] base_vat: modification in import and remove external_dependencies bzr revid: psi@tinyerp.co.in-20110706091448-txl7skwpm10vuk3c --- addons/base_vat/__openerp__.py | 3 --- addons/base_vat/base_vat.py | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/addons/base_vat/__openerp__.py b/addons/base_vat/__openerp__.py index dda64ed584d..c538a419241 100644 --- a/addons/base_vat/__openerp__.py +++ b/addons/base_vat/__openerp__.py @@ -39,9 +39,6 @@ checking the validity of VAT Number assigned to partners in European countries. 'active': False, 'certificate': '0084849360989', 'images': ['images/1_partner_vat.jpeg'], - 'external_dependencies': { - 'python' : ['vatnumber'], - } } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 4909afceb2f..e02a4c8d5b9 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -21,16 +21,13 @@ ############################################################################## import string +import datetime import vatnumber import re -import datetime from osv import osv, fields from tools.misc import ustr from tools.translate import _ -from tools.misc import ustr -import re -import datetime _ref_vat = { 'be': 'BE0477472701', 'at': 'ATU12345675', From da6ca2f3fe4309554f037c881eaf8272b4c96590 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 6 Jul 2011 15:06:18 +0530 Subject: [PATCH 20/55] [IMP] base_vat: remove italian vat validation method from base_vat as it is now available in vatnumber library bzr revid: psi@tinyerp.co.in-20110706093618-fugp4zjdd1kueh1f --- addons/base_vat/base_vat.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index e02a4c8d5b9..2bdd5c8e6ea 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -155,39 +155,6 @@ class res_partner(osv.osv): return False return True - # Italy VAT number check fails is some cases from vatnumber library..so override this check method here - def check_vat_it(self, vat): - ''' - Check Italy VAT number. - ''' - if len(vat) != 11: - return False - try: - int(vat) - except: - return False - if int(vat[0:7]) <= 0: - return False - if int(vat[7:10]) <= 0: - return False - if int(vat[7:10]) > 100 and int(vat[7:10]) < 120: - return False -# Fixed in OpenERP -# if int(vat[7:10]) > 121: -# return False - - sum = int(vat[0]) + vatnumber.mult_add(2, int(vat[1])) + int(vat[2]) + \ - vatnumber.mult_add(2, int(vat[3])) + int(vat[4]) + \ - vatnumber.mult_add(2, int(vat[5])) + int(vat[6]) + \ - vatnumber.mult_add(2, int(vat[7])) + int(vat[8]) + \ - vatnumber.mult_add(2, int(vat[9])) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[10]): - return False - return True - res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file From 37f65bc8bf0145881cc5b2bdf8cf87d6d4532931 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 6 Jul 2011 15:21:49 +0530 Subject: [PATCH 21/55] [IMP] include vatnumber in package list as the base_vat module will use this package for vat validation bzr revid: psi@tinyerp.co.in-20110706095149-waba2fbq4imy9825 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 930b266e66b..044a5888c61 100755 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ if os.name == 'nt': "pydot", "asyncore","asynchat", "reportlab", "vobject", "HTMLParser", "select", "mako", "poplib", "imaplib", "smtplib", "email", "yaml", "DAV", - "uuid", "commands", "openerp", + "uuid", "commands", "openerp", "vatnumber" ], "excludes" : ["Tkconstants","Tkinter","tcl"], } @@ -164,6 +164,7 @@ setup(name = name, 'pyyaml', 'pywebdav', 'feedparser', + 'vatnumber', ], extras_require = { 'SSL' : ['pyopenssl'], From cc758b3c78424f15ced79a448d0f449b1920a083 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Mon, 18 Jul 2011 15:14:51 +0530 Subject: [PATCH 22/55] [IMP] base_vat: remove sweden vat validation method from base_vat as it is now improved in vatnumber library bzr revid: psi@tinyerp.co.in-20110718094451-xuzeenufge64j7p4 --- addons/base_vat/base_vat.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 2bdd5c8e6ea..9f40f656d4e 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -128,33 +128,6 @@ class res_partner(osv.osv): #Valid format and valid date return True - # Sweden VAT number check fails is some cases from vatnumber library..so override this check method here - def check_vat_se(self, vat): - ''' - Check Sweden VAT number. - ''' - if len(vat) != 12: - return False - try: - int(vat) - except: - return False - #if int(vat[9:11]) <= 0: Fixed in OpenERP - if int(vat[9:11]) < 0: - return False - - sum = vatnumber.mult_add(2, int(vat[0])) + int(vat[1]) + \ - vatnumber.mult_add(2, int(vat[2])) + int(vat[3]) + \ - vatnumber.mult_add(2, int(vat[4])) + int(vat[5]) + \ - vatnumber.mult_add(2, int(vat[6])) + int(vat[7]) + \ - vatnumber.mult_add(2, int(vat[8])) - check = 10 - (sum % 10) - if check == 10: - check = 0 - if check != int(vat[9]): - return False - return True - res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file From 62ba542130f9152dae21319c31624d941cf187dc Mon Sep 17 00:00:00 2001 From: Viktor Nagy Date: Fri, 22 Jul 2011 08:27:48 +0200 Subject: [PATCH 23/55] fixed repeatIn with specified tag bug lp bug: https://launchpad.net/bugs/592584 fixed bzr revid: viktor.nagy@toolpart.hu-20110722062748-pz8bp77myr4j3ge0 --- openerp/report/preprocess.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openerp/report/preprocess.py b/openerp/report/preprocess.py index c84ce66b472..78703cb1e78 100644 --- a/openerp/report/preprocess.py +++ b/openerp/report/preprocess.py @@ -66,10 +66,12 @@ class report(object): match = html_parents if txt.group(3): match = [txt.group(3)] - n = node - while n.tag not in match: - n = n.getparent() - n.set('rml_loop', txt.group(2)) + if match[0].startswith("'"): + match[0] = match[0][1:-1] + n2= node + while n2.tag not in match: + n2 = n2.getparent() + n2.set('rml_loop', txt.group(2)) return '[['+txt.group(1)+"''"+txt.group(4)+']]' t = _regex1.sub(_sub1, node.text or node.tail) if t == " ": From f25e0e9f485bf678dfc0e51a2d8ecfd702859ad2 Mon Sep 17 00:00:00 2001 From: Viktor Nagy Date: Fri, 22 Jul 2011 08:47:49 +0200 Subject: [PATCH 24/55] Added documentation to workflow_service methods. bzr revid: viktor.nagy@toolpart.hu-20110722064749-ovx9biphwz50tizd --- openerp/workflow/wkf_service.py | 66 +++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/openerp/workflow/wkf_service.py b/openerp/workflow/wkf_service.py index 6f5059e6817..eeccb4b7e77 100644 --- a/openerp/workflow/wkf_service.py +++ b/openerp/workflow/wkf_service.py @@ -27,6 +27,16 @@ import openerp.netsvc as netsvc import openerp.pooler as pooler class workflow_service(netsvc.Service): + """ + Sometimes you might want to fire a signal or re-evaluate the current state + of a workflow using the service's API. You can access the workflow services + using: + + >>> import netsvc + >>> wf_service = netsvc.LocalService("workflow") + + Then you can use the following methods. + """ def __init__(self, name='workflow', audience='*'): netsvc.Service.__init__(self, name, audience) self.exportMethod(self.trg_write) @@ -42,12 +52,31 @@ class workflow_service(netsvc.Service): self.wkf_on_create_cache[cr.dbname]={} def trg_write(self, uid, res_type, res_id, cr): + """ + Reevaluates the specified workflow instance. Thus if any condition for + a transition have been changed in the backend, then running ``trg_write`` + will move the workflow over that transition. + + :param res_type: the model name + :param res_id: the model instance id the workflow belongs to + :param cr: a database cursor + """ ident = (uid,res_type,res_id) cr.execute('select id from wkf_instance where res_id=%s and res_type=%s and state=%s', (res_id or None,res_type or None, 'active')) for (id,) in cr.fetchall(): instance.update(cr, id, ident) def trg_trigger(self, uid, res_type, res_id, cr): + """ + Activate a trigger. + + If a workflow instance is waiting for a trigger from another model, then this + trigger can be activated if its conditions are met. + + :param res_type: the model name + :param res_id: the model instance id the workflow belongs to + :param cr: a database cursor + """ cr.execute('select instance_id from wkf_triggers where res_id=%s and model=%s', (res_id,res_type)) res = cr.fetchall() for (instance_id,) in res: @@ -56,10 +85,24 @@ class workflow_service(netsvc.Service): instance.update(cr, instance_id, ident) def trg_delete(self, uid, res_type, res_id, cr): + """ + Delete a workflow instance + + :param res_type: the model name + :param res_id: the model instance id the workflow belongs to + :param cr: a database cursor + """ ident = (uid,res_type,res_id) instance.delete(cr, ident) def trg_create(self, uid, res_type, res_id, cr): + """ + Create a new workflow instance + + :param res_type: the model name + :param res_id: the model instance id to own the created worfklow instance + :param cr: a database cursor + """ ident = (uid,res_type,res_id) self.wkf_on_create_cache.setdefault(cr.dbname, {}) if res_type in self.wkf_on_create_cache[cr.dbname]: @@ -72,6 +115,14 @@ class workflow_service(netsvc.Service): instance.create(cr, ident, wkf_id) def trg_validate(self, uid, res_type, res_id, signal, cr): + """ + Fire a signal on a given workflow instance + + :param res_type: the model name + :param res_id: the model instance id the workflow belongs to + :signal: the signal name to be fired + :param cr: a database cursor + """ result = False ident = (uid,res_type,res_id) # ids of all active workflow instances for a corresponding resource (id, model_nam) @@ -81,10 +132,19 @@ class workflow_service(netsvc.Service): result = result or res2 return result - # make all workitems which are waiting for a (subflow) workflow instance - # for the old resource point to the (first active) workflow instance for - # the new resource def trg_redirect(self, uid, res_type, res_id, new_rid, cr): + """ + Re-bind a workflow instance to another instance of the same model. + + Make all workitems which are waiting for a (subflow) workflow instance + for the old resource point to the (first active) workflow instance for + the new resource. + + :param res_type: the model name + :param res_id: the model instance id the workflow belongs to + :param new_rid: the model instance id to own the worfklow instance + :param cr: a database cursor + """ # get ids of wkf instances for the old resource (res_id) #CHECKME: shouldn't we get only active instances? cr.execute('select id, wkf_id from wkf_instance where res_id=%s and res_type=%s', (res_id, res_type)) From 432931dda597f72261f2d68c9252b41f3d50791d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 24 Aug 2011 23:19:43 +0200 Subject: [PATCH 25/55] Add active field on account.fiscal.position. Fixes LP bug #768847 lp bug: https://launchpad.net/bugs/768847 fixed bzr revid: alexis@via.ecp.fr-20110824211943-kcfp6133556zropc --- addons/account/partner.py | 5 +++++ addons/account/partner_view.xml | 1 + 2 files changed, 6 insertions(+) diff --git a/addons/account/partner.py b/addons/account/partner.py index 6ff3879889c..36fd88183f2 100644 --- a/addons/account/partner.py +++ b/addons/account/partner.py @@ -28,12 +28,17 @@ class account_fiscal_position(osv.osv): _description = 'Fiscal Position' _columns = { 'name': fields.char('Fiscal Position', size=64, required=True), + 'active': fields.boolean('Active', help="By unchecking the active field, you may hide a fiscal position without deleting it."), 'company_id': fields.many2one('res.company', 'Company'), 'account_ids': fields.one2many('account.fiscal.position.account', 'position_id', 'Account Mapping'), 'tax_ids': fields.one2many('account.fiscal.position.tax', 'position_id', 'Tax Mapping'), 'note': fields.text('Notes', translate=True), } + _defaults = { + 'active': True, + } + def map_tax(self, cr, uid, fposition_id, taxes, context=None): if not taxes: return [] diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml index fbee97875ae..6051e2bc943 100644 --- a/addons/account/partner_view.xml +++ b/addons/account/partner_view.xml @@ -9,6 +9,7 @@
+ From d518bdce72c8f3136dea3635db03112c44e39c8c Mon Sep 17 00:00:00 2001 From: openerp user Date: Tue, 13 Sep 2011 11:55:22 +0200 Subject: [PATCH 26/55] Adding vat check for country of Croatia bzr revid: openerp@openerp6desktop-20110913095522-b7ry940z7fnysvlb --- addons/base_vat/base_vat.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index 6393c0a6182..835a23e7e27 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -42,7 +42,7 @@ _ref_vat = { 'pt': 'PT123456789', 'ro': 'RO1234567897', 'se': 'SE123456789701', 'si': 'SI12345679', 'sk': 'SK0012345675', 'el': 'EL12345670', - 'mx': 'MXABCD831230T1B', + 'mx': 'MXABCD831230T1B', 'hr': 'HR01234567896' } @@ -1104,7 +1104,28 @@ class res_partner(osv.osv): #Valid format and valid date return True - + + def check_vat_hr(self, vat): + ''' + Check Croatia VAT number. + ''' + if not vat: + return True + + if len(vat) != 11: + return False + try: + int(vat) + except ValueError: + return False + t = 10 + for i in vat[:-1]: + c = int(i) + t = (2 * ((t + c) % 10 or 10)) % 11 + check = (11 - t) % 10 + if check != int(vat[10]): + return False + return True res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From c0936ac657d3e8d41c3b9e7be917a3ef3075cb8f Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 15 Sep 2011 22:22:09 +0200 Subject: [PATCH 27/55] [IMP] Get rid of jQuery accordion. Improved menu (WIP). Now all levels are working bzr revid: fme@openerp.com-20110915202209-5rp3ltzz86msaajz --- addons/web/static/src/css/base.css | 76 +++++++----------------------- addons/web/static/src/js/chrome.js | 25 ++++------ addons/web/static/src/xml/base.xml | 48 ++++++++----------- 3 files changed, 45 insertions(+), 104 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 4645c55f692..9200cfc3383 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -221,17 +221,11 @@ label.error { height: 100%; background: #f0eeee; } +.openerp .oe-application-container { + height: 100%; +} /* Menu */ -.openerp .sf-menu { - margin-bottom: 0; -} -/* -.sf-menu a { - padding: 5px 5px; -} -*/ - .openerp .menu { height: 34px; background: #cc4e45; /* Old browsers */ @@ -291,12 +285,8 @@ label.error { background: linear-gradient(top, #c6c6c6 0%,#5c5c5c 7%,#969595 86%); /* W3C */ /* for ie */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5c5c5c', endColorstr='#969595',GradientType=0 ); /* IE6-9 */ - color: #fff; } -.openerp .oe-application-container { - height: 100%; -} /* Secondary Menu */ .openerp .secondary_menu { width: 200px; @@ -307,14 +297,16 @@ label.error { vertical-align: top; height: 100%; } -.openerp .secondary_menu .menu_content { - padding: 0; - border: none; - background: none; - overflow: hidden; +.openerp .secondary_menu a { + display: block; + padding: 0 5px 2px 5px; + line-height: 20px; + text-decoration: none; + white-space: nowrap; + color: white; + text-shadow: 0 1px 0 #333; } -.openerp .secondary_menu h3 { - padding: 0 0 2px; +.openerp .secondary_menu a.oe_secondary_menu_item { background: #949292; /* Old browsers */ background: -moz-linear-gradient(top, #949292 0%, #6d6b6b 87%, #282828 99%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#949292), color-stop(87%,#6d6b6b), color-stop(99%,#282828)); /* Chrome,Safari4+ */ @@ -325,34 +317,13 @@ label.error { background: linear-gradient(top, #949292 0%,#6d6b6b 87%,#282828 99%); /* W3C */ /* for ie9 */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#949292', endColorstr='#5B5A5A',GradientType=0 ); /* IE6-9 */ - border: none; - /* overriding jquery ui */ - -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; -} -.openerp .secondary_menu h4 { - padding: 0 0 2px 10px; - border: none; - background: none; -} -.openerp .secondary_menu h3 span, .openerp .secondary_menu h4 span { - left: 0 !important; -} -.openerp .secondary_menu a { - display: block; - height: 20px; - padding: 0 5px; - line-height: 20px; white-space: nowrap; color: white; - text-decoration: none; text-shadow: 0 1px 0 #333; } -.openerp .secondary_menu a.leaf:hover, -.openerp .secondary_menu a.leaf:active, -.openerp .secondary_menu a.leaf.active, -.openerp .secondary_menu h4:hover, -.openerp .secondary_menu h4:active, -.openerp .secondary_menu h4.active { +.openerp a.oe_secondary_submenu_item:hover, +.openerp a.oe_secondary_submenu_item.leaf.active { + display: block; background: #ffffff; /* Old browsers */ background: -moz-linear-gradient(top, #ffffff 0%, #d8d8d8 11%, #afafaf 86%, #333333 91%, #5a5858 96%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(11%,#d8d8d8), color-stop(86%,#afafaf), color-stop(91%,#333333), color-stop(96%,#5a5858)); /* Chrome,Safari4+ */ @@ -361,22 +332,11 @@ label.error { background: -ms-linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,#5a5858 96%); /* IE10+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#FFFFFF', endColorstr='#5A5858',GradientType=0 ); /* IE6-9 */ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,#5a5858 96%); /* W3C */ - /* overriding jquery ui */ - -moz-border-radius-topright: 0; -webkit-border-top-right-radius: 0; border-top-right-radius: 0; + padding: 0 5px 2px 5px; + line-height: 20px; color: #3f3d3d; + text-decoration: none; text-shadow: #fff 0 1px 0; - border: none !important; -} - -.openerp .secondary_menu h4:hover a, -.openerp .secondary_menu h4:active a, -.openerp .secondary_menu h4.active a { - color: #3f3d3d; - text-shadow: #fff 0 1px 0; - border: none !important; -} -.openerp div.submenu_accordion div.menu_content a span { - padding-left: 20px; } /* Header */ diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index d114f485c62..0d671b25d53 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -787,18 +787,6 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ var v = { menu : this.data.data.children[i] }; this.$secondary_menu.append(QWeb.render("Menu.secondary", v)); } - this.$secondary_menu.find("div.menu_accordion").accordion({ - animated : false, - autoHeight : false, - icons : false - }); - this.$secondary_menu.find("div.submenu_accordion").accordion({ - animated : false, - autoHeight : false, - active: false, - collapsible: true, - header: 'h4' - }); this.$element.add(this.$secondary_menu).find("a").click(this.on_menu_click); }, @@ -817,15 +805,14 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ id = $menu.data('menu'); } if (this.$secondary_menu.has($menu).length) { - $secondary = $menu.parents('.menu_accordion'); + $secondary = $menu.parents('.oe_secondary_menu'); $parent = this.$element.find('a[data-menu=' + $secondary.data('menu-parent') + ']'); } else { $parent = $menu; - $secondary = this.$secondary_menu.find('.menu_accordion[data-menu-parent=' + $menu.attr('data-menu') + ']'); + $secondary = this.$secondary_menu.find('.oe_secondary_menu[data-menu-parent=' + $menu.attr('data-menu') + ']'); } - this.$secondary_menu.find('.menu_accordion').hide(); - // TODO: ui-accordion : collapse submenus and expand the good one + this.$secondary_menu.find('.oe_secondary_menu').hide(); $secondary.show(); if (id) { @@ -837,11 +824,15 @@ openerp.web.Menu = openerp.web.Widget.extend(/** @lends openerp.web.Menu# */{ $('.active', this.$element.add(this.$secondary_menu.show())).removeClass('active'); $parent.addClass('active'); $menu.addClass('active'); - $menu.parent('h4').addClass('active'); if (this.$secondary_menu.has($menu).length) { + if ($menu.is('.submenu')) { + $menu.next().toggle(); + return false; + } return !$menu.is(".leaf"); } else { + $secondary.find('.oe_secondary_submenu').hide().eq(0).show(); return false; } }, diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 83ca819b4e6..95e2a7e5770 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -374,45 +374,35 @@ - - - - - + + +
- - - -
+ + + +
-