Created new wizard for analytic Lines according to Date
bzr revid: ruchakpatel@gmail.com-20081003133353-1bgnw8vgv6410hh8
This commit is contained in:
@@ -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 []
|
||||
|
||||
@@ -86,12 +86,17 @@
|
||||
<field name="view_type">tree</field>
|
||||
<field name="view_id" ref="view_account_analytic_account_tree"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="action_account_analytic_account_tree2"
|
||||
id="account_analytic_def_chart"
|
||||
parent="account.account_analytic_def_account"/>
|
||||
<menuitem action="action_account_analytic_account_tree2" id="account_analytic_chart" parent="account.menu_finance_charts"/>
|
||||
|
||||
<wizard id="analytic_account_menu_action" menu="False" model="account.analytic.account" name="account.analytic.line1" string="Analytic Account Entries"/>
|
||||
|
||||
<menuitem type="wizard" action="analytic_account_menu_action" id="analytic_account_menu" parent="account.menu_finance_charts" name="Analytic Account lines"/>
|
||||
|
||||
<record id="analytic_account_form" model="ir.actions.act_window">
|
||||
<field name="name">New Analytic Account</field>
|
||||
<field name="res_model">account.analytic.account</field>
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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 = '''<?xml version="1.0"?>
|
||||
<form string="View Account Analytic Lines">
|
||||
<separator string="Account Analytic Lines Analysis" colspan="4"/>
|
||||
<field name="from_date"/>
|
||||
<newline/>
|
||||
<field name="to_date"/>
|
||||
<newline/>
|
||||
<label string=""/>
|
||||
<label string="(Keep empty to open the current situation)" align="0.0" colspan="3"/>
|
||||
</form>'''
|
||||
form1_fields = {
|
||||
'from_date': {
|
||||
'string': 'From',
|
||||
'type': 'date',
|
||||
},
|
||||
'to_date': {
|
||||
'string': 'To',
|
||||
'type': 'date',
|
||||
},
|
||||
}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', 'Cancel','gtk-cancel'),('open', 'Open Entries','gtk-ok')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
|
||||
}
|
||||
}
|
||||
account_analytic_line1('account.analytic.line1')
|
||||
Reference in New Issue
Block a user