diff --git a/addons/.project.moved b/addons/.project.moved new file mode 100644 index 00000000000..45b85705360 --- /dev/null +++ b/addons/.project.moved @@ -0,0 +1,17 @@ + + + new-report-apa + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/addons/.pydevproject b/addons/.pydevproject new file mode 100644 index 00000000000..78259a9c3db --- /dev/null +++ b/addons/.pydevproject @@ -0,0 +1,6 @@ + + + + +python 2.4 + diff --git a/addons/account/account.py b/addons/account/account.py index 3dbb1877679..8374ba3e5e8 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -141,7 +141,9 @@ class account_account(osv.osv): if context is None: context = {} pos = 0 + while pos 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) + else: + result_acc.append(res) + res1 = self.moveline(form, account.id,res['level']) + if res1: + for r in res1: + result_acc.append(r) + if account.code=='0': + result_acc.pop(-1) + if account.child_id: + ids2 = [(x.code,x.id) for x in account.child_id] + ids2.sort() + result_acc += self.lines(form, [x[1] for x in ids2], done, level+1) + return result_acc + + def moveline(self,form,ids,level): + res={} + self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\'' + self.cr.execute( + "SELECT l.id as lid,l.date,j.code as jname, l.ref, l.name as lname, l.debit as debit1, l.credit as credit1 " \ + "FROM account_move_line l " \ + "LEFT JOIN account_journal j " \ + "ON (l.journal_id = j.id) " \ + "WHERE l.account_id = '"+str(ids)+"' " \ + "AND l.date IN (" + self.date_lst_string + ") " \ + "ORDER BY l.id") + res = self.cr.dictfetchall() + sum = 0.0 + for r in res: + sum = r['debit1'] - r['credit1'] + r['balance1'] = sum + r['id'] ='' + r['code']= '' + r['name']='' + r['level']=level + r['debit']='' + r['credit']='' + r['balance']='' + r['leef']='' + return res or '' + + 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,form): + ## Get All Period Date + if not form['periods'][0][2] : + periods_id = self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',form['fiscalyear'])]) + else: + periods_id = 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,form): + return_array = self.date_range(form['date_from'],form['date_to']) + self.date_lst = return_array + self.date_lst.sort() + + def _sum_credit(self): + return self.sum_credit + + 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=2) - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/account/report/account_balance.rml b/addons/account/report/account_balance.rml index b52a644cdd5..462a7bd1744 100644 --- a/addons/account/report/account_balance.rml +++ b/addons/account/report/account_balance.rml @@ -2,116 +2,91 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + - - - + + - - - - - - - - - - - - - - + - - + - - - - - - - - + + + + + + + + + + + + - + - + - + + - + + - - - - - - - - - - - + - + + + + + + - - - - + + - - Account Balance - + + + + [[ get_fiscalyear(data['form']) or removeParentNode('tr') ]]: + [[ get_periods(data['form']) or removeParentNode('tr') ]] + + + -[[ get_fiscalyear(data['form']) ]]: [[ get_periods(data['form']) ]] - - - - + Code @@ -166,25 +140,45 @@ Balance - - [[ repeatIn(lines(data['form']), 'a') ]][[ a['code'] ]] - - - [[ setTag('tr','tr',{'style':'TrLevel'+str(a['level']), 'paraStyle':('Level'+str(a['level']))}) ]] - [[ a['name'] ]] - - - [[ formatLang(a['debit'] or '') ]] - - - [[ formatLang(a['credit'] or '') ]] - - - [[ (a['leef'] and removeParentNode('para')) or formatLang(a['balance'] or '') ]] - [[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['balance'] or '') ]] - - - - + + + + [[ repeatIn(lines(data['form']), 'a') ]] + + [[ setTag('para','para',{'style':('Level'+str(a['level']))}) ]][[ a['code'] or removeParentNode('tr') ]] + + [[ 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 '']] + + + [[ formatLang(a['credit']) and '%.2f'%a['credit'] or '']] + + + [[ (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['jname'] or removeParentNode('tr') ]] + + [[ '... '*(a['level']-3) ]][[ a['lname'] ]] + + + [[ formatLang(a['debit1']) and '%.2f'%a['debit1'] or '']] + + + [[ formatLang(a['credit1']) and '%.2f'%a['credit1'] or '']] + + + [[ formatLang(a['balance1']) and '%.2f'%a['balance1'] or '']] + + + + + + + diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py old mode 100644 new mode 100755 index 78187c703b9..bd04138c8bf --- a/addons/account/report/aged_trial_balance.py +++ b/addons/account/report/aged_trial_balance.py @@ -1,9 +1,6 @@ -# -*- encoding: utf-8 -*- ############################################################################## # -# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved. -# -# $Id$ +# Copyright (c) 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,166 +27,172 @@ import time import pooler +import rml_parse from report import report_sxw -class aged_trial_report(report_sxw.rml_parse): - def __init__(self, cr, uid, name, context): - super(aged_trial_report, self).__init__(cr, uid, name, context) - self.localcontext.update({ - 'time': time, - 'get_lines': self._get_lines, - 'get_total': self._get_total, - 'get_before': self._get_before, - 'get_for_period': self._get_for_period, - 'get_company': self._get_company, - 'get_currency': self._get_currency, - }) +class aged_trial_report(rml_parse.rml_parse): + + def __init__(self, cr, uid, name, context): + super(aged_trial_report, self).__init__(cr, uid, name, context) + self.line_query = '' + self.total_account = [] + + + self.localcontext.update({ + 'time': time, + 'get_lines': self._get_lines, + 'get_total': self._get_total, + 'get_direction': self._get_direction, + 'get_for_period': self._get_for_period, + 'get_company': self._get_company, + 'get_currency': self._get_currency, + + }) + + + def _get_lines(self, form): + + if (form['result_selection'] == 'customer' ): + self.ACCOUNT_TYPE = "('receivable')" + elif (form['result_selection'] == 'supplier'): + self.ACCOUNT_TYPE = "('payable')" + else: + self.ACCOUNT_TYPE = "('payable','receivable')" + - def _add_header(self, node): - return True + res = [] + account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') + self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', + context={'fiscalyear': form['fiscalyear']}) + self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \ + "res_partner.name AS name " \ + "FROM res_partner,account_move_line AS line, account_account,account_move_reconcile AS recon " \ + "WHERE (line.account_id=account_account.id) " \ + "AND ((reconcile_id IS NULL) " \ + "OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) " \ + "AND (line.partner_id=res_partner.id) " \ + "AND (account_account.company_id = %d) " \ + "ORDER BY res_partner.name", (form['date1'],form['company_id'])) + partners = self.cr.dictfetchall() + ## mise a 0 du total + for i in range(7): + self.total_account.append(0) + # + + for partner in partners: + values = {} + ## If choise selection is in the future + if form['direction_selection'] == 'future': + self.cr.execute("SELECT SUM(debit-credit) " \ + "FROM account_move_line AS line, account_account " \ + "WHERE (line.account_id=account_account.id) " \ + "AND (account_account.type IN " + self.ACCOUNT_TYPE + ") " \ + "AND (COALESCE(date_maturity,date) < %s) AND (partner_id=%d) " \ + "AND ((reconcile_id IS NULL) " \ + "OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) " \ + "AND (account_account.company_id = %d) " \ + "AND account_account.active", + (form['date1'], partner['id'],form['date1'], form['company_id'])) + before = self.cr.fetchone() + + self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0) - def _get_lines(self, form): - self.form=form - res = [] - 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': form['fiscalyear'],'state':form['state']}) - self.cr.execute("SELECT DISTINCT res_partner.id AS id, " \ - "res_partner.name AS name, res_partner.ref AS code " \ - "FROM res_partner, account_move_line AS line, account_account " \ - "WHERE (line.account_id=account_account.id) " \ - "AND (line.reconcile_id IS NULL) " \ - "AND (line.partner_id=res_partner.id) " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active " \ - "ORDER BY res_partner.name", (form['company_id'],)) - partners = self.cr.dictfetchall() - for partner in partners: - values = {} - self.cr.execute("SELECT SUM(debit-credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id=account_account.id) " \ - "AND (account_account.type IN (" + form['computation'] +")) " \ - "AND (date < %s) AND (partner_id=%d) " \ - "AND (reconcile_id IS NULL) " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (form['0']['start'], partner['id'], form['company_id'])) - before = self.cr.fetchone() - values['before'] = before and before[0] or "" - for i in range(5): - self.cr.execute("SELECT SUM(debit-credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id=account_account.id) " \ - "AND (account_account.type IN (" + form['computation'] + ")) " \ - "AND (date >= %s) AND (date <= %s) " \ - "AND (partner_id = %d) " \ - "AND (reconcile_id IS NULL) " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (form[str(i)]['start'], form[str(i)]['stop'], - partner['id'], form['company_id'])) - during = self.cr.fetchone() - values[str(i)] = during and during[0] or "" + values['direction'] = before and before[0] or 0.0 + else: + self.cr.execute("SELECT SUM(debit-credit) " \ + "FROM account_move_line AS line, account_account " \ + "WHERE (line.account_id=account_account.id) " \ + "AND (account_account.type IN " + self.ACCOUNT_TYPE + ") " \ + "AND (COALESCE(date_maturity,date) > %s) AND (partner_id=%d) " \ + "AND ((reconcile_id IS NULL) " \ + "OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) " \ + "AND (account_account.company_id = %d) " \ + "AND account_account.active", + (form['date1'], partner['id'],form['date1'], form['company_id'])) + after = self.cr.fetchone() + self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0) + values['direction'] = after and after[0] or "" + #print str(values['direction']) + for i in range(5): + self.cr.execute("SELECT SUM(debit-credit) " \ + "FROM account_move_line AS line, account_account " \ + "WHERE (line.account_id=account_account.id) " \ + "AND (account_account.type IN " + self.ACCOUNT_TYPE + ") " \ + "AND (COALESCE(date_maturity,date) BETWEEN %s AND %s) " \ + "AND (partner_id = %d) " \ + "AND ((reconcile_id IS NULL) " \ + "OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) " \ + "AND (account_account.company_id = %d) " \ + "AND account_account.active", + (form[str(i)]['start'], form[str(i)]['stop'],partner['id'],form['date1'] ,form['company_id'])) + during = self.cr.fetchone() + # Ajout du compteur + self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0) - self.cr.execute("SELECT SUM(debit-credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id = account_account.id) " \ - "AND (account_account.type IN (" + form['computation'] + ")) " \ - "AND (partner_id = %d) " \ - "AND (reconcile_id IS NULL) " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (partner['id'], form['company_id'])) - total = self.cr.fetchone() - values['total'] = total and total[0] or 0.0 - values['name'] = partner['name'] - values['ref'] = partner['code'] - t = 0.0 - for i in range(5)+['before']: - t+= float(values.get(str(i), 0.0) or 0.0) - if values['total']: - res.append(values) - total = 0.0 - totals = {} - for r in res: - total += float(r['total'] or 0.0) - for i in range(5)+['before']: - totals.setdefault(str(i), 0.0) - totals[str(i)] += float(r[str(i)] or 0.0) - if form['sorting_on']=='amount': - res.sort(lambda x,y:cmp(y['total'],x['total'])) - return res + #print str(during) + values[str(i)] = during and during[0] or "" + self.cr.execute("SELECT SUM(debit-credit) " \ + "FROM account_move_line AS line, account_account " \ + "WHERE (line.account_id = account_account.id) " \ + "AND (account_account.type IN " + self.ACCOUNT_TYPE + ") " \ + "AND (partner_id = %d) " \ + "AND ((reconcile_id IS NULL) " \ + "OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) " \ + "AND (account_account.company_id = %d) " \ + "AND account_account.active", + (partner['id'],form['date1'],form['company_id'])) + total = self.cr.fetchone() + values['total'] = total and total[0] or 0.0 + ## Add for total + self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0) + print self.total_account,">>>>>>>>>>>>>Total>>>>>>>>>>>>>>>>" + values['name'] = partner['name'] + #t = 0.0 + #for i in range(5)+['direction']: + # t+= float(values.get(str(i), 0.0) or 0.0) + #values['total'] = t + + if values['total']: + + res.append(values) + + total = 0.0 + + totals = {} + for r in res: + total += float(r['total'] or 0.0) + for i in range(5)+['direction']: + totals.setdefault(str(i), 0.0) + totals[str(i)] += float(r[str(i)] or 0.0) + return res - def _get_total(self, fiscalyear, company_id): - 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': fiscalyear,'state':self.datas['form']['state']}) - self.cr.execute("SELECT SUM(debit - credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id = account_account.id) " \ - "AND (account_account.type IN (" + self.form['computation'] + ")) "\ - "AND reconcile_id IS NULL " \ - "AND partner_id is NOT NULL " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (company_id,)) - total = self.cr.fetchone() - return total and total[0] or 0.0 + + + + def _get_total(self,pos): + print self.total_account,"========_get_total========" + period = self.total_account[int(pos)] + return period - def _get_before(self, date, fiscalyear, company_id): - 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': fiscalyear,'state':self.datas['form']['state']}) - self.cr.execute("SELECT SUM(debit - credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id = account_account.id) " \ - "AND (account_account.type IN (" + self.form['computation'] + ")) " \ - "AND reconcile_id IS NULL " \ - "AND (date < %s) " \ - "AND partner_id IS NOT NULL " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (date, company_id)) - before = self.cr.fetchone() - return before and before[0] or 0.0 + + def _get_direction(self,pos): + + period = self.total_account[int(pos)] + return period - def _get_for_period(self, period, fiscalyear, company_id): - 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': fiscalyear,'state':self.datas['form']['state']}) - self.cr.execute("SELECT SUM(debit - credit) " \ - "FROM account_move_line AS line, account_account " \ - "WHERE (line.account_id = account_account.id) " \ - "AND (account_account.type IN (" + self.form['computation'] + ")) " \ - "AND reconcile_id IS NULL " \ - "AND (date >= %s) " \ - "AND (date <= %s) " \ - "AND partner_id IS NOT NULL " \ - "AND " + line_query + " " \ - "AND (account_account.company_id = %d) " \ - "AND account_account.active", - (period['start'], period['stop'], company_id)) - period = self.cr.fetchone() - return period and period[0] or 0.0 + def _get_for_period(self,pos): + + period = self.total_account[int(pos)] + return period - def _get_company(self, form): - return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name + def _get_company(self, form): + return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name - def _get_currency(self, form): - return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name + def _get_currency(self, form): + 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.aged.trial.balance', - 'res.partner', - 'addons/account/report/aged_trial_balance.rml', - parser=aged_trial_report, header=False) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +report_sxw.report_sxw('report.account.aged_trial_balance', 'res.partner', + 'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False) + diff --git a/addons/account/report/aged_trial_balance.rml b/addons/account/report/aged_trial_balance.rml old mode 100644 new mode 100755 index 99292838dbe..c2fb76f8388 --- a/addons/account/report/aged_trial_balance.rml +++ b/addons/account/report/aged_trial_balance.rml @@ -1,8 +1,35 @@ -