Reverted general ledger changes

bzr revid: jvo@tinyerp.com-20090529114846-u286bym234c88yxa
This commit is contained in:
Jay (Open ERP) 2009-05-29 17:18:46 +05:30
parent d377f1c423
commit ccfec2c1c8
5 changed files with 226 additions and 94 deletions

View File

@ -110,8 +110,96 @@ 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
@ -168,7 +256,6 @@ 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)
@ -183,54 +270,6 @@ 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: ',
@ -238,11 +277,13 @@ 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
@ -257,6 +298,7 @@ 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:
@ -271,10 +313,7 @@ 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
@ -287,21 +326,48 @@ 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):
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
@ -311,6 +377,7 @@ 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
@ -328,6 +395,9 @@ 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
@ -341,7 +411,9 @@ 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()

View File

@ -90,7 +90,7 @@
<paraStyle name="Index" fontName="Helvetica"/>
</stylesheet>
<story>
<para>[[ repeatIn(objects, 'a') ]]</para>
<blockTable colWidths="66.0,124.0,70.0,40.0,80.0,59.0,52.0,54.0" style="tbl_header" repeatRows="1">[[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]]
<tr>
<td><para style="date">Date</para></td>
@ -104,7 +104,7 @@
</tr>
</blockTable>
<section>
<para>[[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]</para>
<para>[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]</para>
<blockTable colWidths="66.0,124.0,70.0,40.0,80.0,59.0,52.0,54.0" style="tbl_content">[[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]]
<tr>
<td>
@ -155,7 +155,7 @@
</tr>
</blockTable>
<section>
<para>[[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]</para>
<para>[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]</para>
<blockTable colWidths="72.0,93.0,66.0,40.0,100.0,50.0,50.0,50.0,40.0" style="tbl_content">[[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]]
<tr>
<td>

View File

@ -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

View File

@ -82,6 +82,9 @@
<paraStyle name="Index" fontName="Helvetica"/>
</stylesheet>
<story>
<para>[[ repeatIn(objects, 'a') ]]</para>
<blockTable colWidths="66.0,35.0,150.0, 90.0,60.0,335.0,50.0,69.0,72.0,64.0,58.0" style="tbl_header" repeatRows="1">[[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]]
<tr>
<td><para style="P12"><font color="white"> </font></para><para style="date">Date</para></td>
@ -99,7 +102,9 @@
</blockTable>
<section>
<para>[[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]</para>
<para>[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]</para>
<blockTable colWidths="66.0,35.0,150.0, 90.0,60.0,335.0,50.0,69.0,72.0,64.0,58.0" style="tbl_content">[[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]]
<tr>
<td>
@ -159,7 +164,7 @@
<section>
<para>[[ repeatIn(get_children_accounts(objects,data['form']), 'o') ]]</para>
<para>[[ repeatIn(get_children_accounts(a,data['form']), 'o') ]]</para>
<blockTable colWidths="66.0,35.0,166.0,90.0,60.0,378.0,50.0,69.0,72.0,64.0" style="tbl_content">[[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]]
<tr>
@ -198,6 +203,6 @@
</tr>
</blockTable>
</section>
</section>
</story>
</document>

View File

@ -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')},