# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## from openerp.addons.web import http from openerp.addons.web.http import request from common_report_header import common_report_header class tax_report(http.Controller, common_report_header): @http.route(['/report/account.report_vat'], type='http', auth='user', website=True, multilang=True) def report_account_tax(self, **data): report_obj = request.registry['report'] self.cr, self.uid, self.pool = request.cr, request.uid, request.registry data = report_obj.eval_params(data) res = {} self.period_ids = [] period_obj = self.pool.get('account.period') self.display_detail = data['form']['display_detail'] res['periods'] = '' res['fiscalyear'] = data['form'].get('fiscalyear_id', False) if data['form'].get('period_from', False) and data['form'].get('period_to', False): self.period_ids = period_obj.build_ctx_periods(self.cr, self.uid, data['form']['period_from'], data['form']['period_to']) docargs = { 'fiscalyear': self._get_fiscalyear(data), 'account': self._get_account(data), 'based_on': self._get_basedon(data), 'period_from': self.get_start_period(data), 'period_to': self.get_end_period(data), 'taxlines': self._get_lines(self._get_basedon(data), company_id=data['form']['company_id']), } return request.registry['report'].render(self.cr, self.uid, [], 'account.report_vat', docargs) def _get_basedon(self, form): return form['form']['based_on'] def _get_lines(self, based_on, company_id=False, parent=False, level=0, context=None): period_list = self.period_ids res = self._get_codes(based_on, company_id, parent, level, period_list, context=context) if period_list: res = self._add_codes(based_on, res, period_list, context=context) else: self.cr.execute ("select id from account_fiscalyear") fy = self.cr.fetchall() self.cr.execute ("select id from account_period where fiscalyear_id = %s",(fy[0][0],)) periods = self.cr.fetchall() for p in periods: period_list.append(p[0]) res = self._add_codes(based_on, res, period_list, context=context) 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, context=context) 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 return top_result def _get_general(self, tax_code_id, period_list, company_id, based_on, context=None): if not self.display_detail: return [] res = [] obj_account = self.pool.get('account.account') periods_ids = tuple(period_list) 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 = %s \ AND line.account_id = account.id \ AND account.company_id = %s \ AND move.id = line.move_id \ AND line.period_id IN %s \ AND ((invoice.state = %s) \ OR (invoice.id IS NULL)) \ GROUP BY account.id,account.name,account.code', ('draft', tax_code_id, company_id, periods_ids, '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 = %s \ AND line.account_id = account.id \ AND account.company_id = %s \ AND line.period_id IN %s\ AND account.active \ GROUP BY account.id,account.name,account.code', ('draft', tax_code_id, company_id, periods_ids,)) res = self.cr.dictfetchall() i = 0 while i= int(accounts[bcl_rup_ind]['level']) and bcl_rup_ind >= 0 ): 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 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: