diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py
index c880db50fc1..975069231ef 100644
--- a/addons/account/account_analytic_line.py
+++ b/addons/account/account_analytic_line.py
@@ -48,6 +48,21 @@ class account_analytic_line(osv.osv):
'date': lambda *a: time.strftime('%Y-%m-%d'),
}
_order = 'date'
+
+
+ def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None):
+ if context is None:
+ context = {}
+
+ if context.get('from_date',False):
+ args.append(['date', '>=',context['from_date']])
+
+ if context.get('to_date',False):
+ args.append(['date','<=',context['to_date']])
+
+ return super(account_analytic_line, self).search(cr, uid, args, offset, limit,
+ order, context=context)
+
def _check_company(self, cr, uid, ids):
lines = self.browse(cr, uid, ids)
for l in lines:
diff --git a/addons/account/project/project.py b/addons/account/project/project.py
index 0f6f0319916..bcec9209d22 100644
--- a/addons/account/project/project.py
+++ b/addons/account/project/project.py
@@ -36,8 +36,15 @@ class account_analytic_account(osv.osv):
def _credit_calc(self, cr, uid, ids, name, arg, context={}):
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) GROUP BY a.id" % acc_set)
- r= dict(cr.fetchall())
+
+ where_date = ''
+ if context.get('from_date',False):
+ where_date += " AND l.date >= '" + context['from_date'] + "'"
+ if context.get('to_date',False):
+ where_date += " AND l.date <= '" + context['to_date'] + "'"
+
+ 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 %s) WHERE l.amount<0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set))
+ r = dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
@@ -45,18 +52,30 @@ class account_analytic_account(osv.osv):
def _debit_calc(self, cr, uid, ids, name, arg, context={}):
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) GROUP BY a.id" % acc_set)
+
+ where_date = ''
+ if context.get('from_date',False):
+ where_date += " AND l.date >= '" + context['from_date'] + "'"
+ if context.get('to_date',False):
+ where_date += " AND l.date <= '" + context['to_date'] + "'"
+
+ 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 %s) WHERE l.amount>0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set))
r= dict(cr.fetchall())
for i in ids:
r.setdefault(i,0.0)
return r
-
-
def _balance_calc(self, cr, uid, ids, name, arg, context={}):
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) GROUP BY a.id" % acc_set)
+
+ where_date = ''
+ if context.get('from_date',False):
+ where_date += " AND l.date >= '" + context['from_date'] + "'"
+ if context.get('to_date',False):
+ where_date += " AND l.date <= '" + context['to_date'] + "'"
+
+ 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 %s) WHERE a.id IN (%s) GROUP BY a.id" % (where_date,acc_set))
res = {}
for account_id, sum in cr.fetchall():
res[account_id] = sum
@@ -86,9 +105,16 @@ class account_analytic_account(osv.osv):
#XXX must convert into one uom
ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
acc_set = ",".join(map(str, ids2))
+
+ where_date = ''
+ if context.get('from_date',False):
+ where_date += " AND l.date >= '" + context['from_date'] + "'"
+ if context.get('to_date',False):
+ where_date += " AND l.date <= '" + context['to_date'] + "'"
+
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) \
+ LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \
WHERE a.id IN ('+acc_set+') GROUP BY a.id')
res = {}
for account_id, sum in cr.fetchall():
@@ -168,7 +194,7 @@ class account_analytic_account(osv.osv):
_order = 'parent_id desc,code'
_constraints = [
- (check_recursion, 'Error! You can not create recursive account.', ['parent_id'])
+ (check_recursion, 'Error! You can not create recursive analytic accounts.', ['parent_id'])
]
def create(self, cr, uid, vals, context=None):
diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml
index a417f14eca6..02842c47333 100644
--- a/addons/account/project/project_view.xml
+++ b/addons/account/project/project_view.xml
@@ -94,8 +94,11 @@
action="action_account_analytic_account_tree2"
id="account_analytic_def_chart"
parent="account_analytic_def_account"/>
-
-
+
+
+
+
+
New Analytic Account
account.analytic.account
diff --git a/addons/account/project/wizard/__init__.py b/addons/account/project/wizard/__init__.py
index b4558079faa..c539b899fba 100644
--- a/addons/account/project/wizard/__init__.py
+++ b/addons/account/project/wizard/__init__.py
@@ -27,6 +27,7 @@ import wizard_account_analytic_cost_ledger_report
import wizard_account_analytic_cost_ledger_for_journal_report
import wizard_account_analytic_analytic_check
import wizard_account_analytic_line
+import wizard_analytic_account_chart
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/account/project/wizard/wizard_account_analytic_line.py b/addons/account/project/wizard/wizard_account_analytic_line.py
index db90e00f3b6..8a6774617b6 100644
--- a/addons/account/project/wizard/wizard_account_analytic_line.py
+++ b/addons/account/project/wizard/wizard_account_analytic_line.py
@@ -26,15 +26,15 @@ import time
from tools.translate import _
def _action_open_window(self, cr, uid, data, context):
- domain=[]
- from_date= data['form']['from_date']
- to_date=data['form']['to_date']
+ domain = []
+ 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)]
+ domain = [('date','>=',from_date),('date','<=',to_date)]
elif from_date:
- domain=[('date','>=',from_date)]
+ domain = [('date','>=',from_date)]
elif to_date:
- domain=[('date','<=',to_date)]
+ domain = [('date','<=',to_date)]
return {
'name': _('Analytic Entries'),
'view_type': 'form',
diff --git a/addons/account/project/wizard/wizard_analytic_account_chart.py b/addons/account/project/wizard/wizard_analytic_account_chart.py
new file mode 100644
index 00000000000..43a921c614e
--- /dev/null
+++ b/addons/account/project/wizard/wizard_analytic_account_chart.py
@@ -0,0 +1,79 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved
+# $Id$
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import wizard
+import pooler
+
+class wizard_analytic_account_chart(wizard.interface):
+ _account_chart_arch = '''
+ '''
+
+ _account_chart_fields = {
+ 'from_date': {
+ 'string': 'From',
+ 'type': 'date',
+ },
+ 'to_date': {
+ 'string': 'To',
+ 'type': 'date',
+ },
+ }
+
+
+ def _analytic_account_chart_open_window(self, cr, uid, data, context):
+ mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
+ act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
+
+ result = mod_obj._get_id(cr, uid, 'account', 'action_account_analytic_account_tree2')
+ id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
+ result = act_obj.read(cr, uid, [id], context=context)[0]
+
+ result_context = {}
+ if data['form']['from_date']:
+ result_context.update({'from_date' : data['form']['from_date']})
+ if data['form']['to_date']:
+ result_context.update({'to_date' : data['form']['to_date']})
+
+ result['context'] = str(result_context)
+ return result
+
+ states = {
+ 'init': {
+ 'actions': [],
+ 'result': {'type': 'form', 'arch':_account_chart_arch, 'fields':_account_chart_fields, 'state': [('end', 'Cancel'), ('open', 'Open Charts')]}
+ },
+ 'open': {
+ 'actions': [],
+ 'result': {'type': 'action', 'action':_analytic_account_chart_open_window, 'state':'end'}
+ }
+ }
+wizard_analytic_account_chart('account.analytic.account.chart')
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+