Changes in account/project.py and other for Analytic Chart of Accounts according to selected dates

bzr revid: ruchakpatel@gmail.com-20081006092800-84af8krgwswd2gbf
This commit is contained in:
Rucha Patel
2008-10-06 14:58:00 +05:30
parent 7c60542fc4
commit 76e2db3bcc
2 changed files with 18 additions and 16 deletions
+17 -7
View File
@@ -52,7 +52,7 @@ class account_analytic_account(osv.osv):
else:
date_stop = time.strftime('%Y-%m-%d')
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount<0 and a.id IN (%s) AND (l.date BETWEEN %s and %s) GROUP BY a.id" % (acc_set,date_start,date_stop))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount<0 and a.id IN (%s) AND (l.date BETWEEN '%s' and '%s') GROUP BY a.id" % (acc_set,date_start,date_stop))
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
@@ -68,7 +68,7 @@ class account_analytic_account(osv.osv):
else:
date_stop = time.strftime('%Y-%m-%d')
acc_set = ",".join(map(str, ids))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount>0 and a.id IN (%s) AND (l.date BETWEEN %s and %s) GROUP BY a.id" % (acc_set,date_start,date_stop))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE l.amount>0 and a.id IN (%s) AND (l.date BETWEEN '%s' and '%s') GROUP BY a.id" % (acc_set,date_start,date_stop))
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
@@ -87,7 +87,8 @@ class account_analytic_account(osv.osv):
date_stop = time.strftime('%Y-%m-%d')
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE a.id IN (%s) AND (l.date BETWEEN %s and %s) GROUP BY a.id" % (acc_set,date_start,date_stop))
cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) WHERE a.id IN (%s) AND (l.date BETWEEN '%s' and '%s') GROUP BY a.id" % (acc_set,date_start,date_stop))
# cr.execute("select a.id, COALESCE(SUM(l.amount),0) from account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id) where (l.date BETWEEN '2008-10-01' AND '2008-10-03') GROUP BY a.id")
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
@@ -114,13 +115,21 @@ class account_analytic_account(osv.osv):
return dict([(i, res[i]) for i in ids ])
def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
#XXX must convert into one uom
# XXX must convert into one uom
if 'date_start' in context and context['date_start']:
date_start = context['date_start']
else:
date_start = time.strftime('%Y-01-01')
if 'date_stop' in context and context['date_stop']:
date_stop = context['date_stop']
else:
date_stop = time.strftime('%Y-%m-%d')
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
cr.execute("SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
FROM account_analytic_account a \
LEFT JOIN account_analytic_line l ON (a.id = l.account_id) \
WHERE a.id IN ('+acc_set+') GROUP BY a.id')
WHERE a.id IN (%s) AND (l.date BETWEEN '%s' and '%s') GROUP BY a.id" % (acc_set,date_start,date_stop))
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
@@ -130,9 +139,10 @@ class account_analytic_account(osv.osv):
if child <> id:
res.setdefault(id, 0.0)
res[id] += res.get(child, 0.0)
if not id in res:
res.setdefault(id, 0.0)
return dict([(i, res[i]) for i in ids])
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
@@ -36,14 +36,6 @@ def _action_open_window(self, cr, uid, data, context):
domain=[]
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('account.analytic.account.tree', 'tree'))
view_res = cr.fetchone()
from_date= data['form']['from_date']
to_date=data['form']['to_date']
if from_date and to_date:
domain=[('date','>=',from_date),('date','<=',to_date)]
elif from_date:
domain=[('date','>=',from_date)]
elif to_date:
domain=[('date','<=',to_date)]
return {
'name': 'Analytic Entries',
'view_type': 'tree',
@@ -51,7 +43,7 @@ def _action_open_window(self, cr, uid, data, context):
'res_model': 'account.analytic.account',
'type': 'ir.actions.act_window',
'view_id' : view_res,
'domain' :domain+[('parent_id','=',False)],
'domain' :[('parent_id','=',False)],
'context':{'date_start':data['form']['from_date'],'date_stop':data['form']['to_date']},
}