diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index f9c2f30c0e1..43e63dd592f 100644 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -110,96 +110,8 @@ class general_ledger(rml_parse.rml_parse): result[account_line.id] = concat + '...' break rup_id+=1 - - #print str(result) return result - 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)]) - res = [] - ctx = self.context.copy() - ## We will make the test for period or date - ## We will now make the test - # - if form.has_key('fiscalyear'): - ctx['fiscalyear'] = form['fiscalyear'] - ctx['periods'] = form['periods'][0][2] - else: - 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 - - if form['display_account'] == 'bal_mouvement': - 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) - #print "Type de vue :" + form['display_account'] - elif form['display_account'] == 'bal_solde': - 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: - 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) - - ## - - - ## We will now compute solde initiaux - - if not len(res): - return[account] - else: - 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 get_min_date(self,form): ## Get max born from account_fiscal year @@ -256,6 +168,7 @@ class general_ledger(rml_parse.rml_parse): else : borne_max = date_max elif form['state'] == 'none': + sql = """ SELECT min(date) as start_date,max(date) as stop_date FROM account_move_line """ self.cr.execute(sql) @@ -270,6 +183,54 @@ class general_ledger(rml_parse.rml_parse): + + def get_children_accounts(self, acc_l, 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 + ## We will now make the test + # + if form.has_key('fiscalyear'): + ctx['fiscalyear'] = form['fiscalyear'] + ctx['periods'] = form['periods'][0][2] + else: + 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) + 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) + 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: + res.append(child_account) + elif form['display_account'] == 'bal_solde': + if accounts['balance'] != 0: + if ( sold_account <> 0.0): + res.append(child_account) + + else: + res.append(child_account) + return res + def lines(self, account, form): inv_types = { 'out_invoice': 'CI: ', @@ -277,13 +238,11 @@ class general_ledger(rml_parse.rml_parse): 'out_refund': 'OR: ', 'in_refund': 'SR: ', } - ### We will now compute solde initaux if form['sortbydate'] == 'sort_date': sorttag = 'l.date' else: sorttag = 'j.code' - sql = """ SELECT l.id, l.date, j.code,c.code AS currency_code,l.amount_currency,l.ref, l.name , l.debit, l.credit, l.period_id FROM account_move_line as l @@ -298,7 +257,6 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute(sql, (account.id, self.date_borne['max_date'], self.date_borne['min_date'],)) res = self.cr.dictfetchall() - sum = 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') for l in res: @@ -313,7 +271,10 @@ class general_ledger(rml_parse.rml_parse): 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 @@ -326,48 +287,21 @@ class general_ledger(rml_parse.rml_parse): # if l['amount_currency'] != None: 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 + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['debit']) + return accounts['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 + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['credit']) + return accounts['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['soldeinit']: - sum_solde += account.init_debit - account.init_credit - - return sum_solde - - + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['balance']) + return accounts['balance'] + def _sum_debit(self, form): if not self.ids: return 0.0 @@ -377,7 +311,6 @@ class general_ledger(rml_parse.rml_parse): sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit - def _sum_credit(self, form): if not self.ids: return 0.0 @@ -395,9 +328,6 @@ class general_ledger(rml_parse.rml_parse): 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) -# print ("SELECT (sum(debit) - sum(credit)) as Test "\ -# "FROM account_move_line l "\ -# "WHERE l.account_id in ("+','.join(map(str, child_ids))+") AND "+query+period_sql) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde @@ -411,9 +341,7 @@ class general_ledger(rml_parse.rml_parse): else: self.account_currency = False - def _sum_currency_amount_account(self, account, form): - 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() diff --git a/addons/account/report/general_ledger.rml b/addons/account/report/general_ledger.rml index ed2d3dae324..2c5bc28b4cb 100644 --- a/addons/account/report/general_ledger.rml +++ b/addons/account/report/general_ledger.rml @@ -90,7 +90,7 @@ - [[ repeatIn(objects, 'a') ]] + [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] Date @@ -104,7 +104,7 @@
- [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] + [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]] [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] @@ -155,7 +155,7 @@
- [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] + [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]] [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] diff --git a/addons/account/report/general_ledger_landscape.py b/addons/account/report/general_ledger_landscape.py index 33eb1ec67ba..65b7efafb3b 100644 --- a/addons/account/report/general_ledger_landscape.py +++ b/addons/account/report/general_ledger_landscape.py @@ -54,6 +54,8 @@ 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 @@ -178,11 +180,10 @@ class general_ledger_landscape(rml_parse.rml_parse): - def get_children_accounts(self, account, form): - + def get_children_accounts(self, acc_l, 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 @@ -198,61 +199,32 @@ class general_ledger_landscape(rml_parse.rml_parse): # 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) + 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) 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 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 accounts['credit'] > 0 or accounts['debit'] > 0 or accounts['balance'] > 0 : + #if child_account not in res: res.append(child_account) elif form['display_account'] == 'bal_solde': - 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 accounts['balance'] != 0: 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) - ## - 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 - - + res.append(child_account) return res def lines(self, account, form): @@ -315,44 +287,17 @@ class general_ledger_landscape(rml_parse.rml_parse): 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 + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['debit']) + return accounts['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 + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['credit']) + return accounts['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['soldeinit'] != 0: - sum_solde += account.init_debit - account.init_credit - - return sum_solde - + accounts = self.pool.get('account.account').read(self.cr, self.uid, account.id,['balance']) + return accounts['balance'] + 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 424c0e3a3f3..3f71ee1f1e6 100644 --- a/addons/account/report/general_ledger_landscape.rml +++ b/addons/account/report/general_ledger_landscape.rml @@ -82,9 +82,6 @@ - - [[ repeatIn(objects, 'a') ]] - [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] Date @@ -102,9 +99,7 @@
- - [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - + [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]] [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] @@ -164,7 +159,7 @@
- [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] + [[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]] [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] @@ -203,6 +198,6 @@ -
+
\ No newline at end of file