Added Aged receivable object for board_service
bzr revid: jvo@tinyerp.com-20090511102026-io7xuqqd2p3du3k0
This commit is contained in:
parent
1a21d05294
commit
e55fba82f3
|
@ -20,8 +20,14 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import datetime
|
||||
import mx.DateTime
|
||||
|
||||
import pooler
|
||||
from osv import fields,osv
|
||||
|
||||
|
||||
def _code_get(self, cr, uid, context={}):
|
||||
acc_type_obj = self.pool.get('account.account.type')
|
||||
ids = acc_type_obj.search(cr, uid, [])
|
||||
|
@ -41,6 +47,7 @@ class report_account_receivable(osv.osv):
|
|||
'credit':fields.float('Credit', readonly=True),
|
||||
}
|
||||
_order = 'name desc'
|
||||
|
||||
def init(self, cr):
|
||||
cr.execute("""
|
||||
create or replace view report_account_receivable as (
|
||||
|
@ -63,7 +70,85 @@ class report_account_receivable(osv.osv):
|
|||
report_account_receivable()
|
||||
|
||||
#a.type in ('receivable','payable')
|
||||
|
||||
class temp_range(osv.osv):
|
||||
_name = 'temp.range'
|
||||
_description = 'A Temporary table used for Dashboard view'
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Range',size=64)
|
||||
}
|
||||
|
||||
temp_range()
|
||||
|
||||
class report_aged_receivable(osv.osv):
|
||||
_name = "report.aged.receivable"
|
||||
_description = "Aged Receivable Till Today"
|
||||
_auto = False
|
||||
|
||||
def __init__(self, pool, cr):
|
||||
super(report_aged_receivable, self).__init__(pool, cr)
|
||||
self.called = False
|
||||
|
||||
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
|
||||
""" To call the init() method timely
|
||||
"""
|
||||
if not self.called:
|
||||
self.init(cr, user)
|
||||
self.called = True # To make sure that init doesn't get called multiple times
|
||||
|
||||
res = super(report_aged_receivable, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
|
||||
return res
|
||||
|
||||
def _calc_bal(self, cr, uid, ids, name, args, context):
|
||||
res = {}
|
||||
for period in self.read(cr,uid,ids,['name']):
|
||||
date1,date2 = period['name'].split(' to ')
|
||||
se = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \
|
||||
WHERE (line.account_id=ac.id) AND ac.type='receivable' \
|
||||
AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \
|
||||
AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1))
|
||||
cr.execute(se)
|
||||
amount = cr.fetchone()
|
||||
amount = amount[0] or 0.00
|
||||
res[period['id']] = amount
|
||||
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Month Range', size=7, readonly=True),
|
||||
'balance': fields.function(_calc_bal, method=True, string='Balance', readonly=True),
|
||||
}
|
||||
|
||||
def init(self, cr, uid=1):
|
||||
""" This view will be used in dashboard
|
||||
"""
|
||||
# ranges = _get_ranges(cr) # Gets the ranges for the x axis of the graph (name column values)
|
||||
pool_obj_fy = pooler.get_pool(cr.dbname).get('account.fiscalyear')
|
||||
today = mx.DateTime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') - mx.DateTime.RelativeDateTime(days=1)
|
||||
today = today.strftime('%Y-%m-%d')
|
||||
fy_id = pool_obj_fy.find(cr,uid)
|
||||
LIST_RANGES = []
|
||||
if fy_id:
|
||||
fy_start_date = pool_obj_fy.read(cr, uid, fy_id, ['date_start'])['date_start']
|
||||
fy_start_date = mx.DateTime.strptime(fy_start_date, '%Y-%m-%d')
|
||||
last_month = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1)
|
||||
|
||||
while (last_month > fy_start_date):
|
||||
LIST_RANGES.append(today + " to " + last_month.strftime('%Y-%m-%d'))
|
||||
today = last_month.strftime('%Y-%m-%d')
|
||||
last_month = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1)
|
||||
|
||||
LIST_RANGES.append(today +" to " + fy_start_date.strftime('%Y-%m-%d'))
|
||||
cr.execute('delete from temp_range')
|
||||
for range in LIST_RANGES:
|
||||
pooler.get_pool(cr.dbname).get('temp.range').create(cr, uid, {'name':range})
|
||||
|
||||
cr.execute("""
|
||||
create or replace view report_aged_receivable as (
|
||||
select id,name from temp_range
|
||||
)""")
|
||||
|
||||
report_aged_receivable()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -49,5 +49,37 @@
|
|||
</record>
|
||||
<menuitem action="action_account_receivable_graph" id="menu_account_receivable_graph" parent="account.menu_finance_reporting"/>
|
||||
|
||||
<!-- Report for Aged Receivable -->
|
||||
|
||||
<record id="view_aged_recv_graph" model="ir.ui.view">
|
||||
<field name="name">report.aged.receivable.graph</field>
|
||||
<field name="model">report.aged.receivable</field>
|
||||
<field name="type">graph</field>
|
||||
<field name="arch" type="xml">
|
||||
<graph string="Aged Receivable" type="bar">
|
||||
<field name="name"/>
|
||||
<field name="balance" operator="+"/>
|
||||
</graph>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_aged_recv_tree" model="ir.ui.view">
|
||||
<field name="name">report.aged.receivable.tree</field>
|
||||
<field name="model">report.aged.receivable</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Aged Receivable">
|
||||
<field name="name"/>
|
||||
<field name="balance"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_aged_receivable_graph" model="ir.actions.act_window">
|
||||
<field name="name">Aged Receivable</field>
|
||||
<field name="res_model">report.aged.receivable</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">graph,tree</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue