=== modified file 'account/report/general_ledger.py'
--- account/report/general_ledger.py 2010-01-18 07:47:33 +0000
+++ account/report/general_ledger.py 2010-03-31 12:20:36 +0000
@@ -36,8 +36,6 @@
class general_ledger(rml_parse.rml_parse):
_name = 'report.account.general.ledger'
-
-
def set_context(self, objects, data, ids, report_type = None):
##
self.borne_date = self.get_min_date(data['form'])
@@ -59,20 +57,16 @@
self.child_ids = ""
self.tot_currency = 0.0
self.period_sql = ""
- self.sold_accounts = {}
self.localcontext.update( {
'time': time,
'lines': self.lines,
- 'sum_debit_account': self._sum_debit_account,
- 'sum_credit_account': self._sum_credit_account,
+ 'sum_calculation': self.sum_calculation,
'sum_solde_account': self._sum_solde_account,
- 'sum_debit': self._sum_debit,
- '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
})
self.context = context
+
def _calc_contrepartie(self,cr,uid,ids, context={}):
result = {}
#for id in ids:
@@ -175,9 +169,6 @@
}
return self.date_borne
-
-
-
def get_children_accounts(self, account, form):
self.child_ids = self.pool.get('account.account').search(self.cr, self.uid,
@@ -202,60 +193,36 @@
ctx['consolidate_childs'] = True
ctx['account_id'] = account.id
ids_acc = self.pool.get('account.account').search(self.cr, self.uid,[('parent_id', 'child_of', [account.id])], context=ctx)
- for child_id in ids_acc:
- child_account = self.pool.get('account.account').browse(self.cr, self.uid, child_id)
- sold_account = self._sum_solde_account(child_account,form)
- self.sold_accounts[child_account.id] = sold_account
+ child_account_l = self.pool.get('account.account').read(self.cr, self.uid, ids_acc, ['code','name','parent_id','type'])
+
+ for child_account in child_account_l:
+ child_account['level'] = 1
if form['display_account'] == 'bal_mouvement':
- if child_account.type != 'view' \
+ if child_account['type'] != 'view' \
and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','=',child_account.id)],
+ [('account_id','=',child_account['id'])],
context=ctx)) <> 0 :
res.append(child_account)
elif form['display_account'] == 'bal_solde':
- if child_account.type != 'view' \
+ if child_account['type'] != 'view' \
and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','=',child_account.id)],
+ [('account_id','=',child_account['id'])],
context=ctx)) <> 0 :
- if ( sold_account <> 0.0):
+ sold_account = self._sum_solde_account(child_account['id'],form)
+ if (sold_account <> 0.0):
res.append(child_account)
else:
- if child_account.type != 'view' \
- and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','>=',child_account.id)],
- context=ctx)) <> 0 :
- res.append(child_account)
+ res.append(child_account)
##
- if not len(res):
-
- return [account]
- else:
- ## We will now compute solde initiaux
- 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 = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'"
- self.cr.execute(SOLDEINIT)
- 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
-
- else:
- move.init_credit = 0
- move.init_debit = 0
-
-
+ if len(res):
+ for r in res:
+ if child_account['parent_id']:
+ if child_account['parent_id'][0] == r['id']:
+ child_account['level'] = r['level'] + 1
+ break
return res
- def lines(self, account, form):
+ def lines(self, account_id, form):
inv_types = {
'out_invoice': 'CI: ',
'in_invoice': 'SI: ',
@@ -278,7 +245,7 @@
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'],))
+ self.cr.execute(sql, (account_id, self.date_borne['max_date'], self.date_borne['min_date'],))
res = self.cr.dictfetchall()
sum = 0.0
@@ -310,71 +277,26 @@
self.tot_currency = self.tot_currency + l['amount_currency']
return res
- 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
- 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
- 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
- if form.get('soldeinit', False):
- sum_solde += account.init_debit - account.init_credit
-
- return sum_solde
-
- 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
- sum_debit = self.cr.fetchone()[0] or 0.0
- return 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
- ## Add solde init to the result
- #
- sum_credit = self.cr.fetchone()[0] or 0.0
- return 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
+ def sum_calculation(self, account, form):
+ ctx = self.context.copy()
+ ctx['state'] = form['context'].get('state','all')
+ ctx['fiscalyear'] = form['fiscalyear']
+ if form['state']=='byperiod' :
+ ctx['periods'] = form['periods'][0][2]
+ elif form['state']== 'bydate':
+ ctx['date_from'] = form['date_from']
+ ctx['date_to'] = form['date_to']
+ elif form['state'] == 'all' :
+ ctx['periods'] = form['periods'][0][2]
+ ctx['date_from'] = form['date_from']
+ ctx['date_to'] = form['date_to']
+ sum_solde_amt_l = self.pool.get('account.account').read(self.cr, self.uid, [account['id']],['debit','credit','balance'], ctx)
+ return sum_solde_amt_l[0]
+
+ def _sum_solde_account(self, account_id, form):
+ self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
+ "FROM account_move_line l "\
+ "WHERE l.account_id = %s AND "+ self.query,(account_id,))
sum_solde = self.cr.fetchone()[0] or 0.0
return sum_solde
=== 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-03-31 11:31:31 +0000
@@ -110,11 +110,11 @@
- [[ o.code or '']] [[ o.name or '']] |
+ [[ '.'*o['level'] ]][[ o['code'] ]] [[ o['name'] ]] |
|
- [[formatLang(sum_debit_account(o, data['form'])) ]] |
- [[formatLang(sum_credit_account(o, data['form'])) ]] |
- [[formatLang(sum_solde_account(o, data['form'])) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['debit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['credit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['balance']) ]] |
|
@@ -127,7 +127,7 @@
|
- [[ repeatIn(lines(o, data['form']), 'line') ]] [[ formatLang(line['date'],date=True) ]] |
+ [[ repeatIn(lines(o['id'], data['form']), 'line') ]] [[ '.'*(o['level']) ]] [[ formatLang(line['date'],date=True) ]] |
[[ line['partner'] or '']] |
[[ line['ref'] or '']] |
[[ line['move'] or '']] |
@@ -161,11 +161,11 @@
- [[ o.code or '' ]] [[ o.name or '' ]] |
+ [[ '.'*o['level'] ]][[ o['code'] ]] [[ o['name'] ]] |
|
- [[ formatLang(sum_debit_account(o, data['form'])) ]] |
- [[formatLang(sum_credit_account(o, data['form'])) ]] |
- [[formatLang(sum_solde_account(o, data['form'])) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['debit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['credit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['balance']) ]] |
[[ formatLang(sum_currency_amount_account(a, data['form'])) ]] |
@@ -180,7 +180,7 @@
| |
- [[ repeatIn(lines(o, data['form']), 'line') ]] [[ formatLang(line['date'],date=True) ]] |
+ [[ repeatIn(lines(o['id'], data['form']), 'line') ]][[ '.'*(o['level']) ]][[ formatLang(line['date'],date=True) ]] |
[[ line['partner'] or '' ]] |
[[ line['ref'] or '']] |
[[ line['move'] or '' ]] |
=== modified file 'account/report/general_ledger_landscape.py'
--- account/report/general_ledger_landscape.py 2010-01-18 07:47:33 +0000
+++ account/report/general_ledger_landscape.py 2010-03-31 12:16:15 +0000
@@ -36,7 +36,6 @@
class general_ledger_landscape(rml_parse.rml_parse):
_name = 'report.account.general.ledger_landscape'
-
def set_context(self, objects, data, ids, report_type = None):
##
self.borne_date = self.get_min_date(data['form'])
@@ -58,20 +57,15 @@
self.child_ids = ""
self.tot_currency = 0.0
self.period_sql = ""
- self.sold_accounts = {}
self.localcontext.update( {
'time': time,
'lines': self.lines,
- 'sum_debit_account': self._sum_debit_account,
- 'sum_credit_account': self._sum_credit_account,
- 'sum_solde_account': self._sum_solde_account,
- 'sum_debit': self._sum_debit,
- 'sum_credit': self._sum_credit,
- 'sum_solde': self._sum_solde,
+ 'sum_calculation': self.sum_calculation,
'get_children_accounts': self.get_children_accounts,
'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:
@@ -107,7 +101,6 @@
return result
def get_min_date(self,form):
-
## Get max born from account_fiscal year
#
sql = """ select min(fy.date_start) as start_date,max(fy.date_stop) as stop_date from account_fiscalyear
@@ -174,15 +167,9 @@
}
return self.date_borne
-
-
-
def get_children_accounts(self, account, form):
-
- print self.ids
self.child_ids = self.pool.get('account.account').search(self.cr, self.uid,
[('parent_id', 'child_of', self.ids)])
-#
res = []
ctx = self.context.copy()
## We will make the test for period or date
@@ -196,67 +183,42 @@
ctx['date_from'] = form['date_from']
ctx['date_to'] = form['date_to']
##
-
#
self.query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
if account and account.child_consol_ids: # add ids of consolidated childs also of selected account
ctx['consolidate_childs'] = True
ctx['account_id'] = account.id
ids_acc = self.pool.get('account.account').search(self.cr, self.uid,[('parent_id', 'child_of', [account.id])], context=ctx)
- for child_id in ids_acc:
- child_account = self.pool.get('account.account').browse(self.cr, self.uid, child_id)
- sold_account = self._sum_solde_account(child_account,form)
- self.sold_accounts[child_account.id] = sold_account
+ child_account_l = self.pool.get('account.account').read(self.cr, self.uid, ids_acc, ['code','name','parent_id','type'])
+
+ for child_account in child_account_l:
+ child_account['level'] = 1
if form['display_account'] == 'bal_mouvement':
- if child_account.type != 'view' \
+ if child_account['type'] != 'view' \
and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','=',child_account.id)],
+ [('account_id','=',child_account['id'])],
context=ctx)) <> 0 :
res.append(child_account)
elif form['display_account'] == 'bal_solde':
- if child_account.type != 'view' \
+ if child_account['type'] != 'view' \
and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','=',child_account.id)],
+ [('account_id','=',child_account['id'])],
context=ctx)) <> 0 :
- if ( sold_account <> 0.0):
+ sold_account = self._sum_solde_account(child_account['id'],form)
+ if (sold_account <> 0.0):
res.append(child_account)
else:
- if child_account.type != 'view' \
- and len(self.pool.get('account.move.line').search(self.cr, self.uid,
- [('account_id','>=',child_account.id)],
- context=ctx)) <> 0 :
- res.append(child_account)
+ res.append(child_account)
##
- if not len(res):
-
- return [account]
- else:
- ## We will now compute solde initiaux
- 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 = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'"
- self.cr.execute(SOLDEINIT)
- 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
-
- else:
- move.init_credit = 0
- move.init_debit = 0
-
-
+ if len(res):
+ for r in res:
+ if child_account['parent_id']:
+ if child_account['parent_id'][0] == r['id']:
+ child_account['level'] = r['level'] + 1
+ break
return res
- def lines(self, account, form):
+ def lines(self, account_id, form):
inv_types = {
'out_invoice': 'CI: ',
'in_invoice': 'SI: ',
@@ -279,7 +241,7 @@
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'],))
+ self.cr.execute(sql, (account_id, self.date_borne['max_date'], self.date_borne['min_date'],))
res = self.cr.dictfetchall()
sum = 0.0
@@ -311,71 +273,26 @@
self.tot_currency = self.tot_currency + l['amount_currency']
return res
- 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
- if form['soldeinit']:
- 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
- if form['soldeinit']:
- 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
- if form.get('soldeinit',False):
- sum_solde += account.init_debit - account.init_credit
-
- return sum_solde
-
- 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
- sum_debit = self.cr.fetchone()[0] or 0.0
- return 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
- ## Add solde init to the result
- #
- sum_credit = self.cr.fetchone()[0] or 0.0
- return 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 ("+','.join(map(str, self.child_ids))+") AND "+self.query)
+ def sum_calculation(self, account, form):
+ ctx = self.context.copy()
+ ctx['state'] = form['context'].get('state','all')
+ ctx['fiscalyear'] = form['fiscalyear']
+ if form['state']=='byperiod' :
+ ctx['periods'] = form['periods'][0][2]
+ elif form['state']== 'bydate':
+ ctx['date_from'] = form['date_from']
+ ctx['date_to'] = form['date_to']
+ elif form['state'] == 'all' :
+ ctx['periods'] = form['periods'][0][2]
+ ctx['date_from'] = form['date_from']
+ ctx['date_to'] = form['date_to']
+ sum_solde_amt_l = self.pool.get('account.account').read(self.cr, self.uid, [account['id']],['debit','credit','balance'], ctx)
+ return sum_solde_amt_l[0]
+
+ def _sum_solde_account(self, account_id, form):
+ self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
+ "FROM account_move_line l "\
+ "WHERE l.account_id = %s AND "+ self.query,(account_id,))
sum_solde = self.cr.fetchone()[0] or 0.0
return sum_solde
@@ -390,7 +307,7 @@
self.account_currency = False
def _sum_currency_amount_account(self, account, form):
- self._set_get_account_currency_code(account.id)
+ self._set_get_account_currency_code(account['id'])
self.cr.execute("SELECT sum(aml.amount_currency) FROM account_move_line as aml,res_currency as rc WHERE aml.currency_id = rc.id AND aml.account_id= %s ", (account.id,))
total = self.cr.fetchone()
=== 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-03-31 11:30:50 +0000
@@ -109,12 +109,12 @@
- [[ o.code ]] [[ o.name ]] |
+ [[ '.'*o['level'] ]][[ o['code'] ]] [[ o['name'] ]] |
|
- [[ formatLang(sum_debit_account(o, data['form'])) ]] |
- [[ formatLang(sum_credit_account(o, data['form'])) ]] |
- [[ formatLang(sum_solde_account(o, data['form'])) ]] |
- [[ formatLang(sum_currency_amount_account(o, data['form'])) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['debit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['credit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['balance']) ]] |
+ [[ formatLang(sum_currency_amount_account(a, data['form'])) ]] |
|
@@ -130,7 +130,7 @@
|
- [[ repeatIn(lines(o, data['form']), 'line') ]] [[ formatLang(line['date'],date=True) ]] |
+ [[ repeatIn(lines(o['id'], data['form']), 'line') ]][[ '.'*(o['level']) ]] [[ formatLang(line['date'],date=True) ]] |
[[ line['code'] ]] |
[[ line['partner'] ]] |
[[ line['ref'] ]] |
@@ -170,11 +170,11 @@
- [[ o.code ]] [[ o.name ]] |
+ [[ '.'*o['level'] ]][[ o['code'] ]] [[ o['name'] ]] |
|
- [[ formatLang(sum_debit_account(o, data['form']))]] |
- [[formatLang(sum_credit_account(o, data['form']))]] |
- [[formatLang(sum_solde_account(o, data['form'])) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['debit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['credit']) ]] |
+ [[ formatLang(sum_calculation(o, data['form'])['balance']) ]] |
|
@@ -189,7 +189,7 @@
|
- [[ repeatIn(lines(o, data['form']), 'line') ]][[ formatLang(line['date'],date=True) ]] |
+ [[ repeatIn(lines(o['id'], data['form']), 'line') ]][[ '.'*(o['level']) ]][[ formatLang(line['date'],date=True) ]] |
[[ line['code'] ]] |
[[ line['partner'] ]] |
[[ line['ref'] ]] |