=== modified file 'account/report/__init__.py' --- account/report/__init__.py 2009-01-04 22:12:50 +0000 +++ account/report/__init__.py 2010-07-15 12:56:49 +0000 @@ -31,7 +31,6 @@ import overdue import aged_trial_balance import tax_report -import general_ledger_landscape import account_tax_code # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === modified file 'account/report/general_ledger.py' --- account/report/general_ledger.py 2010-02-18 09:50:28 +0000 +++ account/report/general_ledger.py 2010-07-15 21:33:20 +0000 @@ -1,5 +1,5 @@ -# -*- encoding: utf-8 -*- -############################################################################## + # -*- coding: utf-8 -*- + ############################################################################## # # Copyright (c) 2005-2006 CamptoCamp # @@ -27,39 +27,33 @@ ############################################################################## import time -from mx.DateTime import * + from report import report_sxw -import xml import rml_parse import pooler class general_ledger(rml_parse.rml_parse): _name = 'report.account.general.ledger' - - - def set_context(self, objects, data, ids, report_type = None): - ## + def set_context(self, objects, data, ids, report_type=None): self.borne_date = self.get_min_date(data['form']) - ## - new_ids = [] - if (data['model'] == 'account.account'): - new_ids = ids - else: - new_ids.append(data['form']['Account_list']) - - objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) - - super(general_ledger, self).set_context(objects, data, new_ids, report_type) - - def __init__(self, cr, uid, name, context): + new_ids = ids + if (data['model'] == 'ir.ui.menu'): + new_ids = [data['form']['Account_list']] + self.sortby = data['form']['sortbydate'] + objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids) + super(general_ledger, self).set_context(objects, data, new_ids, report_type=report_type) + + def __init__(self, cr, uid, name, context=None): + if context is None: + context = {} super(general_ledger, self).__init__(cr, uid, name, context=context) self.date_borne = {} self.query = "" self.child_ids = "" self.tot_currency = 0.0 - self.period_sql = "" self.sold_accounts = {} + self.sortby = 'sort_date' self.localcontext.update( { 'time': time, 'lines': self.lines, @@ -70,44 +64,11 @@ 'sum_credit': self._sum_credit, 'sum_solde': self._sum_solde, 'get_children_accounts': self.get_children_accounts, - 'sum_currency_amount_account': self._sum_currency_amount_account + 'sum_currency_amount_account': self._sum_currency_amount_account, }) self.context = context - def _calc_contrepartie(self,cr,uid,ids, context={}): - result = {} - #for id in ids: - # result.setdefault(id, False) - - for account_line in self.pool.get('account.move.line').browse(cr, uid, ids, context): - # For avoid long text in the field we will limit it to 5 lines - # - # - # - result[account_line.id] = ' ' - num_id_move = str(account_line.move_id.id) - num_id_line = str(account_line.id) - account_id = str(account_line.account_id.id) - # search the basic account - # We have the account ID we will search all account move line from now until this time - # We are in the case of we are on the top of the account move Line - cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\ - where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id ) - res_mv = cr.dictfetchall() - # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line - if (len(res_mv) >=1): - concat = '' - rup_id = 0 - for move_rest in res_mv: - concat = concat + move_rest['code_rest'] + '|' - result[account_line.id] = concat - if rup_id >5: - # we need to stop the computing and to escape but before we will add "..." - result[account_line.id] = concat + '...' - break - rup_id+=1 - return result - - def get_min_date(self,form): + + def get_min_date(self, form): ## Get max born from account_fiscal year # @@ -123,37 +84,46 @@ periods = form['periods'][0][2] 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 + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id in %s """ - sqlargs = (form['fiscalyear'],) + if form['fiscalyear']: + f_ids = [form['fiscalyear']] + else: + f_ids = self.pool.get('account.fiscalyear').search(self.cr, self.uid, [('state', '=', 'draft')]) + + sqlargs = (tuple(f_ids),) + 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() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] + elif form['state'] == 'bydate': borne_min = form['date_from'] borne_max = form['date_to'] + elif form['state'] == 'all': periods = form['periods'][0][2] + 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 + 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'],) + if form['fiscalyear']: + f_ids = [form['fiscalyear']] + else: + f_ids = self.pool.get('account.fiscalyear').search(self.cr, self.uid, [('state', '=', 'draft')]) + sqlargs = (tuple(f_ids),) + 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 + 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) @@ -162,14 +132,15 @@ period_max = res[0]['stop_date'] date_min = form['date_from'] date_max = form['date_to'] - if period_min=',child_account.id)], - context=ctx)) <> 0 : - res.append(child_account) - ## + + eval_state_operand = {'bal_all':'>=','bal_mouvement':'=','bal_solde':'='} + state_acc = form['display_account'] + if child_account.type != 'view' \ + and len(self.pool.get('account.move.line').search(self.cr, self.uid, [('account_id',eval_state_operand[state_acc],child_account.id)], context=ctx)) <> 0 : + if (state_acc in ['bal_mouvement','bal_all']) or (state_acc == 'bal_solde' and sold_account <> 0.0): + res.append(child_account) + if not len(res): - return [account] else: ## We will now compute solde initiaux + if not form['soldeinit']: + return res for move in res: SOLDEINIT = "SELECT SUM(l.debit) AS sum_debit,"\ " SUM(l.credit) AS sum_credit "\ "FROM account_move_line l "\ "WHERE l.account_id = %s "\ "AND l.date < %s AND l.date > %s" - self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'],self.borne_date['min_date'])) + self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'], self.borne_date['min_date'])) resultat = self.cr.dictfetchall() - if resultat[0] : - if resultat[0]['sum_debit'] == None: - sum_debit = 0 - else: - sum_debit = resultat[0]['sum_debit'] - if resultat[0]['sum_credit'] == None: - sum_credit = 0 - else: - sum_credit = resultat[0]['sum_credit'] - - move.init_credit = sum_credit - move.init_debit = sum_debit - + if resultat[0]: + move.init_credit = resultat[0]['sum_credit'] or 0 + move.init_debit = resultat[0]['sum_debit'] or 0 else: move.init_credit = 0 move.init_debit = 0 - - return res def lines(self, account, form): - inv_types = { - 'out_invoice': 'CI: ', - 'in_invoice': 'SI: ', - 'out_refund': 'OR: ', - 'in_refund': 'SR: ', - } + """ Return all the account_move_line of account with their account code counterparts """ + # First compute all counterpart strings for every move_id where this account appear. + # Currently, the counterpart info is used only in landscape mode + sql = """ + SELECT m1.move_id, + array_to_string(ARRAY(SELECT DISTINCT a.code FROM account_move_line m2 LEFT JOIN account_account a ON (m2.account_id=a.id) WHERE m2.move_id = m1.move_id AND m2.account_id<>%%s), ', ') AS counterpart + FROM (SELECT move_id FROM account_move_line l WHERE %s AND l.account_id = %%s GROUP BY move_id) m1 + """ % self.query + self.cr.execute(sql, (account.id, account.id)) + counterpart_res = self.cr.dictfetchall() + counterpart_accounts = {} + for i in counterpart_res: + counterpart_accounts[i['move_id']]=i['counterpart'] + del counterpart_res - if form['sortbydate'] == 'sort_date': - sorttag = 'l.date' + # Then select all account_move_line of this account + if self.sortby == 'sort_date': + sql_sort = 'l.date' else: - sorttag = 'j.code' + sql_sort = 'j.code' sql = """ - SELECT l.id, l.date, j.code,c.code AS currency_code,l.amount_currency,l.ref, l.name , COALESCE(l.debit,0) as debit, COALESCE(l.credit,0) as credit, l.period_id - FROM account_move_line as l - LEFT JOIN res_currency c on (l.currency_id=c.id) - JOIN account_journal j on (l.journal_id=j.id) - AND account_id = %%s - AND %s - WHERE l.date<=%%s - AND l.date>=%%s - ORDER by %s""" % (self.query, sorttag) - - self.cr.execute(sql, (account.id, self.date_borne['max_date'], self.date_borne['min_date'],)) - + SELECT l.id, l.date, j.code, l.amount_currency,l.ref, l.name, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, l.period_id, l.partner_id, + m.name AS move_name, m.id AS move_id, + c.code AS currency_code, + i.id AS invoice_id, i.type AS invoice_type, i.number AS invoice_number, + p.name AS partner_name + FROM account_move_line l + LEFT JOIN account_move m on (l.move_id=m.id) + LEFT JOIN res_currency c on (l.currency_id=c.id) + LEFT JOIN res_partner p on (l.partner_id=p.id) + LEFT JOIN account_invoice i on (m.id =i.move_id) + JOIN account_journal j on (l.journal_id=j.id) + WHERE %s AND l.account_id = %%s AND l.date<=%%s AND l.date>=%%s ORDER by %s + """ % (self.query, sql_sort) + self.cr.execute(sql, (account.id,self.date_borne['max_date'], self.date_borne['min_date'])) res = self.cr.dictfetchall() - sum = 0.0 + account_sum = 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') + inv_types = { 'out_invoice': 'CI', 'in_invoice': 'SI', 'out_refund': 'OR', 'in_refund': 'SR', } + for l in res: - line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id']) - l['move'] = line.move_id.name - self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id)) - tmpres = self.cr.dictfetchall() - if len(tmpres) > 0 : - inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id']) - l['ref'] = inv_types[inv.type] + ': '+str(inv.number) - if line.partner_id : - l['partner'] = line.partner_id.name - else : - l['partner'] = '' - sum = l['debit'] - l ['credit'] -# c = time.strptime(l['date'],"%Y-%m-%d") -# l['date'] = time.strftime("%d-%m-%Y",c) - l['progress'] = sum - l['line_corresp'] = self._calc_contrepartie(self.cr,self.uid,[l['id']])[l['id']] + l['move'] = l['move_name'] + if l['invoice_id']: + l['ref'] = '%s: %s'%(inv_types[l['invoice_type']], l['invoice_number']) + l['partner'] = l['partner_name'] or '' + account_sum = l['debit'] - l['credit'] + l['progress'] = account_sum + l['line_corresp'] = counterpart_accounts[l['move_id']] # Modification du amount Currency - if (l['credit'] > 0): + if l['credit'] > 0: if l['amount_currency'] != None: l['amount_currency'] = abs(l['amount_currency']) * -1 - - # if l['amount_currency'] != None: self.tot_currency = self.tot_currency + l['amount_currency'] return res + def _sum_amount_account(self, acc_id, select_statement): + self.cr.execute("SELECT " + select_statement + " "\ + "FROM account_move_line l "\ + "WHERE l.account_id = %s AND %s "%(acc_id, self.query)) + + return self.cr.fetchone()[0] or 0.0 + def _sum_debit_account(self, account, form): - - self.cr.execute("SELECT sum(debit) "\ - "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, self.query)) - ## Add solde init to the result - # - sum_debit = self.cr.fetchone()[0] or 0.0 + sum_debit = self._sum_amount_account(account.id, "sum(debit)") if form.get('soldeinit', False): sum_debit += account.init_debit - # - ## return sum_debit def _sum_credit_account(self, account, form): - - self.cr.execute("SELECT sum(credit) "\ - "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) - ## Add solde init to the result - # - sum_credit = self.cr.fetchone()[0] or 0.0 + sum_credit = self._sum_amount_account(account.id, "sum(credit)") if form.get('soldeinit', False): sum_credit += account.init_credit - # - ## - return sum_credit def _sum_solde_account(self, account, form): - self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ - "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) - sum_solde = self.cr.fetchone()[0] or 0.0 + sum_solde = self._sum_amount_account(account.id, "(sum(debit) - sum(credit)) as tot_solde ") if form.get('soldeinit', False): sum_solde += account.init_debit - account.init_credit - return sum_solde + def _sum_amount(self, select_statement): + if not self.ids: + return 0.0 + self.cr.execute("SELECT " + select_statement + " "\ + "FROM account_move_line l "\ + "WHERE l.account_id IN %s AND "+self.query, + (tuple(self.child_ids),)) + res = self.cr.fetchone()[0] or 0.0 + return res + def _sum_debit(self, form): - if not self.ids: - return 0.0 - self.cr.execute("SELECT sum(debit) "\ - "FROM account_move_line l "\ - "WHERE l.account_id in %s AND "+self.query, - (tuple(self.child_ids),)) - sum_debit = self.cr.fetchone()[0] or 0.0 - return sum_debit + return self._sum_amount("sum(debit)") def _sum_credit(self, form): - if not self.ids: - return 0.0 - self.cr.execute("SELECT sum(credit) "\ - "FROM account_move_line l "\ - "WHERE l.account_id in %s AND "+self.query, - (tuple(self.child_ids),)) - ## Add solde init to the result - # - sum_credit = self.cr.fetchone()[0] or 0.0 - return sum_credit + return self._sum_amount("sum(credit)") def _sum_solde(self, form): - if not self.ids: - return 0.0 - self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ - "FROM account_move_line l "\ - "WHERE l.account_id in %s AND "+self.query, - (tuple(self.child_ids),)) - sum_solde = self.cr.fetchone()[0] or 0.0 - return sum_solde + return self._sum_amount("(sum(debit) - sum(credit)) as tot_solde") def _set_get_account_currency_code(self, account_id): self.cr.execute("SELECT c.code as code "\ "FROM res_currency c,account_account as ac "\ "WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id)) result = self.cr.fetchone() - if result: - self.account_currency = result[0] - else: - self.account_currency = False + self.account_currency = result and result[0] or False def _sum_currency_amount_account(self, account, form): self._set_get_account_currency_code(account.id) @@ -415,6 +331,7 @@ currency_total = self.tot_currency = 0.0 return currency_total - report_sxw.report_sxw('report.account.general.ledger', 'account.account', 'addons/account/report/general_ledger.rml', parser=general_ledger, header=False) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +report_sxw.report_sxw('report.account.general.ledger_landscape', 'account.account', 'addons/account/report/general_ledger_landscape.rml', parser=general_ledger, header=False) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file === modified file 'account/report/general_ledger.rml' --- account/report/general_ledger.rml 2009-06-09 23:24:24 +0000 +++ account/report/general_ledger.rml 2010-07-15 21:30:48 +0000 @@ -105,7 +105,7 @@
[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] + [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] @@ -156,7 +156,7 @@
[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] + [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] === modified file 'account/report/general_ledger_landscape.rml' --- account/report/general_ledger_landscape.rml 2009-11-20 05:26:20 +0000 +++ account/report/general_ledger_landscape.rml 2010-07-15 21:32:18 +0000 @@ -104,7 +104,7 @@ [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] + [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] @@ -165,7 +165,7 @@ [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] + [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]]