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 dcb9b01afe0..9a0c49abdf4 100644 --- a/addons/l10n_be/wizard/l10_be_partner_vat_listing.py +++ b/addons/l10n_be/wizard/l10_be_partner_vat_listing.py @@ -22,6 +22,8 @@ import time import base64 from tools.translate import _ +import tools +from decimal import Decimal from osv import fields, osv class vat_listing_clients(osv.osv_memory): @@ -58,8 +60,8 @@ class partner_vat(osv.osv_memory): obj_vat_lclient = self.pool.get('vat.listing.clients') obj_model_data = self.pool.get('ir.model.data') data = self.read(cursor, user, ids)[0] - period = obj_period.search(cursor, user, [('fiscalyear_id', '=', data['fyear'])], context=context) - p_id_list = obj_partner.search(cursor, user, [('vat_subjected', '!=', False)], context=context) + period = obj_period.search(cursor, user, [('fiscalyear_id', '=', data['fyear'][0])], context=context) + p_id_list = obj_partner.search(cursor, user, [('vat_subjected', '!=', False),('customer','=',True)], context=context) if not p_id_list: raise osv.except_osv(_('Data Insufficient!'), _('No partner has a VAT Number asociated with him.')) partners = [] @@ -72,12 +74,12 @@ class partner_vat(osv.osv_memory): #(or one of their) default address(es) located in Belgium. go_ahead = False for ads in obj_partner.address: - if ads.type == 'default' and (ads.country_id and ads.country_id.code == 'BE'): + if ads.type == 'default' and (ads.country_id and ads.country_id.code == 'BE') and (obj_partner.vat or '').startswith('BE'): go_ahead = True break if not go_ahead: continue - cursor.execute('select b.code, sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code IN %s and l.partner_id=%s and l.period_id IN %s group by b.code',(('produit','tax'),obj_partner.id,tuple(period),)) + cursor.execute('select b.code, sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code IN %s and l.partner_id=%s and l.period_id IN %s group by b.code',(('produit', 'tax', 'income'),obj_partner.id,tuple(period),)) line_info = cursor.fetchall() if not line_info: continue @@ -87,14 +89,14 @@ class partner_vat(osv.osv_memory): #it seems that this listing is only for belgian customers record['country'] = 'BE' - record['amount'] = 0 - record['turnover'] = 0 + record['amount'] = Decimal(str(0.0)) + record['turnover'] = Decimal(str(0.0)) record['name'] = obj_partner.name for item in line_info: - if item[0] == 'produit': - record['turnover'] += item[1] + if item[0] in ('produit','income'): + record['turnover'] += Decimal(str(item[1])) else: - record['amount'] += item[1] + record['amount'] += Decimal(str(item[1])) id_client = obj_vat_lclient.create(cursor, user, record, context=context) partners.append(id_client) records.append(record) @@ -155,8 +157,8 @@ class partner_vat_list(osv.osv_memory): raise osv.except_osv(_('Data Insufficient'),_('No VAT Number Associated with Main Company!')) cref = company_vat + seq_controlref - dnum = cref + seq_declarantnum - obj_year= obj_fyear.browse(cursor, user, context['fyear'], context=context) + dnum = cref[2:] + (seq_declarantnum or '') + obj_year= obj_fyear.browse(cursor, user, context['fyear'][0], context=context) street = zip_city = country = '' addr = obj_partner.address_get(cursor, user, [obj_cmpny.partner_id.id], ['invoice']) if addr.get('invoice',False): @@ -173,16 +175,16 @@ class partner_vat_list(osv.osv_memory): country = ads.country_id.code sender_date = time.strftime('%Y-%m-%d') - comp_name = obj_cmpny.name +# comp_name = obj_cmpny.name data_file = '\n\n\t\t'+ comp_name +'\n\t\t'+ street +'\n\t\t'+ zip_city +'' - data_file += '\n\t\t'+ country +'\n\t\n' - data_comp = '\n\n\t'+str(company_vat)+'\n\t'+ comp_name +'\n\t'+ street +'\n\t'+ zip_city +'\n\t'+ country +'\n' - data_period = '\n'+ obj_year.date_stop[:4] +'' + data_file += ' VersionTech="1.3">' + data_file += '\n\n\t\n\t\t'+str(company_vat)+'\n\t\t'+ tools.ustr(obj_cmpny.name) +'\n\t\t'+ tools.ustr(street) +'\n\t\t'+ tools.ustr(zip_city) +'' + data_file += '\n\t\t'+ tools.ustr(country) +'\n\t\n' + data_comp = '\n\n\t'+str(company_vat)+'\n\t'+ tools.ustr(obj_cmpny.name) +'\n\t'+ tools.ustr(street) +'\n\t'+ tools.ustr(zip_city) +'\n\t'+ tools.ustr(country) +'\n' + data_period = '\n'+ tools.ustr(obj_year.date_stop[:4]) +'' error_message = [] data = self.read(cursor, user, ids)[0] for partner in data['partner_ids']: @@ -193,22 +195,22 @@ class partner_vat_list(osv.osv_memory): datas.append(client_data) seq = 0 data_clientinfo = '' - sum_tax = 0.00 - sum_turnover = 0.00 + sum_tax = Decimal(str(0.00)) + sum_turnover=Decimal(str(0.00)) if len(error_message): return 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message) for line in datas: if not line: continue - if line['turnover'] < context['limit_amount']: + if Decimal(str(line['turnover'])) < Decimal(str(context['limit_amount'])): continue seq += 1 - sum_tax += line['amount'] - sum_turnover += line['turnover'] - data_clientinfo += '\n\n\t\n\t\t'+line['vat'] +'\n\t\t' + line['country'] +'\n\t\n\t'+str(int(round(line['amount'] * 100))) +'\n\t'+str(int(round(line['turnover'] * 100))) +'\n' + sum_tax +=Decimal(str(line['amount'])) + sum_turnover +=Decimal(str(line['turnover'])) + data_clientinfo += '\n\n\t\n\t\t'+ (line['vat'] or '')[2:] +'\n\t\t' + tools.ustr(line['country']) +'\n\t\n\t'+ str(int(Decimal(str(line['amount'] * 100)))) +'\n\t'+ str(int(Decimal(str(line['turnover'] * 100)))) +'\n' - data_decl ='\n' - data_file += data_decl + data_comp + str(data_period) + data_clientinfo + '\n' + data_decl ='\n' + data_file += tools.ustr(data_decl) + tools.ustr(data_comp) + tools.ustr(data_period) + tools.ustr(data_clientinfo) + '\n' msg = 'Save the File with '".xml"' extension.' file_save = base64.encodestring(data_file.encode('utf8')) self.write(cursor, user, ids, {'file_save':file_save, 'msg':msg, 'name':'vat_list.xml'}, context=context) 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 36a9cd50ea0..03fff730bb4 100644 --- a/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py +++ b/addons/l10n_be/wizard/l10n_be_account_vat_declaration.py @@ -71,13 +71,13 @@ class l10n_be_vat_declaration(osv.osv_memory): tax_code_ids = obj_tax_code.search(cr, uid, [], context=context) ctx = context.copy() data = self.read(cr, uid, ids)[0] - ctx['period_id'] = data['period_id'] #added context here + ctx['period_id'] = data['period_id'][0] #added context here 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 = self.pool.get('res.company')._get_default_ad(obj_company.partner_id.address) - account_period = obj_acc_period.browse(cr, uid, data['period_id'], context=context) + account_period = obj_acc_period.browse(cr, uid, data['period_id'][0], context=context) send_ref = str(obj_company.partner_id.id) + str(account_period.date_start[5:7]) + str(account_period.date_stop[:4]) data_of_file = '\n'