[MERGE] account: merged the branch that add debit/credit option on financial reports

bzr revid: qdp-launchpad@openerp.com-20120213104937-fyfay6sym8l8dq7d
This commit is contained in:
Quentin (OpenERP) 2012-02-13 11:49:37 +01:00
commit 6645ed25db
5 changed files with 69 additions and 25 deletions

View File

@ -55,39 +55,37 @@ class account_financial_report(osv.osv):
res += self._get_children_by_order(cr, uid, ids2, context=context)
return res
def _get_balance(self, cr, uid, ids, name, args, context=None):
def _get_balance(self, cr, uid, ids, field_names, args, context=None):
account_obj = self.pool.get('account.account')
res = {}
res_all = {}
for report in self.browse(cr, uid, ids, context=context):
balance = 0.0
if report.id in res_all:
balance = res_all[report.id]
elif report.type == 'accounts':
# it's the sum of balance of the linked accounts
if report.id in res:
continue
res[report.id] = dict((fn, 0.0) for fn in field_names)
if report.type == 'accounts':
# it's the sum of the linked accounts
for a in report.account_ids:
balance += a.balance
for field in field_names:
res[report.id][field] += getattr(a, field)
elif report.type == 'account_type':
# it's the sum of balance of the leaf accounts with such an account type
# it's the sum the leaf accounts with such an account type
report_types = [x.id for x in report.account_type_ids]
account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context)
for a in account_obj.browse(cr, uid, account_ids, context=context):
balance += a.balance
for field in field_names:
res[report.id][field] += getattr(a, field)
elif report.type == 'account_report' and report.account_report_id:
# it's the amount of the linked report
res2 = self._get_balance(cr, uid, [report.account_report_id.id], 'balance', False, context=context)
res_all.update(res2)
res2 = self._get_balance(cr, uid, [report.account_report_id.id], field_names, False, context=context)
for key, value in res2.items():
balance += value
for field in field_names:
res[report.id][field] += value[field]
elif report.type == 'sum':
# it's the sum of balance of the children of this account.report
#for child in report.children_ids:
res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], 'balance', False, context=context)
res_all.update(res2)
# it's the sum of the children of this account.report
res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], field_names, False, context=context)
for key, value in res2.items():
balance += value
res[report.id] = balance
res_all[report.id] = balance
for field in field_names:
res[report.id][field] += value[field]
return res
_columns = {
@ -95,7 +93,9 @@ class account_financial_report(osv.osv):
'parent_id': fields.many2one('account.financial.report', 'Parent'),
'children_ids': fields.one2many('account.financial.report', 'parent_id', 'Account Report'),
'sequence': fields.integer('Sequence'),
'balance': fields.function(_get_balance, 'Balance'),
'balance': fields.function(_get_balance, 'Balance', multi='balance'),
'debit': fields.function(_get_balance, 'Debit', multi='balance'),
'credit': fields.function(_get_balance, 'Credit', multi="balance"),
'level': fields.function(_get_level, string='Level', store=True, type='integer'),
'type': fields.selection([
('sum','View'),

View File

@ -61,6 +61,9 @@ class report_account_common(report_sxw.rml_parse, common_report_header):
'level': bool(report.style_overwrite) and report.style_overwrite or report.level,
'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances
}
if data['form']['debit_credit']:
vals['debit'] = report.debit
vals['credit'] = report.credit
if data['form']['enable_filter']:
vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance
lines.append(vals)
@ -87,6 +90,11 @@ class report_account_common(report_sxw.rml_parse, common_report_header):
'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1
'account_type': account.type,
}
if data['form']['debit_credit']:
vals['debit'] = account.debit
vals['credit'] = account.credit
lines.append(vals)
if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']):
flag = True
if data['form']['enable_filter']:

View File

@ -143,7 +143,7 @@
<blockTableStyle id="Table1">
<blockTopPadding start="0,0" stop="-1,0" length="10"/>
<blockAlignment value="LEFT"/>
<lineStyle kind="LINEBELOW" colorName="#666666" start="1,1" stop="1,1"/>
<lineStyle kind="LINEBELOW" colorName="#666666" start="1,1" stop="-1,1"/>
</blockTableStyle>
<blockTableStyle id="Table2">
<blockValign value="TOP"/>
@ -205,8 +205,40 @@
<para style="Standard">
<font color="white"> </font>
</para>
<!-- table with debit/credit displayed -->
<blockTable colWidths="210.0,90.0,90.0,100.0" style="Table_Account_Line_Title">
[[ data['form']['debit_credit'] == 1 or removeParentNode('blockTable') ]]
<tr>
<td>
<para style="terp_default_Bold_9">Name</para>
</td>
<td>
<para style="terp_tblheader_Details_Right">Debit</para>
</td>
<td>
<para style="terp_tblheader_Details_Right">Credit</para>
</td>
<td>
<para style="terp_tblheader_Details_Right">Balance</para>
</td>
</tr>
<tr style="Table3">
[[ repeatIn(get_lines(data), 'a') ]]
[[ (a.get('level') &lt;&gt; 0) or removeParentNode('tr') ]]
[[ setTag('tr','tr',{'style': 'Table'+str(min(3,'level' in a and a.get('level') or 1))}) ]]
<td><para style="terp_level_3_name">[[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_name'}) ]][[ a.get('name') ]]</para></td>
<td><para style="terp_level_3_balance">[[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('debit',0.0), currency_obj = company.currency_id) ]]</para></td>
<td><para style="terp_level_3_balance">[[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('credit',0.0), currency_obj = company.currency_id) ]]</para></td>
<td>[[ (a.get('account_type') =='view' and a.get('level') &lt;&gt; 1) or removeParentNode('td') ]]
<para style="terp_level_3_balance"><u>[[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('balance'), currency_obj = company.currency_id) ]]</u></para></td>
<td>[[ (a.get('account_type') &lt;&gt;'view' or a.get('level') == 1) or removeParentNode('td') ]]
<para style="terp_level_3_balance">[[ setTag('para','para',{'style': 'terp_level_'+str(min(6,a.get('level')))+'_balance'}) ]][[ formatLang(a.get('balance'), currency_obj = company.currency_id) ]]</para></td>
</tr>
</blockTable>
<!-- table with no comparison, no debit/credit displayed -->
<blockTable colWidths="390.0,100.0" style="Table_Account_Line_Title">
[[ data['form']['enable_filter'] == 0 or removeParentNode('blockTable') ]]
[[ (not data['form']['enable_filter'] and not data['form']['debit_credit']) or removeParentNode('blockTable') ]]
<tr>
<td>
<para style="terp_default_Bold_9">Name</para>
@ -229,8 +261,10 @@
<para style="Standard">
<font color="white"> </font>
</para>
<!-- table with comparison -->
<blockTable colWidths="263.0,100.0,100" style="Table_Account_Line_Title">
[[ data['form']['enable_filter'] == 1 or removeParentNode('blockTable') ]]
[[ (data['form']['enable_filter'] == 1 and not data['form']['debit_credit']) or removeParentNode('blockTable') ]]
<tr>
<td>
<para style="terp_default_Bold_9">Name</para>

