diff --git a/addons/account/report/general_ledger_landscape.py b/addons/account/report/general_ledger_landscape.py
index 65b7efafb3b..7c224a24dca 100644
--- a/addons/account/report/general_ledger_landscape.py
+++ b/addons/account/report/general_ledger_landscape.py
@@ -54,8 +54,6 @@ class general_ledger_landscape(rml_parse.rml_parse):
def __init__(self, cr, uid, name, context):
super(general_ledger_landscape, self).__init__(cr, uid, name, context)
self.date_borne = {}
- self.sum_debit = 0.00
- self.sum_credit = 0.00
self.query = ""
self.child_ids = ""
self.tot_currency = 0.0
@@ -180,10 +178,11 @@ class general_ledger_landscape(rml_parse.rml_parse):
- def get_children_accounts(self, acc_l, form):
+ def get_children_accounts(self, account, form):
+
self.child_ids = self.pool.get('account.account').search(self.cr, self.uid,
[('parent_id', 'child_of', self.ids)])
- done_l = []
+#
res = []
ctx = self.context.copy()
## We will make the test for period or date
@@ -199,32 +198,61 @@ class general_ledger_landscape(rml_parse.rml_parse):
#
self.query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
- ids_acc = []
- for acc in acc_l:
- if acc and acc.child_consol_ids: # add ids of consolidated childs also of selected account
- ctx['consolidate_childs'] = True
- ctx['account_id'] = acc.id
- ids_acc += self.pool.get('account.account').search(self.cr, self.uid,[('parent_id', 'child_of', [acc.id])], 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:
- if child_id not in done_l:
- done_l.append(child_id)
- else:
- continue
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
- accounts = self.pool.get('account.account').read(self.cr, self.uid, child_id,['debit','credit','balance'])
if form['display_account'] == 'bal_mouvement':
- if accounts['credit'] > 0 or accounts['debit'] > 0 or accounts['balance'] > 0 :
- #if child_account not in res:
+ 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)
elif form['display_account'] == 'bal_solde':
- if accounts['balance'] != 0:
+ 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 :
if ( sold_account <> 0.0):
res.append(child_account)
-
else:
- res.append(child_account)
+ 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)
+ ##
+ 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
+
+
return res
def lines(self, account, form):
@@ -287,17 +315,44 @@ class general_ledger_landscape(rml_parse.rml_parse):
return res
def _sum_debit_account(self, account, form):
- accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['debit'])
- return accounts['debit']
+
+ 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):
- accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['credit'])
- return accounts['credit']
+
+ 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):
- accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['balance'])
- return accounts['balance']
-
+ 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['soldeinit']:
+ sum_solde += account.init_debit - account.init_credit
+
+ return sum_solde
+
def _sum_debit(self, form):
if not self.ids:
return 0.0
diff --git a/addons/account/report/general_ledger_landscape.rml b/addons/account/report/general_ledger_landscape.rml
index 3f71ee1f1e6..424c0e3a3f3 100644
--- a/addons/account/report/general_ledger_landscape.rml
+++ b/addons/account/report/general_ledger_landscape.rml
@@ -82,6 +82,9 @@
+
+ [[ repeatIn(objects, 'a') ]]
+
[[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]]
| Date |
@@ -99,7 +102,9 @@
- [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]
+
+ [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]
+
[[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]]
@@ -159,7 +164,7 @@
- [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]
+ [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]
[[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]]
@@ -198,6 +203,6 @@
-
+
\ No newline at end of file
diff --git a/addons/account/wizard/wizard_general_ledger_report.py b/addons/account/wizard/wizard_general_ledger_report.py
index afd8a272a66..c03171f8e61 100644
--- a/addons/account/wizard/wizard_general_ledger_report.py
+++ b/addons/account/wizard/wizard_general_ledger_report.py
@@ -84,7 +84,7 @@ period_fields = {
'sortbydate':{'string':"Sort by:",'type':'selection','selection':[('sort_date','Date'),('sort_mvt','Movement')]},
'display_account':{'string':"Display accounts ",'type':'selection','selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]},
'landscape':{'string':"Landscape Mode",'type':'boolean'},
- # 'soldeinit':{'string':"Include initial balances",'type':'boolean'},
+ 'soldeinit':{'string':"Include initial balances",'type':'boolean'},
'amount_currency':{'string':"With Currency",'type':'boolean'},
'date_from': {'string':" Start date",'type':'date','required':True ,'default': lambda *a: time.strftime('%Y-01-01')},
'date_to': {'string':"End date",'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
| |