1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
28 from osv import fields,osv
31 def _code_get(self, cr, uid, context={}):
32 acc_type_obj = self.pool.get('account.account.type')
33 ids = acc_type_obj.search(cr, uid, [])
34 res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
35 return [(r['code'], r['name']) for r in res]
38 class report_account_receivable(osv.osv):
39 _name = "report.account.receivable"
40 _description = "Receivable accounts"
43 'name': fields.char('Week of Year', size=7, readonly=True),
44 'type': fields.selection(_code_get, 'Account Type', required=True),
45 'balance':fields.float('Balance', readonly=True),
46 'debit':fields.float('Debit', readonly=True),
47 'credit':fields.float('Credit', readonly=True),
53 create or replace view report_account_receivable as (
56 to_char(date,'YYYY:IW') as name,
57 sum(l.debit-l.credit) as balance,
58 sum(l.debit) as debit,
59 sum(l.credit) as credit,
64 account_account a on (l.account_id=a.id)
68 to_char(date,'YYYY:IW'), a.type
70 report_account_receivable()
72 #a.type in ('receivable','payable')
73 class temp_range(osv.osv):
75 _description = 'A Temporary table used for Dashboard view'
78 'name' : fields.char('Range',size=64)
83 class report_aged_receivable(osv.osv):
84 _name = "report.aged.receivable"
85 _description = "Aged Receivable Till Today"
88 def __init__(self, pool, cr):
89 super(report_aged_receivable, self).__init__(pool, cr)
92 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
93 """ To call the init() method timely
97 self.called = True # To make sure that init doesn't get called multiple times
99 res = super(report_aged_receivable, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
102 def _calc_bal(self, cr, uid, ids, name, args, context):
104 for period in self.read(cr,uid,ids,['name']):
105 date1,date2 = period['name'].split(' to ')
106 query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \
107 WHERE (line.account_id=ac.id) AND ac.type='receivable' \
108 AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \
109 AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1))
111 amount = cr.fetchone()
112 amount = amount[0] or 0.00
113 res[period['id']] = amount
118 'name': fields.char('Month Range', size=7, readonly=True),
119 'balance': fields.function(_calc_bal, method=True, string='Balance', readonly=True),
122 def init(self, cr, uid=1):
123 """ This view will be used in dashboard
125 # ranges = _get_ranges(cr) # Gets the ranges for the x axis of the graph (name column values)
126 pool_obj_fy = pooler.get_pool(cr.dbname).get('account.fiscalyear')
127 today = mx.DateTime.strptime(time.strftime('%Y-%m-%d'), '%Y-%m-%d') - mx.DateTime.RelativeDateTime(days=1)
128 today = today.strftime('%Y-%m-%d')
129 fy_id = pool_obj_fy.find(cr,uid)
132 fy_start_date = pool_obj_fy.read(cr, uid, fy_id, ['date_start'])['date_start']
133 fy_start_date = mx.DateTime.strptime(fy_start_date, '%Y-%m-%d')
134 last_month_date = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1)
136 while (last_month_date > fy_start_date):
137 LIST_RANGES.append(today + " to " + last_month_date.strftime('%Y-%m-%d'))
138 today = (last_month_date- 1).strftime('%Y-%m-%d')
139 last_month_date = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1)
141 LIST_RANGES.append(today +" to " + fy_start_date.strftime('%Y-%m-%d'))
142 cr.execute('delete from temp_range')
144 for range in LIST_RANGES:
145 pooler.get_pool(cr.dbname).get('temp.range').create(cr, uid, {'name':range})
148 create or replace view report_aged_receivable as (
149 select id,name from temp_range
152 report_aged_receivable()
154 class report_invoice_created(osv.osv):
155 _name = "report.invoice.created"
156 _description = "Report of Invoices Created within Last 15 days"
159 'name': fields.char('Description', size=64, readonly=True),
160 'type': fields.selection([
161 ('out_invoice','Customer Invoice'),
162 ('in_invoice','Supplier Invoice'),
163 ('out_refund','Customer Refund'),
164 ('in_refund','Supplier Refund'),
165 ],'Type', readonly=True),
166 'number': fields.char('Invoice Number', size=32, readonly=True),
167 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
168 'amount_untaxed': fields.float('Untaxed', readonly=True),
169 'amount_total': fields.float('Total', readonly=True),
170 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True),
171 'date_invoice': fields.date('Date Invoiced', readonly=True),
172 'date_due': fields.date('Due Date', readonly=True),
173 'residual': fields.float('Residual', readonly=True),
174 'state': fields.selection([
176 ('proforma','Pro-forma'),
177 ('proforma2','Pro-forma'),
180 ('cancel','Cancelled')
181 ],'State', readonly=True),
182 'origin': fields.char('Origin', size=64, readonly=True),
183 'create_date' : fields.datetime('Create Date', readonly=True)
185 _order = 'create_date'
188 cr.execute("""create or replace view report_invoice_created as (
190 inv.id as id, inv.name as name, inv.type as type,
191 inv.number as number, inv.partner_id as partner_id,
192 inv.amount_untaxed as amount_untaxed,
193 inv.amount_total as amount_total, inv.currency_id as currency_id,
194 inv.date_invoice as date_invoice, inv.date_due as date_due,
195 inv.residual as residual, inv.state as state,
196 inv.origin as origin, inv.create_date as create_date
200 (to_date(to_char(inv.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') < CURRENT_DATE)
202 (to_date(to_char(inv.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') >= (CURRENT_DATE-15))
204 report_invoice_created()
206 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: