account: account balance report improvement (not yet finished)

bzr revid: qdp-launchpad@tinyerp.com-20100706093231-n3zj7v8nq42aujuy
This commit is contained in:
qdp-launchpad@tinyerp.com 2010-07-06 11:32:31 +02:00
parent a9df8e33ae
commit 470916f5d6
5 changed files with 178 additions and 207 deletions

View File

@ -32,6 +32,7 @@ class account_move_line(osv.osv):
_description = "Entry Lines"
def _query_get(self, cr, uid, obj='l', context={}):
print 'dans le query_get', context
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalperiod_obj = self.pool.get('account.period')
fiscalyear_ids = []

View File

@ -32,168 +32,162 @@ from report import report_sxw
import osv
import tools
import pooler
from tools.translate import _
class account_balance(report_sxw.rml_parse):
_name = 'report.account.account.balance'
def __init__(self, cr, uid, name, context=None):
super(account_balance, self).__init__(cr, uid, name, context=context)
self.sum_debit = 0.00
self.sum_credit = 0.00
self.date_lst = []
self.date_lst_string = ''
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_fiscalyear':self.get_fiscalyear,
'get_periods':self.get_periods,
})
self.context = context
_name = 'report.account.account.balance'
def _add_header(self, node, header=1):
if header==0:
self.rml_header = ""
return True
def set_context(self, objects, data, ids, report_type = None):
new_ids = ids
if (data['model'] == 'ir.ui.menu'):
new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or []
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
self.query_get_clause = data['form']['query_line'] or ''
super(account_balance, self).set_context(objects, data, new_ids, report_type)
def get_fiscalyear(self, form):
res=[]
if form.has_key('fiscalyear_id'):
fisc_id = form['fiscalyear_id']
if not (fisc_id):
return ''
self.cr.execute("select name from account_fiscalyear where id = %s" , (int(fisc_id),))
res=self.cr.fetchone()
return res and res[0] or ''
def __init__(self, cr, uid, name, context=None):
super(account_balance, self).__init__(cr, uid, name, context=context)
self.sum_debit = 0.00
self.sum_credit = 0.00
self.date_lst = []
self.date_lst_string = ''
self.localcontext.update({
'time': time,
'lines': self.lines,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_fiscalyear':self.get_fiscalyear,
'get_periods':self.get_periods,
})
self.context = context
def get_periods(self, form):
result=''
if form.has_key('periods') and form['periods']:
period_ids = form['periods']
per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods'])
for r in per_ids:
if r == per_ids[len(per_ids)-1]:
result+=r.name+". "
else:
result+=r.name+", "
else:
fy_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear'])
res = fy_obj.period_ids
len_res = len(res)
for r in res:
if r == res[len_res-1]:
result+=r.name+". "
else:
result+=r.name+", "
def _add_header(self, node, header=1):
if header==0:
self.rml_header = ""
return True
return str(result and result[:-1]) or 'ALL'
def get_fiscalyear(self, form):
res=[]
if form.has_key('fiscalyear_id'):
fisc_id = form['fiscalyear_id']
if not (fisc_id):
return ''
self.cr.execute("select name from account_fiscalyear where id = %s" , (int(fisc_id),))
res=self.cr.fetchone()
return res and res[0] or ''
def lines(self, form, ids=[], done=None, level=1):
if not ids:
ids = self.ids
if not ids:
return []
if not done:
done={}
if form.has_key('Account_list') and form['Account_list']:
ids = [form['Account_list']]
del form['Account_list']
res={}
result_acc=[]
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear_id']
if form['filter'] == 'filter_period':
periods = form['periods']
if not periods:
sql = """
Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s
"""
sqlargs = (form['fiscalyear'],)
def get_periods(self, form):
result=''
if form.has_key('periods') and form['periods']:
period_ids = form['periods']
per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods'])
for r in per_ids:
if r == per_ids[len(per_ids)-1]:
result+=r.name+". "
else:
sql = """
Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s
"""
sqlargs = (tuple(periods),)
self.cr.execute(sql, sqlargs)
res = self.cr.dictfetchall()
ctx['periods'] = form['periods']
elif form['filter'] == 'filter_date':
ctx['date_from'] = form['date_from']
ctx['date_to'] = form['date_to']
elif form['filter'] == 'filter_no' :
ctx['periods'] = form['periods']
ctx['date_from'] = form['date_from']
ctx['date_to'] = form['date_to']
# accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)
# def cmp_code(x, y):
# return cmp(x.code, y.code)
# accounts.sort(cmp_code)
child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)
if child_ids:
ids = child_ids
accounts = self.pool.get('account.account').read(self.cr, self.uid, ids, ['type','code','name','debit','credit','balance','parent_id'], ctx)
for account in accounts:
if account['id'] in done:
continue
done[account['id']] = 1
res = {
'id' : account['id'],
'type' : account['type'],
'code': account['code'],
'name': account['name'],
'level': level,
'debit': account['debit'],
'credit': account['credit'],
'balance': account['balance'],
# 'leef': not bool(account['child_id']),
'parent_id':account['parent_id'],
'bal_type':'',
}
self.sum_debit += account['debit']
self.sum_credit += account['credit']
# if account.child_id:
# def _check_rec(account):
# if not account.child_id:
# return bool(account.credit or account.debit)
# for c in account.child_id:
# if not _check_rec(c) or _check_rec(c):
# return True
# return False
# if not _check_rec(account) :
# continue
if account['parent_id']:
# acc = self.pool.get('account.account').read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx)
for r in result_acc:
if r['id'] == account['parent_id'][0]:
res['level'] = r['level'] + 1
break
if form['display_account'] == 'bal_mouvement':
if res['credit'] > 0 or res['debit'] > 0 or res['balance'] > 0 :
result_acc.append(res)
elif form['display_account'] == 'bal_solde':
if res['balance'] != 0:
result_acc.append(res)
result+=r.name+", "
else:
fy_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear'])
res = fy_obj.period_ids
len_res = len(res)
for r in res:
if r == res[len_res-1]:
result+=r.name+". "
else:
result+=r.name+", "
return str(result and result[:-1]) or _('ALL')
def lines(self, form, ids=[], done=None, level=1):
if not ids:
ids = self.ids
if not ids:
return []
if not done:
done={}
res={}
result_acc=[]
ctx = self.context.copy()
ctx['fiscalyear'] = form['fiscalyear_id']
if form['filter'] == 'filter_period':
ctx['periods'] = form['periods']
elif form['filter'] == 'filter_date':
ctx['date_from'] = form['date_from']
ctx['date_to'] = form['date_to']
# accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)
# def cmp_code(x, y):
# return cmp(x.code, y.code)
# accounts.sort(cmp_code)
child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)
if child_ids:
ids = child_ids
print 'on va faire un read'
accounts = self.pool.get('account.account').read(self.cr, self.uid, ids, ['type','code','name','debit','credit','balance','parent_id'], ctx)
print 'on a fait un read'
import pdb
pdb.set_trace()
for account in accounts:
if account['id'] in done:
continue
done[account['id']] = 1
res = {
'id' : account['id'],
'type' : account['type'],
'code': account['code'],
'name': account['name'],
'level': level,
'debit': account['debit'],
'credit': account['credit'],
'balance': account['balance'],
# 'leef': not bool(account['child_id']),
'parent_id':account['parent_id'],
'bal_type':'',
}
self.sum_debit += account['debit']
self.sum_credit += account['credit']
# if account.child_id:
# def _check_rec(account):
# if not account.child_id:
# return bool(account.credit or account.debit)
# for c in account.child_id:
# if not _check_rec(c) or _check_rec(c):
# return True
# return False
# if not _check_rec(account) :
# continue
if account['parent_id']:
# acc = self.pool.get('account.account').read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx)
for r in result_acc:
if r['id'] == account['parent_id'][0]:
res['level'] = r['level'] + 1
break
if form['display_account'] == 'bal_mouvement':
if res['credit'] > 0 or res['debit'] > 0 or res['balance'] > 0 :
result_acc.append(res)
# if account.child_id:
# acc_id = [acc.id for acc in account.child_id]
# lst_string = ''
# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\''
# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string))
# a_id = self.cr.fetchall()
# a_id.sort()
# ids2 = [x[1] for x in a_id]
elif form['display_account'] == 'bal_solde':
if res['balance'] != 0:
result_acc.append(res)
else:
result_acc.append(res)
# if account.child_id:
# acc_id = [acc.id for acc in account.child_id]
# lst_string = ''
# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\''
# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string))
# a_id = self.cr.fetchall()
# a_id.sort()
# ids2 = [x[1] for x in a_id]
#
# result_acc += self.lines(form, ids2, done, level+1)
return result_acc
# result_acc += self.lines(form, ids2, done, level+1)
return result_acc
def _sum_credit(self):
return self.sum_credit
def _sum_credit(self):
return self.sum_credit
def _sum_debit(self):
return self.sum_debit
def _sum_debit(self):
return self.sum_debit
report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance, header=0)