View File

@ -36,6 +36,7 @@ class accounting_report(osv.osv_memory):
'period_to_cmp': fields.many2one('account.period', 'End Period'),
'date_from_cmp': fields.date("Start Date"),
'date_to_cmp': fields.date("End Date"),
'debit_credit': fields.boolean('Display Debit/Credit Columns', help="This option allow you to get more details about your the way your balances are computed. Because it is space consumming, we do not allow to use it while doing a comparison"),
}
def _get_account_report(self, cr, uid, context=None):
@ -85,7 +86,7 @@ class accounting_report(osv.osv_memory):
return res
def _print_report(self, cr, uid, ids, data, context=None):
data['form'].update(self.read(cr, uid, ids, ['date_from_cmp', 'date_to_cmp', 'fiscalyear_id_cmp', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'account_report_id', 'enable_filter', 'label_filter'], context=context)[0])
data['form'].update(self.read(cr, uid, ids, ['date_from_cmp', 'debit_credit', 'date_to_cmp', 'fiscalyear_id_cmp', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'account_report_id', 'enable_filter', 'label_filter'], context=context)[0])
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.financial.report',

View File

@ -11,6 +11,7 @@
<xpath expr="//field[@name='target_move']" position="after">
<field name="account_report_id" domain="[('parent_id','=',False)]"/>
<field name="enable_filter"/>
<field name="debit_credit" attrs="{'invisible': [('enable_filter','=',True)]}"/>
</xpath>
<xpath expr="//notebook/page[@string='Filters']" position="after">
<page string="Comparison" attrs="{'invisible': [('enable_filter','=',False)]}">