From bf339aba8e25c0a7f59c0cb10477eb4036eb50fc Mon Sep 17 00:00:00 2001 From: "nel@tinyerp.com" <> Date: Sun, 11 Apr 2010 21:31:52 +0200 Subject: [PATCH] [FIX] l10n_be: compliancy of belgian vat declaration with Intervat 5.1.0 (from 05 feb 2010) bzr revid: nel@tinyerp.com-20100411193152-twcdvdgkpe321dir --- addons/l10n_be/account_pcmn_belgium.xml | 28 +++- .../wizard/l10_be_partner_vat_listing.py | 14 +- .../wizard/l10n_be_account_vat_declaration.py | 10 +- addons/l10n_be/wizard/l10n_be_vat_intra.py | 126 +++++------------- .../l10n_be/wizard/l10n_be_vat_intra_view.xml | 9 +- 5 files changed, 79 insertions(+), 108 deletions(-) diff --git a/addons/l10n_be/account_pcmn_belgium.xml b/addons/l10n_be/account_pcmn_belgium.xml index b2d5a405ee8..e11815a7234 100644 --- a/addons/l10n_be/account_pcmn_belgium.xml +++ b/addons/l10n_be/account_pcmn_belgium.xml @@ -6466,9 +6466,20 @@ 44 - Services intra-communautaires + Services intra-communautaires et ABC + + 44a + Services intra-communautaires + + + + 44b + ABC intra-communautaires + + + 45 Operations avec TVA due par le cocontractant @@ -7053,14 +7064,25 @@ - TVA 0% Intracommunautaire (Services et ABC) + TVA 0% Services Intracommunautaires V-INTRA-S 0 percent - + sale + + + TVA 0% ABC Intracommunautaire + V-INTRA-ABC 0 + + percent + + + sale + + diff --git a/addons/l10n_be/wizard/l10_be_partner_vat_listing.py b/addons/l10n_be/wizard/l10_be_partner_vat_listing.py index 049a625830b..118e0ee3d26 100644 --- a/addons/l10n_be/wizard/l10_be_partner_vat_listing.py +++ b/addons/l10n_be/wizard/l10_be_partner_vat_listing.py @@ -37,6 +37,18 @@ class vat_listing_clients(osv.osv_memory): 'amount': fields.float('Amount'), 'turnover': fields.float('Turnover'), } + def name_get(self, cr, uid, ids, context={}): + if not len(ids): + return [] + return [(r['id'], r['name'] + ' - ' + r['vat']) \ + for r in self.read(cr, uid, ids, ['name', 'vat'], + context, load='_classic_write')] + + def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100): + client = self.search(cr, uid, [('vat', '=', name)]+args, limit=limit, context=context) + if not client: + client = self.search(cr, uid, [('name', 'ilike', '%%%s%%' % name)]+args, limit=limit, context=context) + return self.name_get(cr, uid, client, context=context) vat_listing_clients() @@ -225,4 +237,4 @@ class partner_vat_list(osv.osv_memory): partner_vat_list() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py b/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py index a82175a59ee..be261bd1366 100644 --- a/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py +++ b/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py @@ -56,7 +56,9 @@ class l10n_be_vat_declaration(osv.osv_memory): user_cmpny = obj_company.name vat_no=obj_company.partner_id.vat if not vat_no: - raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!')) +# raise wizard.except_wizard(_('Data Insufficient'),_('No VAT Number Associated with Main Company!')) + osv.except_osv(_('Data Insufficient'), _('No VAT Number Associated with Main Company!')) + tax_code_ids = obj_tax_code.search(cr, uid, [], context=context) ctx = context.copy() @@ -65,7 +67,7 @@ class l10n_be_vat_declaration(osv.osv_memory): tax_info = obj_tax_code.read(cr, uid, tax_code_ids, ['code','sum_period'], context=ctx) address = post_code = city = country_code = '' - city, post_code, address, country_code = pooler.get_pool(cr.dbname).get('res.company')._get_default_ad(obj_company.partner_id.address) + city, post_code, address, country_code =self.pool.get('res.company')._get_default_ad(obj_company.partner_id.address) year_id = obj_fyear.find(cr, uid) @@ -77,7 +79,7 @@ class l10n_be_vat_declaration(osv.osv_memory): data_of_file='\n' data_of_file +='\n\t\n\t\t'+str(vat_no)+'\n\t\t'+str(obj_company.name)+'\n\t\t
'+address+'
' data_of_file +='\n\t\t'+post_code+'\n\t\t'+city+'\n\t\t'+country_code+'\n\t\t'+send_ref+'\n\t
' - data_of_file +='\n\t\n\t\t1\n\t\t'+str(vat_no[2:])+'\n\t\t\n\t\t\t' + data_of_file +='\n\t\n\t\t1\n\t\t'+((vat_no and str(vat_no[2:])) or '')+'\n\t\t\n\t\t\t' starting_month = account_period.date_start[5:7] ending_month = account_period.date_stop[5:7] @@ -89,7 +91,7 @@ class l10n_be_vat_declaration(osv.osv_memory): else: data_of_file += ''+starting_month+'\n\t\t\t' data_of_file += '' + str(account_period.date_stop[:4]) + '\n\t\t\n\t\t' - data_of_file += '\n\t\t'+ (data['form']['client_nihil'] and 'YES' or 'NO') +'' + data_of_file += '\n\t\t'+ (data['client_nihil'] and 'YES' or 'NO') +'' data_of_file +='\n\t\t\n\t\t\t' for item in tax_info: diff --git a/addons/l10n_be/wizard/l10n_be_vat_intra.py b/addons/l10n_be/wizard/l10n_be_vat_intra.py index d7869a7c197..bb74665480d 100644 --- a/addons/l10n_be/wizard/l10n_be_vat_intra.py +++ b/addons/l10n_be/wizard/l10n_be_vat_intra.py @@ -20,6 +20,7 @@ ############################################################################## import time import base64 +from tools.translate import _ from osv import osv, fields @@ -34,14 +35,18 @@ class partner_vat_intra(osv.osv_memory): return obj_country.search(cursor, user, [('code', 'in', ['AT', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB'])]) _columns = { - 'trimester': fields.selection( [('1','Jan/Feb/Mar'), - ('2','Apr/May/Jun'), - ('3','Jul/Aug/Sep'), - ('4','Oct/Nov/Dec')], - 'Trimester Number', required=True, help="It will be the first digit of period"), + 'period_code': fields.char('Period Code',size = 6,required = True, help = '''This is where you have to set the period code for the intracom declaration using the format: ppyyyy + PP can stand for a month: from '01' to '12'. + PP can stand for a trimester: '31','32','33','34' + The first figure means that it is a trimester, + The second figure identify the trimester. + PP can stand for a complete fiscal year: '00'. + YYYY stands for the year (4 positions). + ''' + ), + 'period_ids': fields.many2many('account.period', 'account_period_rel', 'acc_id', 'period_id', 'Period (s)', help = 'Select here the period(s) you want to include in your intracom declaration'), 'test_xml': fields.boolean('Test XML file', help="Sets the XML output as test file"), 'mand_id' : fields.char('MandataireId', size=14, required=True, help="This identifies the representative of the sending company. This is a string of 14 characters"), - 'fyear': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True), 'msg': fields.text('File created', size=64, readonly=True), 'file_save' : fields.binary('Save File', readonly=True), 'country_ids': fields.many2many('res.country', 'vat_country_rel', 'vat_id', 'country_id', 'European Countries'), @@ -60,19 +65,16 @@ class partner_vat_intra(osv.osv_memory): data_cmpny = obj_user.browse(cursor, user, user).company_id data = self.read(cursor, user, ids)[0] - data_fiscal = obj_fyear.browse(cursor, user, data['fyear'], context=context) - company_vat = data_cmpny.partner_id.vat if not company_vat: raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!')) seq_controlref = obj_sequence.get(cursor, user, 'controlref') seq_declarantnum = obj_sequence.get(cursor, user, 'declarantnum') - cref = company_vat + seq_controlref - dnum = cref + seq_declarantnum - if len(data_fiscal.date_start.split('-')[0]) < 4: - raise osv.except_osv(_('Data Insufficient'),_('Trimester year should be length of 4 digits!')) - period_trimester = data['trimester'] + data_fiscal.date_start.split('-')[0] + cref = company_vat[2:] + seq_controlref[-4:] + dnum = cref + seq_declarantnum[-5:] + if len(data['form']['period_code']) != 6: + raise wizard.except_wizard(_('Wrong Period Code'), _('The period code you entered is not valid.')) street = zip_city = country = '' addr = obj_partner.address_get(cursor, user, [data_cmpny.partner_id.id], ['invoice']) @@ -92,15 +94,11 @@ class partner_vat_intra(osv.osv_memory): sender_date = time.strftime('%Y-%m-%d') data_file = '\n\n\t\t\t'+str(data_cmpny.name)+'\n\t\t\t'+ str(street) +'\n\t\t\t'+ str(zip_city) +'' data_file +='\n\t\t\t' + str(country) +'\n\t\t\n\t' - - data_comp ='\n\t\t\n\t\t\t'+str(company_vat)+'\n\t\t\t'+str(data_cmpny.name)+'\n\t\t\t'+ str(street) +'\n\t\t\t'+ str(zip_city) +'\n\t\t\t'+ str(country) +'\n\t\t' - data_period = '\n\t\t'+ str(period_trimester) +'' #trimester - + data_comp ='\n\t\t\n\t\t\t'+str(company_vat[2:])+'\n\t\t\t'+str(data_cmpny.name)+'\n\t\t\t'+ str(street) +'\n\t\t\t'+ str(zip_city) +'\n\t\t\t'+ str(country) +'\n\t\t' + data_period = '\n\t\t'+ data['period_code'] +'' #trimester error_message = [] seq = 0 amount_sum = 0 @@ -110,85 +108,23 @@ class partner_vat_intra(osv.osv_memory): nb_period = len(data_fiscal.period_ids) fiscal_periods = data_fiscal.period_ids - - if data['trimester'] == '1': - if nb_period == 12: - start_date = fiscal_periods[0].date_start - end_date = fiscal_periods[2].date_stop - elif nb_period == 4: - start_date = fiscal_periods[0].date_start - end_date = fiscal_periods[0].date_stop - elif data['trimester'] == '2': - if nb_period == 12: - start_date = fiscal_periods[3].date_start - end_date = fiscal_periods[5].date_stop - elif nb_period == 4: - start_date = fiscal_periods[1].date_start - end_date = fiscal_periods[1].date_stop - elif data['trimester'] == '3': - if nb_period == 12: - start_date = fiscal_periods[6].date_start - end_date = fiscal_periods[8].date_stop - elif nb_period == 4: - start_date = fiscal_periods[2].date_start - end_date = fiscal_periods[2].date_stop - elif data['trimester'] == '4': - if nb_period == 12: - start_date = fiscal_periods[9].date_start - end_date = fiscal_periods[11].date_stop - elif nb_period == 4: - start_date = fiscal_periods[3].date_start - end_date = fiscal_periods[3].date_stop - - period = "to_date('" + str(start_date) + "','yyyy-mm-dd') and to_date('" + str(end_date) +"','yyyy-mm-dd')" - record = {} - - for p_id in p_id_list: - list_partner = [] - partner = obj_partner.browse(cursor, user, p_id, context=context) - go_ahead = False - country_code = '' - for ads in partner.address: - if ads.type == 'default' and (ads.country_id and ads.country_id.id in data['country_ids']): - go_ahead = True - country_code = ads.country_id.code - break - if not go_ahead: - continue - - cursor.execute('select sum(debit)-sum(credit) as amount from account_move_line l left join account_account a on (l.account_id=a.id) where a.type in ('"'receivable'"') and l.partner_id=%%s and l.date between %s' % (period,), (p_id,)) - res = cursor.dictfetchall() - list_partner.append(res[0]['amount']) - list_partner.append('T') #partner.ref ...should be check - list_partner.append(partner.vat) - list_partner.append(country_code) - #...deprecated... -# addr = pool.get('res.partner').address_get(cr, uid, [partner.id], ['invoice']) -# if addr.get('invoice',False): -# ads = pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0] -# -# if ads.country_id: -# code_country = ads.country_id.code -# list_partner.append(code_country) -# else: -# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no country associated with its Invoice address!') -# if len(list_partner)<4: -# list_partner.append('') -# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no Invoice address!') -# list_partner.append(code_country or 'not avail') - record[p_id] = list_partner - - if len(error_message): - data['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message) - return data['msg'] + list_partner = [] data_clientinfo = '' + cr.execute('''SELECT l.partner_id AS partner_id, p.vat AS vat, t.code AS intra_code, SUM(l.tax_amount) AS amount + FROM account_move_line l + LEFT JOIN account_tax_code t ON (l.tax_code_id = t.id) + LEFT JOIN res_partner p ON (l.partner_id = p.id) + WHERE t.code IN ('44a','44b','88') + AND l.period_id IN %s + GROUP BY l.partner_id, p.vat, t.code''', (tuple(data['form']['period_ids'][0][2]), )) + for row in cr.dictfetchall(): - for r in record: seq += 1 - amt = record[r][0] or 0 + amt = row['amount'] or 0 amt = int(amt * 100) amount_sum += amt - data_clientinfo +='\n\t\t\n\t\t\t\n\t\t\t\t'+record[r][2] +'\n\t\t\t\t'+record[r][3] +'\n\t\t\t\n\t\t\t'+str(amt) +'\n\t\t\t'+str(period_trimester) +'\n\t\t\t'+str(record[r][1]) +'\n\t\t' + intra_code = row['intra_code'] == '88' and 'L' or (row['intra_code'] == '44b' and 'T' or (row['intra_code'] == '44a' and 'S' or '')) + data_clientinfo +='\n\t\t\n\t\t\t\n\t\t\t\t'+row['vat'][2:] +'\n\t\t\t\t'+row['vat'][:2] +'\n\t\t\t\n\t\t\t'+str(amt) +'\n\t\t\t'+str(intra_code) +'\n\t\t' amount_sum = int(amount_sum) data_decl = '\n\t' data_file += str(data_decl) + str(data_comp) + str(data_period) + str(data_clientinfo) + '\n\t\n' @@ -199,4 +135,4 @@ class partner_vat_intra(osv.osv_memory): partner_vat_intra() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/l10n_be/wizard/l10n_be_vat_intra_view.xml b/addons/l10n_be/wizard/l10n_be_vat_intra_view.xml index 8e5025c058e..f67123aed0c 100644 --- a/addons/l10n_be/wizard/l10n_be_vat_intra_view.xml +++ b/addons/l10n_be/wizard/l10n_be_vat_intra_view.xml @@ -18,12 +18,11 @@