account: add multi company to tax report

bzr revid: ced-7a9c197e7b5a8c67dba0266ce4f8f00a42fde807
This commit is contained in:
ced 2007-07-10 15:25:04 +00:00
parent 997d69a667
commit 38e5e493f9
3 changed files with 111 additions and 31 deletions

View File

@ -38,6 +38,8 @@ class tax_report(report_sxw.rml_parse):
'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,
})
def _add_header(self, node):
@ -46,15 +48,17 @@ class tax_report(report_sxw.rml_parse):
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_id):
self.cr.execute('select sum(tax_amount) as tax_amount, sum(debit) as debit, sum(credit) as credit, count(*) as count, account_id from account_move_line where state<>%s and period_id=%d and tax_code_id=%d group by account_id', ('draft',period_id, tax_code_id))
def _get_general(self, tax_code_id, period_id, company_id):
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 \
from account_move_line AS line, account_account AS account \
where line.state<>%s and line.period_id=%d and line.tax_code_id=%d \
AND line.account_id = account.id AND account.company_id = %d \
group by account.id', ('draft',period_id, tax_code_id, company_id))
res = self.cr.dictfetchall()
i = 0
while i<len(res):
res[i]['account'] = self.pool.get('account.account').browse(self.cr, self.uid, res[i]['account_id'])
i+=1
#print '-'*50
#print 'GENERAL', res
return res
def _get_codes(self, period_id, parent=False, level=0):
@ -66,9 +70,15 @@ class tax_report(report_sxw.rml_parse):
res += self._get_codes(period_id, code.id, level+1)
return res
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw(
'report.account.vat.declaration',
'account.tax.code',
'addons/account/report/tax_report.rml',
parser=tax_report)
parser=tax_report, header=False)

View File