View File

@ -245,11 +245,11 @@
<td><para style="P10">Balance</para></td>
</tr>
<tr>
<td><para style="P14">[[ repeatIn(lines(data['form']), 'a') ]]<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><i>[[ a['code'] or removeParentNode('tr') ]]</i></para></td>
<td><para style="P14"><font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font color="white">[[ '..'*(a['level']-1) ]]</font><font>[[ a['name'] ]]</font></para></td>
<td><para style="P3"><font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['debit']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[formatLang(a['debit']) ]]</font></para></td>
<td><para style="P3"><font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['credit']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[ formatLang(a['credit']) ]]</font></para></td>
<td><para style="P3"><font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['balance']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[ formatLang(a['balance']) ]]</font></para></td>
<td><para style="P14">[[ repeatIn(lines(data['form']), 'a') ]]<!--<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><i>[[ a['code'] or removeParentNode('tr') ]]</i>--></para></td>
<td><para style="P14"><!--<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font color="white">[[ '..'*(a['level']-1) ]]</font><font>[[ a['name'] ]]</font>--></para></td>
<td><para style="P3"><!--<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['debit']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[formatLang(a['debit']) ]]</font>--></para></td>
<td><para style="P3"><!--<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['credit']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[ formatLang(a['credit']) ]]</font>--></para></td>
<td><para style="P3"><!--<font>[[ a['level']&gt;2 and setTag('para','para',{'fontName':"Helvetica"}) ]]</font><font>[[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['balance']) ]]</font><font>[[ a['type']&lt;&gt;'view' and removeParentNode('font') ]] [[ formatLang(a['balance']) ]]</font>--></para></td>
</tr>
</blockTable>
</story>

View File

@ -25,47 +25,43 @@ from osv import osv, fields
from tools.translate import _
class account_balance_report(osv.osv_memory):
_inherit = "account.common.report"
_name = 'account.balance.report'
_description = 'Account Balance Report'
_columns = {
'company_id': fields.many2one('res.company', 'Company', required=True),
'display_account': fields.selection([('bal_all','All'), ('bal_mouvement','With movements'),
('bal_solde','With balance is not equal to 0'),
],'Display accounts'),
}
],'Display accounts', required=True),
}
_defaults = {
'display_account': 'bal_all'
}
}
def default_get(self, cr, uid, fields, context=None):
""" To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
res = {}
if 'journal_ids' in fields:# FIX me!!
res['journal_ids'] = []
return res
else:
result = super(account_balance_report, self).default_get(cr, uid, fields, context=context)
result.update({'company_id':self.pool.get('account.account').read(cr, uid, result['chart_account_id'], context=context)['company_id']})
return result
# def default_get(self, cr, uid, fields, context=None):
# """ To get default values for the object.
# @param self: The object pointer.
# @param cr: A database cursor
# @param uid: ID of the user currently logged in
# @param fields: List of fields for which we want default values
# @param context: A standard dictionary
# @return: A dictionary which of fields with values.
# """
# res = {}
# if 'journal_ids' in fields:# FIX me!!
# res['journal_ids'] = []
# return res
# else:
# result = super(account_balance_report, self).default_get(cr, uid, fields, context=context)
# result.update({'company_id':self.pool.get('account.account').read(cr, uid, result['chart_account_id'], context=context)['company_id']})
# return result
def _print_report(self, cr, uid, ids, data, query_line, context=None):
if data['model']=='ir.ui.menu':
data['ids'] = [data['form']['chart_account_id']]
data['form'].update(self.read(cr, uid, ids, ['display_account', 'company_id',])[0])
data['form']['query_get'] = query_line
data['form']['query_line'] = query_line
return { 'type': 'ir.actions.report.xml', 'report_name': 'account.account.balance', 'datas': data, 'nodestroy':True, }
account_balance_report()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2,36 +2,17 @@
<openerp>
<data>
<record id="account_report_balance_view" model="ir.ui.view">
<field name="name">Account Balance</field>
<field name="model">account.balance.report</field>
<field name="type">form</field>
<field name="inherit_id" ref="account_common_report_view" />
<field name="arch" type="xml">
<form string="Print Account Balance" >
<group width="600" height="250">
<group colspan="4" col="4">
<field name="chart_account_id" colspan="2" widget='selection'/>
<field name="fiscalyear_id"/>
<field name="filter"/>
<field name="company_id"/>
<field name="display_account"/>
</group>
<group attrs="{'invisible':[('filter','!=','filter_period')]}">
<separator string="Periods" colspan="4"/>
<field name="period_from"/>
<field name="period_to"/>
</group>
<group colspan="4" attrs="{'invisible':[('filter','!=','filter_date')]}">
<separator string="Date" colspan="4"/>
<field name="date_from"/>
<field name="date_to"/>
</group>
<group colspan="4" col="4" >
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-print" name="check_report" string="Print" type="object"/>
</group>
</group>
</form>
<field name="fiscalyear_id" position="after">
<field name="display_account"/>
<newline/>
</field>
</field>
</record>
<record id="action_account_balance_menu" model="ir.actions.act_window">
@ -43,7 +24,6 @@
<field name="view_id" ref="account_report_balance_view"/>
<field name="target">new</field>
</record>
<menuitem
icon="STOCK_PRINT"
name="Account Balance"