diff --git a/addons/account/project/report/analytic_balance.py b/addons/account/project/report/analytic_balance.py index b16a6040237..62b7c9f0a4b 100644 --- a/addons/account/project/report/analytic_balance.py +++ b/addons/account/project/report/analytic_balance.py @@ -32,6 +32,7 @@ import pooler import time from report import report_sxw + class account_analytic_balance(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(account_analytic_balance, self).__init__(cr, uid, name, context) diff --git a/addons/account/project/report/analytic_balance.rml b/addons/account/project/report/analytic_balance.rml index 6191906b446..77d52c2526c 100644 --- a/addons/account/project/report/analytic_balance.rml +++ b/addons/account/project/report/analytic_balance.rml @@ -3,6 +3,37 @@ @@ -10,65 +41,30 @@ - - + - - - - - - - - - - - + + - + - + + - + - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - @@ -76,152 +72,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - Analytic Balance - - - - - - - - - - [[ company.name ]] - - - Period from [[ data['form']['date1'] ]] - to [[ data['form']['date2'] ]] - - - Currency: [[ company.currency_id.name ]] - - - - - - - Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]] - - - - - - - Code - - - Account Name - - - Debit - - - Credit - - - Balance - - - Quantity - - - - - -
- [[ repeatIn(objects,'o') ]] - + - [[ o.code ]] [[ o.complete_name ]] + Code + + + Account Name + + + Debit + + + Credit + + + Balance + + + Quantity + + + + + + Total + + + + [[ sum_debit(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ sum_credit(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ sum_balance(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ sum_quantity(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + + + + [[ repeatIn(objects,'o') ]] + + + + [[ o.code ]] + + + [[ o.complete_name ]] + + + [[ move_sum_debit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ move_sum_credit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ move_sum_balance(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + [[ move_sum_quantity(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]] + + + + + [[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]] + [[ move_g['code'] ]] + + + [[ move_g['name'] ]] + + + [[ move_g['debit'] ]] + + + [[ move_g['credit'] ]] + + + [[ move_g['balance'] ]] + + + [[ (move_g['quantity'] or 0.0) ]] + + + + + + - - - - [[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]] - [[ move_g['code'] ]] - - - [[ move_g['name'] ]] - - - [[ '%.2f' % move_g['debit'] ]] - - - [[ '%.2f' % move_g['credit'] ]] - - - [[ '%.2f' % move_g['balance'] ]] - - - [[ '%.2f' % (move_g['quantity'] or 0.0) ]] - - - - - - - Total ([[ o.code ]]) - - - [[ '%.2f' % (move_sum_debit(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (move_sum_credit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 )]] - - - [[ '%.2f' % (move_sum_balance(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % move_sum_quantity(o.id,data['form']['date1'],data['form']['date2']) or 0.0]] - - - - +
- - - - - - - Total - - - [[ '%.2f' % (sum_debit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (sum_credit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]] - - - [[ '%.2f' % (sum_balance(objects,data['form']['date1'],data['form']['date2']) or 0.0)]] - - - [[ '%.2f' % sum_quantity(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]] - - - - - - - - -
- - + \ No newline at end of file diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 5ff60c44a18..1ecb0869876 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -71,7 +71,10 @@ class account_balance(report_sxw.rml_parse): self.cr.execute("select name from account_period where id in (%s)" % (period_ids)) res=self.cr.fetchall() for r in res: - result+=r[0]+", " + if (r == res[res.__len__()-1]): + result+=r[0]+". " + else: + result+=r[0]+", " return str(result and result[:-1]) or '' def lines(self, form, ids={}, done=None, level=1): @@ -118,6 +121,7 @@ class account_balance(report_sxw.rml_parse): 'credit': account.credit, 'balance': account.balance, 'leef': not bool(account.child_id), + 'bal_type':'', } self.sum_debit += account.debit self.sum_credit += account.credit @@ -177,6 +181,10 @@ class account_balance(report_sxw.rml_parse): r['credit']='' r['balance']='' r['leef']='' + if sum > 0.0: + r['bal_type']=" Dr." + else: + r['bal_type']=" Cr." return res or '' def date_range(self,start,end): diff --git a/addons/account/report/account_balance.rml b/addons/account/report/account_balance.rml index 462a7bd1744..0b614106551 100644 --- a/addons/account/report/account_balance.rml +++ b/addons/account/report/account_balance.rml @@ -61,15 +61,14 @@ - - + - - + + - + @@ -94,7 +93,7 @@ fontSize="8.0" /> [[ setTag('para','para',{'style':('Level'+str(a['level']))}) ]][[ (a['level']<6 and removeParentNode('font') or '... '*(a['level']-4)) ]][[ setTag('blockTable','blockTable',{'style':'TrLevel'+str(a['level'])}) ]][[ a['name'] ]] - [[ formatLang(a['debit']) and '%.2f'%a['debit'] or '']] + [[ (a['level']<4) and setTag('para','para',{'style':'P3'}) ]][[ (a['leef'] and removeParentNode('para')) or formatLang(a['debit']) and '%.2f'%a['debit'] or '0.00' ]] + [[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['debit']) and '%.2f'%a['debit'] or '0.00' ]] - [[ formatLang(a['credit']) and '%.2f'%a['credit'] or '']] + [[ (a['level']<4) and setTag('para','para',{'style':'P3'}) ]][[ (a['leef'] and removeParentNode('para')) or formatLang(a['credit']) and '%.2f'%a['credit'] or '0.00' ]] + [[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['credit']) and '%.2f'%a['credit'] or '0.00' ]] - [[ (a['level']<4) and setTag('para','para',{'style':'P3a'}) ]][[ (a['leef'] and removeParentNode('para')) or formatLang(a['balance']) and '%.2f'%a['balance'] or '' ]] - [[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['balance']) and formatLang(a['balance']) or '' ]] + [[ (a['level']<4) and setTag('para','para',{'style':'P3a'}) ]][[ (a['leef'] and removeParentNode('para')) or formatLang(a['balance']) and '%.2f'%a['balance'] or '0.00' ]] + [[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['balance']) and formatLang(a['balance']) or '0.00' ]] @@ -166,13 +167,13 @@ [[ '... '*(a['level']-3) ]][[ a['lname'] ]] - [[ formatLang(a['debit1']) and '%.2f'%a['debit1'] or '']] + [[ formatLang(a['debit1']) and '%.2f'%a['debit1'] or '0.00']] - [[ formatLang(a['credit1']) and '%.2f'%a['credit1'] or '']] + [[ formatLang(a['credit1']) and '%.2f'%a['credit1'] or '0.00']] - [[ formatLang(a['balance1']) and '%.2f'%a['balance1'] or '']] + [[ formatLang(a['balance1']) and '%.2f'%a['balance1'] or '0.00' ]] diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index 912e8396ef2..e7313354aea 100644 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.py @@ -1,9 +1,6 @@ -# -*- encoding: utf-8 -*- ############################################################################## # -# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved. -# -# $Id$ +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsability of assessing all potential @@ -30,11 +27,15 @@ import pooler import time +import re +import datetime from report import report_sxw class partner_balance(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(partner_balance, self).__init__(cr, uid, name, context) + self.date_lst = [] + self.date_lst_string = '' self.localcontext.update( { 'time': time, 'lines': self.lines, @@ -47,44 +48,138 @@ class partner_balance(report_sxw.rml_parse): 'solde_credit': self._solde_balance_credit, 'get_company': self._get_company, 'get_currency': self._get_currency, + 'comma_me' : self.comma_me, }) - + ## Compute account list one time + # + # Date Management + # + def date_range(self,start,end): + start = datetime.date.fromtimestamp(time.mktime(time.strptime(start,"%Y-%m-%d"))) + end = datetime.date.fromtimestamp(time.mktime(time.strptime(end,"%Y-%m-%d"))) + full_str_date = [] + # + r = (end+datetime.timedelta(days=1)-start).days + # + date_array = [start+datetime.timedelta(days=i) for i in range(r)] + for date in date_array: + full_str_date.append(str(date)) + return full_str_date + + # + def transform_period_into_date_array(self,data): + ## Get All Period Date + # + # If we have no period we will take all perdio in the FiscalYear. + if not data['form']['periods'][0][2] : + periods_id = self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',data['form']['fiscalyear'])]) + else: + periods_id = data['form']['periods'][0][2] + date_array = [] + for period_id in periods_id: + period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id) + date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop) + + self.date_lst = date_array + self.date_lst.sort() + + + def transform_date_into_date_array(self,data): + return_array = self.date_range(data['form']['date1'],data['form']['date2']) + self.date_lst = return_array + self.date_lst.sort() + + + + def comma_me(self,amount): + if type(amount) is float : + amount = str('%.2f'%amount) + else : + amount = str(amount) + if (amount == '0'): + return ' ' + orig = amount + new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount) + if orig == new: + return new + else: + return self.comma_me(new) + def preprocess(self, objects, data, ids): + # Transformation des date + # + # + if data['form'].has_key('fiscalyear'): + self.transform_period_into_date_array(data) + else: + self.transform_date_into_date_array(data) + ## + self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\'' + ## Compute Code account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', - context={'fiscalyear': data['form']['fiscalyear']}) - self.cr.execute('SELECT DISTINCT line.partner_id ' \ - 'FROM account_move_line AS line, account_account AS account ' \ - 'WHERE line.partner_id IS NOT NULL ' \ - 'AND line.date >= %s ' \ - 'AND line.date <= %s ' \ - 'AND ' + line_query + ' ' \ - 'AND line.account_id = account.id ' \ - 'AND account.company_id = %d ' \ - 'AND account.active', - (data['form']['date1'], data['form']['date2'], - data['form']['company_id'])) - new_ids = [id for (id,) in self.cr.fetchall()] + # + if (data['form']['result_selection'] == 'customer' ): + self.ACCOUNT_TYPE = "('receivable')" + elif (data['form']['result_selection'] == 'supplier'): + self.ACCOUNT_TYPE = "('payable')" + else: + self.ACCOUNT_TYPE = "('payable','receivable')" + # self.cr.execute('SELECT a.id ' \ 'FROM account_account a ' \ 'LEFT JOIN account_account_type t ' \ 'ON (a.type = t.code) ' \ 'WHERE t.partner_account = TRUE ' \ 'AND a.company_id = %d ' \ + 'AND a.type IN ' + self.ACCOUNT_TYPE + " " \ 'AND a.active', (data['form']['company_id'],)) self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()]) - self.partner_ids = ','.join(map(str, new_ids)) - objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids) - super(partner_balance, self).preprocess(objects, data, new_ids) + + super(partner_balance, self).preprocess(objects, data, ids) + + def lines(self,data): - def lines(self): - if not self.partner_ids: - return [] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + full_account = [] + result_tmp = 0.0 + + # + # + # + if data['form']['soldeinit'] : + self.cr.execute( + "SELECT p.ref, p.name,l.account_id,ac.name as account_name,ac.code as code , sum(debit) as debit, sum(credit) as credit, " \ + "CASE WHEN sum(debit) > sum(credit) " \ + "THEN sum(debit) - sum(credit) " \ + "ELSE 0 " \ + "END AS sdebit, " \ + "CASE WHEN sum(debit) < sum(credit) " \ + "THEN sum(credit) - sum(debit) " \ + "ELSE 0 " \ + "END AS scredit, " \ + "(SELECT sum(debit-credit) " \ + "FROM account_move_line l " \ + "WHERE partner_id = p.id " \ + "AND date < %s " \ + "AND blocked = TRUE AND l.reconcile_id IS NULL " \ + ") AS enlitige " \ + "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ + "JOIN account_account ac ON (l.account_id = ac.id)" \ + "WHERE " \ +# " account_id IN (" + self.account_ids + ") " \ + "l.date < %s AND l.reconcile_id IS NULL " \ + "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ + "ORDER BY l.account_id,p.name", + (self.date_lst[0],self.date_lst[0])) + res = self.cr.dictfetchall() + + for r in res: + full_account.append(r) + # + # + # self.cr.execute( - "SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \ + "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \ "CASE WHEN sum(debit) > sum(credit) " \ "THEN sum(debit) - sum(credit) " \ "ELSE 0 " \ @@ -96,129 +191,315 @@ class partner_balance(report_sxw.rml_parse): "(SELECT sum(debit-credit) " \ "FROM account_move_line l " \ "WHERE partner_id = p.id " \ - "AND date >= %s " \ - "AND date <= %s " \ + "AND l.date IN (" + self.date_lst_string + ") " \ "AND blocked = TRUE " \ - "AND " + line_query + " " \ ") AS enlitige " \ "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ - "AND l.date >= %s " \ - "AND l.date <= %s " \ - "AND " + line_query + " " \ - "GROUP BY p.id, p.ref, p.name " \ - "ORDER BY p.ref, p.name", - (self.datas['form']['date1'], self.datas['form']['date2'], - self.datas['form']['date1'], self.datas['form']['date2'])) + "JOIN account_account ac ON (l.account_id = ac.id)" \ + "WHERE " \ +# " account_id IN (" + self.account_ids + ") " \ + " l.date IN (" + self.date_lst_string + ") " \ + "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ + "ORDER BY l.account_id,p.name") res = self.cr.dictfetchall() - return res + print"=====res=====",res + for r in res: + full_account.append(r) + + ## We will now compute Total + return self._add_subtotal(full_account) - def _sum_debit(self): + def _add_subtotal(self,cleanarray): + i=0 + completearray = [] + tot_debit = 0.0 + tot_credit = 0.0 + tot_scredit = 0.0 + tot_sdebit = 0.0 + tot_enlitige = 0.0 + for r in cleanarray: + # For the first element we always add the line + # type = 1 is the line is the first of the account + # type = 2 is an other line of the account + if i==0: + # We add the first as the header + # + ## + new_header = {} + new_header['ref'] = '' + new_header['name'] = r['account_name'] + new_header['code'] = r['code'] + new_header['debit'] = 0 + new_header['credit'] = 0 + new_header['scredit'] = 0 + new_header['sdebit'] = 0 + new_header['enlitige'] = 0 + new_header['balance'] = 0 + new_header['type'] = 3 + ## + completearray.append(new_header) + # + r['type'] = 1 + r['balance'] = float(r['sdebit']) - float(r['scredit']) + completearray.append(r) + # + tot_debit = r['debit'] + tot_credit = r['credit'] + tot_scredit = r['scredit'] + tot_sdebit = r['sdebit'] + tot_enlitige = (r['enlitige'] or 0.0) + # + else: + if cleanarray[i]['account_id'] <> cleanarray[i-1]['account_id']: + ## + new_tot = {} + new_tot['ref'] = 'Total' + new_tot['name'] = cleanarray[i-1]['account_name'] + new_tot['code'] = cleanarray[i-1]['code'] + + new_tot['debit'] = tot_debit + new_tot['credit'] = tot_credit + new_tot['scredit'] = tot_scredit + new_tot['sdebit'] = tot_sdebit + new_tot['enlitige'] = tot_enlitige + new_tot['balance'] = float(tot_sdebit) - float(tot_scredit) + new_tot['type'] = 3 + ## + completearray.append(new_tot) + + # we reset the counter + tot_debit = r['debit'] + tot_credit = r['credit'] + tot_scredit = r['scredit'] + tot_sdebit = r['sdebit'] + tot_enlitige = (r['enlitige'] or 0.0) + # + ## + new_header = {} + new_header['ref'] = '' + new_header['name'] = r['account_name'] + new_header['code'] = r['code'] + new_header['debit'] = 0 + new_header['credit'] = 0 + new_header['scredit'] = 0 + new_header['sdebit'] = 0 + new_header['enlitige'] = 0 + new_header['balance'] = 0 + new_header['type'] = 3 + ## + ## + completearray.append(new_header) + ## + # + r['type'] = 1 + # + r['balance'] = float(r['sdebit']) - float(r['scredit']) + # + completearray.append(r) + if cleanarray[i]['account_id'] == cleanarray[i-1]['account_id']: + # we reset the counter + tot_debit = tot_debit + r['debit'] + tot_credit = tot_credit + r['credit'] + tot_scredit = tot_scredit + r['scredit'] + tot_sdebit = tot_sdebit + r['sdebit'] + tot_enlitige = tot_enlitige + (r['enlitige'] or 0.0) + # + r['type'] = 2 + # + r['balance'] = float(r['sdebit']) - float(r['scredit']) + # + completearray.append(r) + i = i + 1 + return completearray + + + def _sum_debit(self,data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, - obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + result_tmp = 0.0 + # + # + if data['form']['soldeinit'] : + self.cr.execute( + 'SELECT sum(debit) ' \ + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.reconcile_id IS NULL ' \ + 'AND date < %s ', + (self.date_lst[0],)) + result_tmp = float(self.cr.fetchone()[0] or 0.0) + # + # self.cr.execute( 'SELECT sum(debit) ' \ - 'FROM account_move_line ' \ - 'WHERE partner_id IN (' + self.partner_ids + ') ' \ - 'AND account_id IN (' + self.account_ids + ') ' \ - 'AND date >=%s ' \ - 'AND date <= %s ' \ - 'AND ' + line_query, - (self.datas['form']['date1'], self.datas['form']['date2'])) - return self.cr.fetchone()[0] or 0.0 + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.date IN (' + self.date_lst_string + ') ' ) + result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) + + return result_tmp - def _sum_credit(self): + def _sum_credit(self,data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, - obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + + result_tmp = 0.0 + # + # + if data['form']['soldeinit'] : + self.cr.execute( + 'SELECT sum(credit) ' \ + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.reconcile_id IS NULL ' \ + 'AND date < %s ' , + (self.date_lst[0],)) + result_tmp = float(self.cr.fetchone()[0] or 0.0) + # + # self.cr.execute( 'SELECT sum(credit) ' \ - 'FROM account_move_line ' \ - 'WHERE partner_id IN (' + self.partner_ids + ') ' \ - 'AND account_id IN (' + self.account_ids + ') ' \ - 'AND date >= %s ' \ - 'AND date <= %s ' \ - 'AND ' + line_query, - (self.datas['form']['date1'], self.datas['form']['date2'])) - return self.cr.fetchone()[0] or 0.0 + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.date IN (' + self.date_lst_string + ') ' ) + + result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) + + return result_tmp - def _sum_litige(self): + def _sum_litige(self,data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, - obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + result_tmp = 0.0 + + # + # + if data['form']['soldeinit'] : + self.cr.execute( + 'SELECT sum(debit-credit) ' \ + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.reconcile_id IS NULL ' \ + 'AND date < %s ' \ + 'AND blocked=TRUE ' , + (self.date_lst[0],)) + result_tmp = float(self.cr.fetchone()[0] or 0.0) + # + # self.cr.execute( 'SELECT sum(debit-credit) ' \ - 'FROM account_move_line ' \ - 'WHERE partner_id IN (' + self.partner_ids + ') ' \ - 'AND account_id IN (' + self.account_ids + ') ' \ - 'AND date >= %s ' \ - 'AND date <= %s ' \ - 'AND blocked=TRUE ' \ - 'AND ' + line_query, - (self.datas['form']['date1'], self.datas['form']['date2'])) - return self.cr.fetchone()[0] or 0.0 + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' l.date IN (' + self.date_lst_string + ') ' \ + 'AND blocked=TRUE ' ) + result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) + + return result_tmp - def _sum_sdebit(self): + def _sum_sdebit(self,data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, - obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + result_tmp = 0.0 + + # + # + if data['form']['soldeinit'] : + self.cr.execute( + 'SELECT CASE WHEN sum(debit) > sum(credit) ' \ + 'THEN sum(debit) - sum(credit) ' \ + 'ELSE 0 ' \ + 'END ' \ + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' date < %s ' \ + 'AND reconcile_id IS NULL ' \ + 'GROUP BY partner_id', + (self.date_lst[0],)) + + if self.cr.fetchone() != None: + result_tmp = float(self.cr.fetchone()[0]) + else: + result_tmp = 0.0 + # + # self.cr.execute( 'SELECT CASE WHEN sum(debit) > sum(credit) ' \ - 'THEN sum(debit - credit) ' \ + 'THEN sum(debit) - sum(credit) ' \ 'ELSE 0 ' \ 'END ' \ - 'FROM account_move_line ' \ - 'WHERE partner_id IN (' + self.partner_ids + ') ' \ - 'AND account_id IN (' + self.account_ids + ') ' \ - 'AND date >= %s ' \ - 'AND date <= %s ' \ - 'AND ' + line_query + ' ' \ - 'GROUP BY partner_id', - (self.datas['form']['date1'], self.datas['form']['date2'])) - return self.cr.fetchone()[0] or 0.0 + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + 'l.date IN (' + self.date_lst_string + ') ' \ + 'GROUP BY partner_id') + + if self.cr.fetchone() != None: + result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) + else: + result_tmp = 0.0 + return result_tmp - def _sum_scredit(self): + def _sum_scredit(self,data): if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') - line_query = account_move_line_obj._query_get(self.cr, self.uid, - obj='account_move_line', - context={'fiscalyear': self.datas['form']['fiscalyear'],'state':self.datas['form']['state']}) + result_tmp = 0.0 + # + # + if data['form']['soldeinit'] : + self.cr.execute( + 'SELECT CASE WHEN sum(debit) < sum(credit) ' \ + 'THEN sum(credit) - sum(debit) ' \ + 'ELSE 0 ' \ + 'END ' \ + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + ' date <= %s ' \ + 'AND l.reconcile_id IS NULL ' \ + 'GROUP BY partner_id', + (self.date_lst[0],)) + if self.cr.fetchone() != None: + result_tmp = float(self.cr.fetchone()[0]) + else: + result_tmp = 0.0 + # + # self.cr.execute( 'SELECT CASE WHEN sum(debit) < sum(credit) ' \ - 'THEN sum(credit - debit) ' \ + 'THEN sum(credit) - sum(debit) ' \ 'ELSE 0 ' \ 'END ' \ - 'FROM account_move_line ' \ - 'WHERE partner_id IN (' + self.partner_ids + ') ' \ - 'AND account_id IN (' + self.account_ids + ') ' \ - 'AND date >= %s ' \ - 'AND date <= %s ' \ - 'AND ' + line_query + ' ' \ - 'GROUP BY partner_id', - (self.datas['form']['date1'], self.datas['form']['date2'])) - return self.cr.fetchone()[0] or 0.0 - - def _solde_balance_debit(self): - debit, credit = self._sum_debit(), self._sum_credit() + 'FROM account_move_line AS l ' \ + 'WHERE ' \ +# ' account_id IN (' + self.account_ids + ') ' \ + 'l.date IN (' + self.date_lst_string + ') ' \ + 'GROUP BY partner_id') + + if self.cr.fetchone() != None: + result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) + else: + result_tmp = 0.0 + + return result_tmp + + def _solde_balance_debit(self,data): + debit, credit = self._sum_debit(data), self._sum_credit(data) return debit > credit and debit - credit - def _solde_balance_credit(self): - debit, credit = self._sum_debit(), self._sum_credit() + def _solde_balance_credit(self,data): + debit, credit = self._sum_debit(data), self._sum_credit(data) return credit > debit and credit - debit def _get_company(self, form): @@ -228,9 +509,5 @@ class partner_balance(report_sxw.rml_parse): return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name report_sxw.report_sxw('report.account.partner.balance', 'res.partner', - 'addons/account/report/partner_balance.rml',parser=partner_balance, + 'account/report/partner_balance.rml',parser=partner_balance, header=False) - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/account/report/partner_balance.rml b/addons/account/report/partner_balance.rml index c0d9ea67a2c..5e99323bb09 100644 --- a/addons/account/report/partner_balance.rml +++ b/addons/account/report/partner_balance.rml @@ -1,8 +1,37 @@ - + @@ -13,55 +42,24 @@ - - - - - - + + + + + + - - - - - - - - - - - - - - - - + - + + + - - - - - - - - - - - - - - - - - - - + @@ -70,197 +68,63 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - Third party balance - - - From [[ formatLang(data['form']['date1'], date=True) ]] - to [[ formatLang(data['form']['date2'], date=True) ]] - - - - - [[ get_company(data['form']) ]] - - - - - - - - Currency: [[ get_currency(data['form']) ]] - - - - - - - Printing date: [[ formatLang(time.strftime('%Y-%m-%d'), date=True) ]] at [[ time.strftime('%H:%M:%S') ]] - - - - - - - Account number - - - Account name - - - Transactions - - - Balances - - - In dispute - - - - - - - - - - - - Debit - - - Credit - - - Debit - - - Credit - - - - - - - - - - - - - - - [[ repeatIn(lines(), 'a') ]][[ a['ref'] ]] - - - [[ a['name'] ]] - - - [[ formatLang(a['debit']) ]] - - - [[ formatLang(a['credit']) ]] - - - [[ formatLang(a['sdebit']) ]] - - - [[ formatLang(a['scredit']) ]] - - - [[ formatLang((a['enlitige'] or 0.0)) ]] - - - - - - - + + Grand total - [[ formatLang(sum_debit()) ]] + [[ comma_me(sum_debit(data)) ]] - [[ formatLang(sum_credit()) ]] + [[ comma_me(sum_credit(data)) ]] - [[ formatLang(sum_sdebit()) ]] + [[ comma_me(sum_sdebit(data)) ]] - [[ formatLang(sum_scredit()) ]] + [[ comma_me(sum_scredit(data)) ]] - [[ formatLang(sum_litige()) ]] + [[ comma_me(sum_litige(data)) ]] @@ -278,10 +142,10 @@ - [[ formatLang(solde_debit()) ]] + [[ comma_me(solde_debit(data)) ]] - [[ formatLang(solde_credit()) ]] + [[ comma_me(solde_credit(data)) ]] @@ -290,10 +154,55 @@ + + + + Code + + + Partner name + + + Débit + + + Crédit + + + Balance + + + In dispute + + + + + [[ repeatIn(lines(data), 'a') ]][[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ a['ref'] ]] + + + [[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ a['type']==3 and a['code'] ]] [[ a['name'] ]] + + + [[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['debit']) ]] + + + [[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['credit']) ]] + + + [[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['balance']) ]] + + + [[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['enlitige']) ]] + + + + + + + - diff --git a/addons/account/report/tax_report.rml b/addons/account/report/tax_report.rml index cd8ee532948..50dd5a89dda 100755 --- a/addons/account/report/tax_report.rml +++ b/addons/account/report/tax_report.rml @@ -102,6 +102,15 @@ + + + + + + + + + @@ -134,6 +143,18 @@ + + + +
+
''' + + dates_form = '''
- -