@ -40,15 +40,15 @@
<paraStyle name="P2" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P3" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P4" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P5" fontName="Times-Roman" alignment="CENTER"/>
<paraStyle name="P6" fontName="Times-Roman" alignment="LEFT"/>
<paraStyle name="P7" fontName="Times-Roman" fontSize="6.0" leading="8"/>
<paraStyle name="P8" fontName="Times-Roman" fontSize="11.0" leading="14" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P9" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P10" fontName="Times-Roman" fontSize="7.0" leading="9" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P11" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P12" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P13" fontName="Times-Roman" fontSize="6.0" leading="8" alignment="LEFT"/>
<paraStyle name="P5" fontName="Times-Roman" fontSize="11.0" leading="14" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P6" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P7" fontName="Times-Roman" alignment="CENTER"/>
<paraStyle name="P8" fontName="Times-Roman" alignment="LEFT"/>
<paraStyle name="P9" fontName="Times-Roman" fontSize="6.0" leading="8"/>
<paraStyle name="P10" fontName="Times-Roman" fontSize="6.0" leading="8" alignment="LEFT"/>
<paraStyle name="P11" fontName="Times-Roman" fontSize="7.0" leading="9" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P12" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P13" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Standard" fontName="Times-Roman"/>
<paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
@ -70,12 +70,12 @@
<para style="P1">Tax Report</para>
</td>
<td>
<para style="P2"><i>Period:</i> [[ get_period(data['form']['period_id']) ]]</para>
<para style="P2">Period: [[ get_period(data['form']['period_id']) ]]</para>
</td>
</tr>
<tr>
<td>
<para style="Table Contents">[[ company.name ]]</para>
<para style="Table Contents">[[ get_company(data['form']) ]]</para>
</td>
<td>
<para style="P3">
@ -83,15 +83,15 @@
</para>
</td>
<td>
<para style="P4"><i>Currency:</i> [[ company.currency_id.name ]]</para>
<para style="P4">Currency: [[ get_currency(data['form']) ]]</para>
</td>
</tr>
</blockTable>
<para style="Standard">
<font color="white"> </font>
</para>
<para style="P5"><i>Printing date: </i>[[ time.strftime('%Y-%m-%d') ]] <i>at</i> [[ time.strftime('%H:%M:%S') ]]</para>
<para style="P6">
<para style="P7"><font face="Times-Roman">Printing date: </font>[[ time.strftime('%Y-%m-%d') ]] <font face="Times-Roman">at</font> [[ time.strftime('%H:%M:%S') ]]</para>
<para style="P8">
<font color="white"> </font>
</para>
<blockTable colWidths="148.0,168.0,64.0,59.0,71.0" repeatRows="1" style="Tableau3">
@ -113,51 +113,51 @@
</td>
</tr>
</blockTable>
<para style="P7">
<para style="P9">
<font color="white"> </font>
</para>
<section>
<para style="P7">[[ repeatIn(get_codes(data['form']['period_id']), 'o') ]]</para>
<para style="P9">[[ repeatIn(get_codes(data['form']['period_id']), 'o') ]]</para>
<blockTable colWidths="316.0,64.0,59.0,71.0" repeatRows="1" style="Tableau1">
<tr>
<td>
<para style="P8">[[ o[0] ]] [[ o[1].code ]] - [[ o[1].name ]]</para>
<para style="P5">[[ o[0] ]] [[ o[1].code ]] - [[ o[1].name ]]</para>
</td>
<td>
<para style="P8">
<para style="P5">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P8">
<para style="P5">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P9">[[ o[1].sum_period and ('%.2f' % o[1].sum_period) or '' ]]</para>
<para style="P6">[[ o[1].sum_period and ('%.2f' % o[1].sum_period) or '' ]]</para>
</td>
</tr>
</blockTable>
<blockTable colWidths="44.0,273.0,62.0,60.0,72.0" repeatRows="1" style="Tableau2">
<tr>
<td>
<para style="P10">[[repeatIn(get_general(o[1], data['form']['period_id']), 'g') ]]</para>
<para style="P11">[[repeatIn(get_general(o[1], data['form']['period_id'], data['form']['company_id']), 'g') ]]</para>
</td>
<td>
<para style="P11">[[ g['account'].name ]]</para>
<para style="P12">[[ g['account'].name ]]</para>
</td>
<td>
<para style="P12">[[ g['debit'] and '%.2f' % g['debit'] or '' ]]</para>
<para style="P13">[[ g['debit'] and '%.2f' % g['debit'] or '' ]]</para>
</td>
<td>
<para style="P12">[[ g['credit'] and '%.2f' % g['credit'] or '' ]]</para>
<para style="P13">[[ g['credit'] and '%.2f' % g['credit'] or '' ]]</para>
</td>
<td>
<para style="P12">[[ g['tax_amount'] and '%.2f' % g['tax_amount'] or '' ]]</para>
<para style="P13">[[ g['tax_amount'] and '%.2f' % g['tax_amount'] or '' ]]</para>
</td>
</tr>
</blockTable>
<para style="P13">
<para style="P10">
<font color="white"> </font>
</para>
</section>

View File

@ -0,0 +1,70 @@
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import time
import wizard
import pooler
dates_form = '''<?xml version="1.0"?>
<form string="Select period">
<field name="company_id"/>
<newline/>
<field name="period_id"/>
</form>'''
dates_fields = {
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
'period_id': {'string':'Period', 'type':'many2one', 'relation': 'account.period', 'required':True},
}
class wizard_report(wizard.interface):
def _get_defaults(self, cr, uid, data, context):
period_obj = pooler.get_pool(cr.dbname).get('account.period')
data['form']['period_id'] = period_obj.find(cr, uid)[0]
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
return data['form']
states = {
'init': {
'actions': [_get_defaults],
'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print VAT Decl.')]}
},
'report': {
'actions': [],
'result': {'type':'print', 'report':'account.vat.declaration', 'state':'end'}
}
}
wizard_report('account.vat.declaration')