Browse Source

[MERGE][account_financial_report] Added Partner Balances to AFR

pull/7/merge
Humberto Arocha 11 years ago
parent
commit
60001206d5
  1. 80
      account_financial_report/model/account_financial_report.py
  2. 273
      account_financial_report/report/balance_full_4_cols_partner_balance.rml
  3. 230
      account_financial_report/report/parser.py
  4. 11
      account_financial_report/view/report.xml
  5. 3
      account_financial_report/view/wizard.xml
  6. 8
      account_financial_report/wizard/wizard.py

80
account_financial_report/model/account_financial_report.py

@ -38,27 +38,45 @@ class account_financial_report(osv.osv):
_columns = {
'name': fields.char('Name', size=128, required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'),
'account_ids': fields.many2many('account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'journal_ledger': fields.boolean('journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str': fields.char('Description', help='Description for the Summary', size=128),
'currency_id': fields.many2one(
'res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
'inf_type': fields.selection(
[('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'),
('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'),
('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer(
'Up to level', help='Display accounts up to this level (0 to show all)'),
'account_ids': fields.many2many(
'account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
'fiscalyear_id': fields.many2one(
'account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id',
'period_id', 'Periods', help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean(
'Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'journal_ledger': fields.boolean(
'journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'partner_balance': fields.boolean('Partner Balance', help="Allows to "
"Generate a Partner Balance for accounts with moves. Available when "
"Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'tot_check': fields.boolean(
'Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str':
fields.char(
'Description',
help='Description for the Summary',
size=128),
'target_move': fields.selection([('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Entries to Include', required=True,
help='Print All Accounting Entries or just Posted Accounting Entries'),
help='Print All Accounting Entries or just Posted Accounting Entries'),
#~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'),
('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
'date_to': fields.date('End date'),
'date_from': fields.date('Start date'),
}
@ -66,8 +84,15 @@ class account_financial_report(osv.osv):
_defaults = {
'display_account_level': lambda *a: 0,
'inf_type': lambda *a: 'BS',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
'company_id': lambda self, cr, uid, c:
self.pool.get(
'res.company')._company_default_get(
cr,
uid,
'account.invoice',
context=c),
'fiscalyear_id': lambda self, cr, uid, c:
self.pool.get('account.fiscalyear').find(cr, uid),
'display_account': lambda *a: 'bal_mov',
'columns': lambda *a: 'five',
@ -85,9 +110,18 @@ class account_financial_report(osv.osv):
lst = self.search(cr, uid, [(
'name', 'like', new_name)], context=context)
if lst:
new_name = '%s (%s)' % (new_name, len(lst)+1)
new_name = '%s (%s)' % (new_name, len(lst) + 1)
defaults['name'] = new_name
return super(account_financial_report, self).copy(cr, uid, id, defaults, context=context)
return (
super(
account_financial_report,
self).copy(
cr,
uid,
id,
defaults,
context=context)
)
def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
if context is None:
@ -99,7 +133,8 @@ class account_financial_report(osv.osv):
return res
def onchange_columns(self, cr, uid, ids, columns, fiscalyear_id, period_ids, context=None):
def onchange_columns(self, cr, uid, ids, columns,
fiscalyear_id, period_ids, context=None):
if context is None:
context = {}
res = {'value': {}}
@ -116,7 +151,8 @@ class account_financial_report(osv.osv):
res['value'].update({'period_ids': []})
return res
def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None):
def onchange_analytic_ledger(
self, cr, uid, ids, company_id, analytic_ledger, context=None):
if context is None:
context = {}
context['company_id'] = company_id

273
account_financial_report/report/balance_full_4_cols_partner_balance.rml

@ -0,0 +1,273 @@
<?xml version="1.0"?>
<document filename="test.pdf">
<template pageSize="(27.94cm,21.59cm)" title="Test" author="Martin Simon" allowSplitting="20" showBoundary="0">
<pageTemplate id="first">
<frame id="first" x1="1.0cm" y1="1.0cm" width="26.0cm" height="16.65cm"/>
<pageGraphics>
<setFont name="Helvetica-Oblique" size="6"/>
<image x="1.0cm" y="17.65cm" width="5.0cm">[[company.logo and company.logo or removeParentNode('image')]]</image>
<!--
<drawString x="1.0cm" y="24.5cm">[[company.logo and removeParentNode('para') or company.name]]</drawString>
-->
<place x="-3.5cm" y="16.15cm" width="19cm" height="5.0cm">
<blockTable colWidths="9.6cm,9.4cm" style="TITLE">
<tr>
<td><para style="TOP_TITLE"></para></td>
<td><para style="TITLE_CENTER_NAME">
<font>[[ (company.name and company.name or 'NOMBRE DE COMPANIA NO DISPONIBLE')]]</font>
<font>[[ get_vat_by_country(data['form']) ]]</font>
</para></td>
</tr>
<tr>
<td><para style="TOP_TITLE"></para></td>
<td><para style="TITLE_CENTER">[[ get_informe_text(data['form']) ]]</para></td>
</tr>
<tr>
<td><para style="TOP_TITLE"></para></td>
<td><para style="TITLE_CENTER">(Expressed in [[data['form'] and (' %s'%( exchange_name(data['form']))) or '']])</para></td>
</tr>
<tr>
<td><para style="TOP_TITLE"></para></td>
<td><para style="TITLE_CENTER">[[data['form'] and get_month(data['form']) or '']]</para></td>
</tr>
</blockTable>
</place>
<drawRightString x="270mm" y="5mm">Printing Date: [[ formatLang(time.strftime('%Y-%m-%d %H:%M:%S'),date_time=True) ]] [[ get_informe_text(data['form']) ]] / Pág.: <pageNumber/>-<pageCount/></drawRightString>
</pageGraphics>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="BODY_LINE">
<blockValign value="TOP"/>
<blockAlignment value="RIGHT"/>
<blockTopPadding length="1.0"/>
<blockBottomPadding length="1.0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1" thickness='0.25'/>
</blockTableStyle>
<blockTableStyle id="TITLE">
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="BODY">
<blockValign value="TOP"/>
<blockAlignment value="RIGHT"/>
<blockTopPadding length="1.0"/>
<blockBottomPadding length="1.0"/>
<lineStyle kind="LINEBELOW" colorName="darkgrey" start="0,0" stop="-1,-1" thickness='0.25'/>
</blockTableStyle>
<blockTableStyle id="BODY_STRIKE">
<blockValign value="TOP"/>
<blockAlignment value="RIGHT"/>
<blockTopPadding length="1.0"/>
<blockBottomPadding length="1.0"/>
<lineStyle kind="LINEBELOW" colorName="#FFFFFF" start="0,1" stop="-1,-1" thickness='0.5'/>
</blockTableStyle>
<blockTableStyle id="TOP_TABLE">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#FFFFFF" start="0,-1" stop="0,-1" thickness='0.25'/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle
name="TITLE_LEFT_ALIGN_NEW"
fontName="Courier"
fontSize="7.0"
leading="10"
alignment="RIGHT"
spaceBefore="0.0"
spaceAfter="0.0"/>
<paraStyle name="TITLES_NEW"
fontName="Courier"
fontSize="7.0"
leading="10"
alignment="LEFT"
spaceBefore="0.0"
spaceAfter="0.0"/>
<paraStyle
name="TITLE_LEFT_ALIGN"
fontName="Helvetica-Bold"
fontSize="7.0"
leading="10"
alignment="RIGHT"
spaceBefore="0.0"
spaceAfter="0.0"/>
<paraStyle name="TOP_TITLE" fontName="Helvetica-Bold" fontSize="7" leftIndent="0.0" alignment="LEFT"/>
<paraStyle
name="TITLES"
fontName="Helvetica-Bold"
fontSize="7.0"
leading="10"
alignment="LEFT"
spaceBefore="0.0"
spaceAfter="0.0"/>
<paraStyle name="TITLE_CENTER" fontName="Helvetica-Bold" fontSize="7" leading="10" leftIndent="0.0" alignment="CENTER"/>
<paraStyle name="TITLE_CENTER_NAME" fontName="Helvetica-Bold" fontSize="12" leading="13" leftIndent="0.0" alignment="CENTER"/>
<paraStyle
name="TITLE"
alignment="CENTER"
fontName="Helvetica"
fontSize="18.0"
leading="20"
spaceBefore="-3.0"
textColor="black"/>
</stylesheet>
<images/>
<story>
<para>[[setLang(user.lang)]]</para>
<blockTable colWidths="2.5cm,13.5cm,2.5cm,2.5cm,2.5cm,2.5cm" style="BODY" repeatRows="0">
<tr noRowsplits="0">
<td>
<para style="TITLE_LEFT_ALIGN">
<font>CODE</font>
</para>
</td>
<td>
<para style="TITLES">ACCOUNT</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">INITIAL</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">DEBIT</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">CREDIT</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">BALANCE</para>
</td>
</tr>
</blockTable>
<blockTable colWidths="2.25cm,13.75cm,2.5cm,2.5cm,2.5cm,2.5cm" style="BODY_LINE" repeatRows="1">
<!--
[[ (a['type'] &lt;&gt; 'view') or removeParentNode('blockTable') ]]
-->
<tr noRowsplits="1">
<td>
<para style="TITLES_NEW">
<font></font>
</para>
</td>
<td>
<para style="TITLES_NEW">
<font>PARTNER</font>
</para>
</td>
<td>
<para style="TITLES_NEW"></para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN"></para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN"></para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN"></para>
</td>
</tr>
</blockTable>
<section>
<para>[[ repeatIn([x for x in lines(data['form']) if x['type'] != 'view'], 'a') ]]</para>
<blockTable colWidths="2.5cm,13.5cm,2.5cm,2.5cm,2.5cm,2.5cm" style="BODY" repeatRows="0">
<tr>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]]</font>
<i>[[a['label']==True and a['code'] or '' ]]</i>
</para>
</td>
<td>
<para style="TITLES">
<font>[[ ((a['total'] and not a['label']) and setTag('para','para',{'alignment':"RIGHT"}) or (a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}))) or removeParentNode('font') ]]</font>
<font>[[ a['type']=='view' and a['name'].upper() or a['name'].title() ]]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(a['balanceinit'] and a['balanceinit'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(a['debit'], digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(a['credit'], digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier-Bold"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(a['balance'] and a['balance'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']]</font>
</para>
</td>
</tr>
</blockTable>
<section>
<para>[[ repeatIn(a['partner'], 'm') ]]</para>
<blockTable colWidths="2.25cm,13.75cm,2.5cm,2.5cm,2.5cm,2.5cm" style="BODY_LINE" repeatRows="1">
<!--
[[ (a['type'] &lt;&gt; 'view') or removeParentNode('blockTable') ]]
-->
<tr>
<td>
<para style="TITLES_NEW">
</para>
</td>
<td>
<para style="TITLES_NEW">
<font>[[ m['partner_name'] ]]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(m['balanceinit'] and m['balanceinit'] * m.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(m['debit'], digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(m['credit'], digits=2, grouping=True) or '']]</font>
</para>
</td>
<td>
<para style="TITLE_LEFT_ALIGN">
<font>[[ a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Courier"}) or removeParentNode('font') ]]</font>
<font>[[ (a['total']==True) and formatLang(m['balance'] and m['balance'] * a.get('change_sign',1.0) or 0.0, digits=2, grouping=True) or '']]</font>
</para>
</td>
</tr>
</blockTable>
</section>
<spacer length="2.5mm"/>
</section>
</story>
</document>

230
account_financial_report/report/parser.py

@ -35,7 +35,6 @@ from report import report_sxw
from tools import config
from tools.translate import _
from osv import osv
import pdb
from openerp.tools.safe_eval import safe_eval as eval
@ -62,20 +61,21 @@ class account_balance(report_sxw.rml_parse):
'get_vat_by_country': self.get_vat_by_country,
})
self.context = context
def get_vat_by_country(self, form):
"""
Return the vat of the partner by country
"""
rc_obj = self.pool.get('res.company')
country_code=rc_obj.browse(self.cr, self.uid, form['company_id'][0]).partner_id.country_id.code or ''
string_vat= rc_obj.browse(self.cr, self.uid, form['company_id'][0]).partner_id.vat or ''
country_code = rc_obj.browse(self.cr, self.uid,
form['company_id'][0]).partner_id.country_id.code or ''
string_vat = rc_obj.browse(self.cr, self.uid,
form['company_id'][0]).partner_id.vat or ''
if string_vat:
if country_code=='MX':
if country_code == 'MX':
return '%s' % (string_vat[2:])
elif country_code=='VE':
return '- %s-%s-%s'%(string_vat[2:3],string_vat[3:11],string_vat[11:12])
elif country_code == 'VE':
return '- %s-%s-%s' % (string_vat[2:3], string_vat[3:11], string_vat[11:12])
else:
return string_vat
else:
@ -120,10 +120,10 @@ class account_balance(report_sxw.rml_parse):
if form['filter'] in ['bydate', 'all']:
months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1]-1]
mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1] - 1]
ano = time.strptime(form['date_to'], "%Y-%m-%d")[0]
dia = time.strptime(form['date_to'], "%Y-%m-%d")[2]
return _('From ')+self.formatLang(form['date_from'], date=True) + _(' to ')+self.formatLang(form['date_to'], date=True)
return _('From ') + self.formatLang(form['date_from'], date=True) + _(' to ') + self.formatLang(form['date_to'], date=True)
elif form['filter'] in ['byperiod', 'all']:
aux = []
period_obj = self.pool.get('account.period')
@ -132,7 +132,7 @@ class account_balance(report_sxw.rml_parse):
aux.append(period.date_start)
aux.append(period.date_stop)
sorted(aux)
return _('From ')+self.formatLang(aux[0], date=True)+_(' to ')+self.formatLang(aux[-1], date=True)
return _('From ') + self.formatLang(aux[0], date=True) + _(' to ') + self.formatLang(aux[-1], date=True)
def get_periods_and_date_text(self, form):
"""
@ -190,6 +190,104 @@ class account_balance(report_sxw.rml_parse):
else:
return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids]
def _get_partner_balance(self, account, init_period, ctx=None):
rp_obj = self.pool.get('res.partner')
res = []
ctx = ctx or {}
if account['type'] in ('other', 'liquidity', 'receivable', 'payable'):
sql_query = """
SELECT
CASE
WHEN aml.partner_id IS NOT NULL
THEN (SELECT name FROM res_partner WHERE aml.partner_id = id)
ELSE 'UNKNOWN'
END AS partner_name,
CASE
WHEN aml.partner_id IS NOT NULL
THEN aml.partner_id
ELSE 0
END AS p_idx,
%s,
%s,
%s,
%s
FROM account_move_line AS aml
INNER JOIN account_account aa ON aa.id = aml.account_id
INNER JOIN account_move am ON am.id = aml.move_id
%s
GROUP BY p_idx, partner_name
"""
WHERE_POSTED = ''
if ctx.get('state', 'posted') == 'posted':
WHERE_POSTED = "AND am.state = 'posted'"
cur_periods = ', '.join([str(i) for i in ctx['periods']])
init_periods = ', '.join([str(i) for i in init_period])
WHERE = """
WHERE aml.period_id IN (%s)
AND aa.id = %s
AND aml.state <> 'draft'
""" % (init_periods, account['id'])
query_init = sql_query % ('SUM(aml.debit) AS init_dr',
'SUM(aml.credit) AS init_cr',
'0.0 AS bal_dr',
'0.0 AS bal_cr',
WHERE + WHERE_POSTED)
WHERE = """
WHERE aml.period_id IN (%s)
AND aa.id = %s
AND aml.state <> 'draft'
""" % (cur_periods, account['id'])
query_bal = sql_query % ('0.0 AS init_dr',
'0.0 AS init_cr',
'SUM(aml.debit) AS bal_dr',
'SUM(aml.credit) AS bal_cr',
WHERE + WHERE_POSTED)
query = '''
SELECT
partner_name,
p_idx,
SUM(init_dr)-SUM(init_cr) AS balanceinit,
SUM(bal_dr) AS debit,
SUM(bal_cr) AS credit,
SUM(init_dr) - SUM(init_cr) + SUM(bal_dr) - SUM(bal_cr) AS balance
FROM (
SELECT
*
FROM (%s) vinit
UNION ALL (%s)
) v
GROUP BY p_idx, partner_name
ORDER BY partner_name
''' % (query_init, query_bal)
self.cr.execute(query)
res_dict = self.cr.dictfetchall()
unknown = False
for det in res_dict:
i, d, c, b = det['balanceinit'], det[
'debit'], det['credit'], det['balance'],
if not any([i, d, c, b]):
continue
data = {
'partner_name': det['partner_name'],
'balanceinit': i,
'debit': d,
'credit': c,
'balance': b,
}
if not det['p_idx']:
unknown = data
continue
res.append(data)
unknown and res.append(unknown)
return res
def _get_analytic_ledger(self, account, ctx={}):
res = []
@ -200,7 +298,7 @@ class account_balance(report_sxw.rml_parse):
#~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % (
periods, account['id'])
if ctx.get('state','posted')=='posted':
if ctx.get('state', 'posted') == 'posted':
where += "AND am.state = 'posted'"
sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion,
(select name from res_partner where aml.partner_id = id) as partner,
@ -250,7 +348,7 @@ class account_balance(report_sxw.rml_parse):
#~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % (
periods, account['id'])
if ctx.get('state','posted')=='posted':
if ctx.get('state', 'posted') == 'posted':
where += "AND am.state = 'posted'"
sql_detalle = """SELECT
DISTINCT am.id as am_id,
@ -274,9 +372,9 @@ class account_balance(report_sxw.rml_parse):
'name': det['name'],
'date': det['date'],
'period': det['periodo'],
'obj': am_obj.browse(self.cr,self.uid,det['am_id'])
'obj': am_obj.browse(self.cr, self.uid, det['am_id'])
})
print 'ACCOUNT NAME', am_obj.browse(self.cr,self.uid,det['am_id']).name
print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid, det['am_id']).name
return res
def lines(self, form, level=0):
@ -309,11 +407,9 @@ class account_balance(report_sxw.rml_parse):
ids2.append([aa_brw.id, True, True, aa_brw])
return ids2
#############################################################################
#######################################################################
# CONTEXT FOR ENDIND BALANCE #
#######################################################################
def _ctx_end(ctx):
ctx_end = ctx
ctx_end['filter'] = form.get('filter', 'all')
@ -347,7 +443,7 @@ class account_balance(report_sxw.rml_parse):
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', ctx_init['fiscalyear']), ('date_stop', '<', fiscalyear.date_start)])
return ctx_init
#############################################################################
#######################################################################
# CONTEXT FOR INITIAL BALANCE #
#######################################################################
@ -394,7 +490,7 @@ class account_balance(report_sxw.rml_parse):
if 'account_list' in form and form['account_list']:
account_ids = form['account_list']
account_list= form['account_list']
account_list = form['account_list']
del form['account_list']
credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[
@ -490,38 +586,41 @@ class account_balance(report_sxw.rml_parse):
tot = {}
###############################################################
# Calculations of credit, debit and balance,
# Calculations of credit, debit and balance,
# without repeating operations.
###############################################################
account_black_ids = account_obj.search(self.cr, self.uid, (
[('id', 'in', [i[0] for i in all_account_ids]),
('type', 'not in',
('view', 'consolidation'))]))
('view', 'consolidation'))]))
account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
i[0] for i in all_account_ids]),('type', '=', 'view')]))
i[0] for i in all_account_ids]), ('type', '=', 'view')]))
acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))]))
i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))]))
account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol(
self.cr, self.uid, acc_cons_ids) or []
self.cr, self.uid, acc_cons_ids) or []
account_black_ids += account_obj.search(self.cr, self.uid, (
[('id', 'in', account_consol_ids ),
('type', 'not in',
('view', 'consolidation'))]))
[('id', 'in', account_consol_ids),
('type', 'not in',
('view', 'consolidation'))]))
account_black_ids = list(set(account_black_ids))
c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([
('id', 'in', account_consol_ids),
('type', '=', 'view')]))
('id', 'in',
account_consol_ids),
('type', '=', 'view')]))
delete_cons = False
if c_account_not_black_ids:
delete_cons = set(account_not_black_ids) & set(c_account_not_black_ids) and True or False
account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids))
delete_cons = set(account_not_black_ids) & set(
c_account_not_black_ids) and True or False
account_not_black_ids = list(
set(account_not_black_ids) - set(c_account_not_black_ids))
# This could be done quickly with a sql sentence
account_not_black = account_obj.browse(
@ -537,7 +636,8 @@ class account_balance(report_sxw.rml_parse):
c_account_not_black_ids = [i.id for i in c_account_not_black]
if delete_cons:
account_not_black_ids = c_account_not_black_ids + account_not_black_ids
account_not_black_ids = c_account_not_black_ids + \
account_not_black_ids
account_not_black = c_account_not_black + account_not_black
else:
acc_cons_brw = account_obj.browse(
@ -546,11 +646,13 @@ class account_balance(report_sxw.rml_parse):
acc_cons_brw.reverse()
acc_cons_ids = [i.id for i in acc_cons_brw]
account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids
account_not_black = c_account_not_black + acc_cons_brw + account_not_black
account_not_black_ids = c_account_not_black_ids + \
acc_cons_ids + account_not_black_ids
account_not_black = c_account_not_black + \
acc_cons_brw + account_not_black
all_account_period = {} # All accounts per period
all_account_period = {} # All accounts per period
# Iteration limit depending on the number of columns
if form['columns'] == 'thirteen':
limit = 13
@ -561,7 +663,7 @@ class account_balance(report_sxw.rml_parse):
for p_act in range(limit):
if limit != 1:
if p_act == limit-1:
if p_act == limit - 1:
form['periods'] = period_ids
else:
if form['columns'] == 'thirteen':
@ -591,7 +693,7 @@ class account_balance(report_sxw.rml_parse):
'obj': i,
'debit': d,
'credit': c,
'balance': d-c
'balance': d - c
}
if form['inf_type'] == 'BS':
dict_black.get(i.id)['balanceinit'] = 0.0
@ -611,12 +713,12 @@ class account_balance(report_sxw.rml_parse):
dict_not_black.get(i.id)['balanceinit'] = 0.0
all_account = dict_black.copy(
) #It makes a copy because they modify
) # It makes a copy because they modify
for acc_id in account_not_black_ids:
acc_childs = dict_not_black.get(acc_id).get('obj').type=='view' \
and dict_not_black.get(acc_id).get('obj').child_id \
or dict_not_black.get(acc_id).get('obj').child_consol_ids
acc_childs = dict_not_black.get(acc_id).get('obj').type == 'view' \
and dict_not_black.get(acc_id).get('obj').child_id \
or dict_not_black.get(acc_id).get('obj').child_consol_ids
for child_id in acc_childs:
if child_id.type == 'consolidation' and delete_cons:
continue
@ -631,7 +733,7 @@ class account_balance(report_sxw.rml_parse):
child_id.id).get('balanceinit')
all_account[acc_id] = dict_not_black[acc_id]
if p_act == limit-1:
if p_act == limit - 1:
all_account_period['all'] = all_account
else:
if form['columns'] == 'thirteen':
@ -669,7 +771,7 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get(pn-1).get(id).get('debit', 0.0), all_account_period.get(pn-1).get(id).get('credit', 0.0), all_account_period.get(pn-1).get(id).get('balance', 0.0)])
all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0), all_account_period.get(pn - 1).get(id).get('balance', 0.0)])
res.update({
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
@ -677,8 +779,8 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get(pn-1).get(id).get('balanceinit', 0.0), all_account_period.get(pn-1).get(id).get('debit', 0.0), all_account_period.get(pn-1).get(id).get('credit', 0.0)])
b = z(i+d-c)
all_account_period.get(pn - 1).get(id).get('balanceinit', 0.0), all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
@ -687,7 +789,7 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit',0.0), all_account_period.get('all').get(id).get('balance')])
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance')])
res.update({
'dbr5': self.exchange(d),
'cdr5': self.exchange(c),
@ -695,8 +797,8 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit',0.0)])
b = z(i+d-c)
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr5': self.exchange(d),
'cdr5': self.exchange(c),
@ -718,7 +820,7 @@ class account_balance(report_sxw.rml_parse):
else:
i, d, c = map(z, [
all_account_period.get(p_num).get(id).get('balanceinit', 0.0), all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0)])
b = z(i+d-c)
b = z(i + d - c)
res.update({
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
@ -738,7 +840,7 @@ class account_balance(report_sxw.rml_parse):
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
b = z(i+d-c)
b = z(i + d - c)
res.update({
'dbr13': self.exchange(d),
'cdr13': self.exchange(c),
@ -748,17 +850,17 @@ class account_balance(report_sxw.rml_parse):
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
b = z(i+d-c)
b = z(i + d - c)
res.update({
'balanceinit': self.exchange(i),
'debit': self.exchange(d),
'credit': self.exchange(c),
'ytd': self.exchange(d-c),
'ytd': self.exchange(d - c),
})
if form['inf_type'] == 'IS' and form['columns'] == 'one':
res.update({
'balance': self.exchange(d-c),
'balance': self.exchange(d - c),
})
else:
res.update({
@ -774,7 +876,7 @@ class account_balance(report_sxw.rml_parse):
to_test = [False]
if form['display_account'] == 'mov' and aa_id[3].parent_id:
# Include accounts with movements
for x in range(pn-1):
for x in range(pn - 1):
to_test.append(res.get(
'dbr%s' % x, 0.0) >= 0.005 and True or False)
to_test.append(res.get(
@ -784,7 +886,7 @@ class account_balance(report_sxw.rml_parse):
elif form['display_account'] == 'bal' and aa_id[3].parent_id:
# Include accounts with balance
for x in range(pn-1):
for x in range(pn - 1):
to_test.append(res.get(
'bal%s' % x, 0.0) >= 0.005 and True or False)
if any(to_test):
@ -792,7 +894,7 @@ class account_balance(report_sxw.rml_parse):
elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
# Include accounts with balance or movements
for x in range(pn-1):
for x in range(pn - 1):
to_test.append(res.get(
'bal%s' % x, 0.0) >= 0.005 and True or False)
to_test.append(res.get(
@ -828,6 +930,9 @@ class account_balance(report_sxw.rml_parse):
res['mayor'] = self._get_analytic_ledger(res, ctx=ctx_end)
elif to_include and form['journal_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
res['journal'] = self._get_journal_ledger(res, ctx=ctx_end)
elif to_include and form['partner_balance'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
res['partner'] = self._get_partner_balance(
res, ctx_i['periods'], ctx=ctx_end)
else:
res['mayor'] = []
@ -937,7 +1042,13 @@ report_sxw.report_sxw('report.afr.analytic.ledger',
'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.partner.balance',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_partner_balance.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.journal.ledger',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_journal_ledger.rml',
@ -961,4 +1072,3 @@ report_sxw.report_sxw('report.afr.13cols',
'account_financial_report/report/balance_full_13_cols.rml',
parser=account_balance,
header=False)

11
account_financial_report/view/report.xml

@ -46,6 +46,17 @@
header="False"
/>
<report
auto="False"
id="partner_balance_report"
menu="True"
model="wizard.report"
name="afr.partner.balance"
rml="account_financial_report/report/balance_full_4_cols_partner_balance.rml"
string="Partner Balance"
header="False"
/>
<report
auto="False"
id="journal_ledger_report"

3
account_financial_report/view/wizard.xml

@ -44,6 +44,9 @@
<field name="journal_ledger"
attrs="{'readonly':['|',('columns','!=','four'),('inf_type','!=','BS')],}"
/>
<field name="partner_balance"
attrs="{'readonly':['|',('columns','!=','four'),('inf_type','!=','BS')],}"
/>
</group>
</group>
<group>

8
account_financial_report/wizard/wizard.py

@ -51,14 +51,16 @@ class wizard_report(osv.osv_memory):
'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'journal_ledger': fields.boolean('Journal Ledger', help="Allows to Generate an Journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'partner_balance': fields.boolean('Partner Balance', help="Allows to "
"Generate a Partner Balance for accounts with moves. Available when "
"Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str': fields.char('Description', help='Description for the Summary', size=128),
'target_move': fields.selection([('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Entries to Include', required=True,
help='Print All Accounting Entries or just Posted Accounting Entries'),
help='Print All Accounting Entries or just Posted Accounting Entries'),
#~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
'date_to': fields.date('End date'),
@ -276,6 +278,8 @@ class wizard_report(osv.osv_memory):
name = 'afr.analytic.ledger'
elif data['form']['journal_ledger'] and data['form']['inf_type'] == 'BS':
name = 'afr.journal.ledger'
elif data['form']['partner_balance'] and data['form']['inf_type'] == 'BS':
name = 'afr.partner.balance'
else:
name = 'afr.4cols'
if data['form']['columns'] == 'five':

Loading…
Cancel
Save