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 ##############################################################################
23 from osv import fields,osv
24 from tools.sql import drop_view_if_exists
26 class report_timesheet_user(osv.osv):
27 _name = "report_timesheet.user"
28 _description = "Timesheet per day"
31 'name': fields.date('Date', readonly=True),
32 'user_id':fields.many2one('res.users', 'User', readonly=True),
33 'quantity': fields.float('Quantity', readonly=True),
34 'cost': fields.float('Cost', readonly=True)
36 _order = 'name desc,user_id desc'
38 drop_view_if_exists(cr, 'report_timesheet_user')
40 create or replace view report_timesheet_user as (
45 sum(l.unit_amount) as quantity,
48 account_analytic_line l
51 group by l.date, l.user_id
54 report_timesheet_user()
56 class report_timesheet_account(osv.osv):
57 _name = "report_timesheet.account"
58 _description = "Timesheet per account"
61 'name': fields.date('Month', readonly=True),
62 'user_id':fields.many2one('res.users', 'User', readonly=True),
63 'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
64 'quantity': fields.float('Quantity', readonly=True),
66 _order = 'name desc,account_id desc,user_id desc'
68 drop_view_if_exists(cr, 'report_timesheet_account')
70 create or replace view report_timesheet_account as (
73 to_char(create_date, 'YYYY-MM-01') as name,
76 sum(unit_amount) as quantity
80 to_char(create_date, 'YYYY-MM-01'), user_id, account_id
83 report_timesheet_account()
86 class report_timesheet_account_date(osv.osv):
87 _name = "report_timesheet.account.date"
88 _description = "Daily timesheet per account"
91 'name': fields.date('Date', readonly=True),
92 'user_id':fields.many2one('res.users', 'User', readonly=True),
93 'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True),
94 'quantity': fields.float('Quantity', readonly=True),
96 _order = 'name desc,account_id desc,user_id desc'
99 drop_view_if_exists(cr, 'report_timesheet_account_date')
101 create or replace view report_timesheet_account_date as (
107 sum(unit_amount) as quantity
109 account_analytic_line
111 date, user_id, account_id
114 report_timesheet_account_date()
117 class report_timesheet_invoice(osv.osv):
118 _name = "report_timesheet.invoice"
119 _description = "Costs to invoice"
122 'user_id':fields.many2one('res.users', 'User', readonly=True),
123 'account_id':fields.many2one('account.analytic.account', 'Project', readonly=True),
124 'manager_id':fields.many2one('res.users', 'Manager', readonly=True),
125 'quantity': fields.float('Quantity', readonly=True),
126 'amount_invoice': fields.float('To invoice', readonly=True)
128 _rec_name = 'user_id'
129 _order = 'user_id desc'
131 drop_view_if_exists(cr, 'report_timesheet_invoice')
133 create or replace view report_timesheet_invoice as (
136 l.user_id as user_id,
137 l.account_id as account_id,
138 a.user_id as manager_id,
139 sum(l.unit_amount) as quantity,
140 sum(l.unit_amount * t.list_price) as amount_invoice
141 from account_analytic_line l
142 left join hr_timesheet_invoice_factor f on (l.to_invoice=f.id)
143 left join account_analytic_account a on (l.account_id=a.id)
144 left join product_product p on (l.to_invoice=f.id)
145 left join product_template t on (l.to_invoice=f.id)
147 l.to_invoice is not null and
155 report_timesheet_invoice()
157 class report_random_timsheet(osv.osv):
158 _name = "report.random.timesheet"
159 _description = "Random Timesheet Report"
163 'analytic_account_id' : fields.many2one('account.analytic.account','Analytic Account', readonly=True),
164 'name': fields.char('Description', size=64, readonly=True),
165 'quantity' : fields.float('Quantity', readonly=True),
166 'date': fields.date('Date', readonly=True),
167 'user_id' : fields.many2one('res.users', 'User', readonly=True)
171 def __init__(self, pool, cr):
172 super(report_random_timsheet, self).__init__(pool, cr)
175 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
176 """ To call the init() method timely
180 self.called = True # To make sure that init doesn't get called multiple times
182 res = super(report_random_timsheet, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
185 def init(self, cr, uid=1):
186 drop_view_if_exists(cr, 'report_random_timesheet')
188 cr.execute("""create or replace view report_random_timesheet as (
191 line.id as id, line.account_id as analytic_account_id, line.name as name,
192 line.unit_amount as quantity, line.date as date, line.user_id as user_id
194 account_analytic_line line, hr_department dept,hr_department_user_rel dept_user
196 (dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)
197 AND (dept.manager_id = """ + str(uid) + """ )
198 AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))
203 report_random_timsheet()
205 class random_timesheet_lines(osv.osv):
206 _name = "random.timesheet.lines"
207 _description = "Random Timesheet Lines"
211 'date': fields.date('Date', readonly=True),
212 'name': fields.char('Description', size=64, readonly=True),
213 'user_id' : fields.many2one('res.users', 'User', readonly=True),
214 'quantity' : fields.float('Quantity', readonly=True),
215 'product_id' : fields.many2one('product.product', 'Product', readonly=True),
216 'analytic_account_id' : fields.many2one('account.analytic.account','Analytic Account', readonly=True),
217 'uom_id' : fields.many2one('product.uom', 'UoM', readonly=True),
218 'amount' : fields.float('Amount', readonly=True),
219 'to_invoice': fields.many2one('hr_timesheet_invoice.factor', 'Invoicing', readonly=True),
220 'general_account_id' : fields.many2one('account.account', 'General Account', readonly=True)
226 drop_view_if_exists(cr, 'random_timesheet_lines')
228 cr.execute("""create or replace view random_timesheet_lines as (
230 line.id as id, line.date as date, line.name as name, line.unit_amount as quantity,
231 line.product_id as product_id, line.account_id as analytic_account_id,
232 line.product_uom_id as uom_id, line.amount as amount, line.to_invoice as to_invoice,
233 line.general_account_id as general_account_id, line.user_id as user_id
235 account_analytic_line line
237 (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-15))
241 random_timesheet_lines()
243 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: