# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2008 Tiny SPRL (). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ############################################################################## import time import pooler import rml_parse import copy from report import report_sxw import pdb import re class tax_report(rml_parse.rml_parse): _name = 'report.account.vat.declaration' def __init__(self, cr, uid, name, context): super(tax_report, self).__init__(cr, uid, name, context) self.localcontext.update({ 'time': time, 'get_period': self._get_period, 'get_codes': self._get_codes, 'get_general': self._get_general, 'get_company': self._get_company, 'get_currency': self._get_currency, 'get_lines' : self._get_lines, }) def comma_me(self,amount): if type(amount) is float : amount = str('%.2f'%amount) else : amount = str(amount) if (amount == '0'): return ' ' orig = amount new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount) if orig == new: return new else: return self.comma_me(new) def _get_lines(self, based_on,period_list,company_id=False, parent=False, level=0): res = self._get_codes(based_on,parent,level,period_list) res = self._add_codes(based_on,res,period_list) i = 0 top_result = [] while i < len(res): res_dict = { 'code' : res[i][1].code, 'name' : res[i][1].name, 'debit' : 0, 'credit' : 0, 'tax_amount' : res[i][1].sum_period, 'type' : 1, 'level' : res[i][0], 'pos' : 0 } top_result.append(res_dict) res_general = self._get_general(res[i][1].id,period_list,company_id,based_on) ind_general = 0 while ind_general < len(res_general) : res_general[ind_general]['type'] = 2 res_general[ind_general]['pos'] = 0 res_general[ind_general]['level'] = res_dict['level'] top_result.append(res_general[ind_general]) ind_general+=1 i+=1 #array_result = self.sort_result(top_result) return top_result #return array_result def _get_period(self, period_id): return self.pool.get('account.period').browse(self.cr, self.uid, period_id).name def _get_general(self, tax_code_id,period_list ,company_id, based_on): res=[] period_sql_list = ','.join(map(str, period_list[0][2])) if based_on == 'payments': self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ SUM(line.debit) AS debit, \ SUM(line.credit) AS credit, \ COUNT(*) AS count, \ account.id AS account_id, \ account.name AS name, \ account.code AS code \ FROM account_move_line AS line, \ account_account AS account, \ account_move AS move \ LEFT JOIN account_invoice invoice ON \ (invoice.move_id = move.id) \ WHERE line.state<>%s \ AND line.tax_code_id = %d \ AND line.account_id = account.id \ AND account.company_id = %d \ AND move.id = line.move_id \ AND ((invoice.state = %s) \ OR (invoice.id IS NULL)) \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, company_id, 'paid')) else : self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ SUM(line.debit) AS debit, \ SUM(line.credit) AS credit, \ COUNT(*) AS count, \ account.id AS account_id, \ account.name AS name, \ account.code AS code \ FROM account_move_line AS line, \ account_account AS account \ WHERE line.state <> %s \ AND line.tax_code_id = %d \ AND line.account_id = account.id \ AND account.company_id = %d \ AND account.active \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, company_id)) res = self.cr.dictfetchall() #AND line.period_id IN ('+ period_sql_list +') \ i = 0 while i= int(accounts[bcl_rup_ind]['level']) and bcl_rup_ind >= 0 ): tot_elem = copy.copy(accounts[bcl_rup_ind]) res_tot = { 'code' : accounts[bcl_rup_ind]['code'], 'name' : '', 'debit' : 0, 'credit' : 0, 'tax_amount' : accounts[bcl_rup_ind]['tax_amount'], 'type' : accounts[bcl_rup_ind]['type'], 'level' : 0, 'pos' : 0 } if res_tot['type'] == 1: # on change le type pour afficher le total res_tot['type'] = 2 result_accounts.append(res_tot) bcl_current_level = accounts[bcl_rup_ind]['level'] bcl_rup_ind -= 1 old_level = account_elem['level'] result_accounts.append(account_elem) ind+=1 return result_accounts report_sxw.report_sxw('report.account.vat.declaration', 'account.tax.code', 'addons/account/report/tax_report.rml', parser=tax_report, header=False)