_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()