From 3fe23e653216f4dfd9b8eba0012f16c6bcc4037c Mon Sep 17 00:00:00 2001 From: "Jay (Open ERP)" Date: Tue, 10 Mar 2009 15:34:32 +0530 Subject: [PATCH] Board_service : Corrected Random timesheet for My Department bzr revid: jvo@tinyerp.com-20090310100432-hcdrp9ek95t407g6 --- addons/report_timesheet/report_timesheet.py | 53 ++++++++++++--------- addons/report_timesheet/report_timesheet_view.xml | 11 ++--- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/addons/report_timesheet/report_timesheet.py b/addons/report_timesheet/report_timesheet.py index 0c901d4..1c526d3 100644 --- a/addons/report_timesheet/report_timesheet.py +++ b/addons/report_timesheet/report_timesheet.py @@ -159,37 +159,44 @@ class report_random_timsheet(osv.osv): _auto = False _columns = { - 'name': fields.char('Description', size=64, readonly=True), - 'date': fields.date('Date', readonly=True), 'analytic_account_id' : fields.many2one('account.analytic.account','Analytic Account', readonly=True), + 'name': fields.char('Description', size=64, readonly=True), 'quantity' : fields.float('Quantity', readonly=True), - 'product_id' : fields.many2one('product.product','Product', readonly=True), - 'amount' : fields.float('Amount', readonly=True), - 'uom_id' : fields.many2one('product.uom','UOM', readonly=True) - } + 'date': fields.date('Date', readonly=True), + 'user_id' : fields.many2one('res.users', 'User', readonly=True) + } _order = "date desc" - def init(self, cr): + def __init__(self, pool, cr): + super(report_random_timsheet, 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_random_timsheet, self).fields_view_get(cr, user, view_id, view_type, context, toolbar) + return res + + def init(self, cr, uid=1): + cr.execute("""create or replace view report_random_timesheet as ( - select line.id as id, line.name as name, line.date as date, - act.id as analytic_account_id, line.unit_amount as quantity, - prod.id as product_id, line.amount as amount, uom_uom.id as uom_id - - from account_analytic_line line - - left join account_analytic_account act on (line.account_id = act.id) - left join hr_employee emp on (line.user_id = emp.id) - left join hr_department dept on (dept.manager_id = emp.parent_id) - left join hr_department_user_rel dept_user on (line.user_id = dept_user.user_id) - left join product_template prod on (line.product_id = prod.id) - left join product_uom uom_uom on (line.product_uom_id = uom_uom.id) - - where (line.date < CURRENT_DATE AND line.date >= (CURRENT_DATE-3)) - + select + line.id as id, line.account_id as analytic_account_id, line.name as name, + line.unit_amount as quantity, line.date as date, line.user_id as user_id + from + account_analytic_line line, hr_department dept,hr_department_user_rel dept_user + where + (dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null) + AND (dept.manager_id = """ + str(uid) + """ ) + AND (line.date < CURRENT_DATE AND line.date >= (CURRENT_DATE-3)) ORDER BY line.name LIMIT 10 ) - """) + """ ) report_random_timsheet() diff --git a/addons/report_timesheet/report_timesheet_view.xml b/addons/report_timesheet/report_timesheet_view.xml index 4c61156..5bfe1ed 100644 --- a/addons/report_timesheet/report_timesheet_view.xml +++ b/addons/report_timesheet/report_timesheet_view.xml @@ -287,13 +287,10 @@ tree - - - - - - - + + + + -- 1.7.10.4