From 470916f5d65c81bab4e149301f34513bd44ccebb Mon Sep 17 00:00:00 2001 From: "qdp-launchpad@tinyerp.com" <> Date: Tue, 6 Jul 2010 11:32:31 +0200 Subject: [PATCH] account: account balance report improvement (not yet finished) bzr revid: qdp-launchpad@tinyerp.com-20100706093231-n3zj7v8nq42aujuy --- addons/account/account_move_line.py | 1 + addons/account/report/account_balance.py | 292 +++++++++--------- addons/account/report/account_balance.rml | 10 +- .../account/wizard/account_balance_report.py | 50 ++- .../wizard/account_balance_report_view.xml | 32 +- 5 files changed, 178 insertions(+), 207 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 0bc9e476601..2844ed48f10 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -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 = [] diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index f5d57ecd8f7..e3b6b946300 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -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) diff --git a/addons/account/report/account_balance.rml b/addons/account/report/account_balance.rml index f10b66f0a8d..2b37b553075 100644 --- a/addons/account/report/account_balance.rml +++ b/addons/account/report/account_balance.rml @@ -245,11 +245,11 @@ Balance - [[ repeatIn(lines(data['form']), 'a') ]][[ a['level']>2 and setTag('para','para',{'fontName':"Helvetica"}) ]][[ a['code'] or removeParentNode('tr') ]] - [[ a['level']>2 and setTag('para','para',{'fontName':"Helvetica"}) ]][[ '..'*(a['level']-1) ]][[ a['name'] ]] - [[ a['level']>2 and setTag('para','para',{'fontName':"Helvetica"}) ]][[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['debit']) ]][[ a['type']<>'view' and removeParentNode('font') ]] [[formatLang(a['debit']) ]] - [[ a['level']>2 and setTag('para','para',{'fontName':"Helvetica"}) ]][[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['credit']) ]][[ a['type']<>'view' and removeParentNode('font') ]] [[ formatLang(a['credit']) ]] - [[ a['level']>2 and setTag('para','para',{'fontName':"Helvetica"}) ]][[ a['type']=='view' and removeParentNode('font') ]][[ formatLang(a['balance']) ]][[ a['type']<>'view' and removeParentNode('font') ]] [[ formatLang(a['balance']) ]] + [[ repeatIn(lines(data['form']), 'a') ]] + + + + diff --git a/addons/account/wizard/account_balance_report.py b/addons/account/wizard/account_balance_report.py index 0ba229398b3..8d826173ae0 100644 --- a/addons/account/wizard/account_balance_report.py +++ b/addons/account/wizard/account_balance_report.py @@ -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: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/account_balance_report_view.xml b/addons/account/wizard/account_balance_report_view.xml index bcfbc1c2b83..6448b3078fd 100644 --- a/addons/account/wizard/account_balance_report_view.xml +++ b/addons/account/wizard/account_balance_report_view.xml @@ -2,36 +2,17 @@ + Account Balance account.balance.report form + -
- - - - - - - - - - - - - - - - - - - -