diff --git a/addons/account/project/project.py b/addons/account/project/project.py index b4cc3468e5f..9810fa8a365 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -43,17 +43,32 @@ class account_analytic_account(osv.osv): _description = 'Analytic Accounts' def _credit_calc(self, cr, uid, ids, name, arg, context={}): + 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') 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) + 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) return r def _debit_calc(self, cr, uid, ids, name, arg, context={}): - + 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') 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) + 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) @@ -62,9 +77,17 @@ class account_analytic_account(osv.osv): def _balance_calc(self, cr, uid, ids, name, arg, context={}): + 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.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) + 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)) res = {} for account_id, sum in cr.fetchall(): res[account_id] = sum @@ -109,6 +132,7 @@ class account_analytic_account(osv.osv): res[id] += res.get(child, 0.0) return dict([(i, res[i]) for i in ids]) + def name_get(self, cr, uid, ids, context={}): if not len(ids): return [] diff --git a/addons/account/project/project_view.xml b/addons/account/project/project_view.xml index 45a4307a6c9..82ba671265f 100644 --- a/addons/account/project/project_view.xml +++ b/addons/account/project/project_view.xml @@ -86,12 +86,17 @@ tree + + + + + New Analytic Account account.analytic.account diff --git a/addons/account/project/wizard/__init__.py b/addons/account/project/wizard/__init__.py index 477e5262a00..66cce97becb 100644 --- a/addons/account/project/wizard/__init__.py +++ b/addons/account/project/wizard/__init__.py @@ -35,6 +35,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_account_analytic_line1 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/project/wizard/wizard_account_analytic_line1.py b/addons/account/project/wizard/wizard_account_analytic_line1.py new file mode 100644 index 00000000000..5f1f7b85c83 --- /dev/null +++ b/addons/account/project/wizard/wizard_account_analytic_line1.py @@ -0,0 +1,91 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +import pooler +import time + +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', + "view_mode": 'tree,form', + 'res_model': 'account.analytic.account', + 'type': 'ir.actions.act_window', + 'view_id' : view_res, + 'domain' :domain+[('parent_id','=',False)], + 'context':{'date_start':data['form']['from_date'],'date_stop':data['form']['to_date']}, + } + + +class account_analytic_line1(wizard.interface): + form1 = ''' +
+ + + + + +