Timesheet
bzr revid: pinky-970b9a72923a1021b5753707b850d22d6d3f4b03
This commit is contained in:
parent
64216c3578
commit
f5284f3bd8
|
@ -33,6 +33,46 @@ from osv import osv
|
|||
|
||||
from mx import DateTime
|
||||
|
||||
class one2many_mod2(fields.one2many):
|
||||
def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = []
|
||||
|
||||
res5 = obj.read(cr, user, ids, ['date_current'], context)
|
||||
res6 = {}
|
||||
for r in res5:
|
||||
res6[r['id']] = r['date_current']
|
||||
|
||||
for id in ids:
|
||||
dom = []
|
||||
if id in res6:
|
||||
dom = [('name','>=',res6[id]+' 00:00:00'),('name','<=',res6[id]+' 23:59:59')]
|
||||
ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'=',id)]+dom, limit=self._limit)
|
||||
for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
|
||||
res[r[self._fields_id]].append( r['id'] )
|
||||
return res
|
||||
|
||||
|
||||
class one2many_mod(fields.one2many):
|
||||
def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = []
|
||||
|
||||
res5 = obj.read(cr, user, ids, ['date_current'], context)
|
||||
res6 = {}
|
||||
for r in res5:
|
||||
res6[r['id']] = r['date_current']
|
||||
|
||||
for id in ids:
|
||||
dom = []
|
||||
if id in res6:
|
||||
dom = [('date','=',res6[id])]
|
||||
ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'=',id)]+dom, limit=self._limit)
|
||||
for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
|
||||
res[r[self._fields_id]].append( r['id'] )
|
||||
return res
|
||||
|
||||
class hr_timesheet_sheet(osv.osv):
|
||||
_name = "hr_timesheet_sheet.sheet"
|
||||
|
@ -132,8 +172,8 @@ class hr_timesheet_sheet(osv.osv):
|
|||
'date_from': fields.date('Date from', required=True, select=1),
|
||||
'date_to': fields.date('Date to', required=True, select=1),
|
||||
'date_current': fields.date('Current date', required=True),
|
||||
'timesheet_ids' : fields.one2many('hr.analytic.timesheet', 'sheet_id', 'Timesheets', domain=[('date','=',time.strftime('%Y-%m-%d'))], readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'attendances_ids' : fields.one2many('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'timesheet_ids' : one2many_mod('hr.analytic.timesheet', 'sheet_id', 'Timesheets', domain=[('date','=',time.strftime('%Y-%m-%d'))], readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'state' : fields.selection([('draft','Draft'),('confirm','Confirmed'),('done','Done')], 'state', select=True, required=True, readonly=True),
|
||||
'total_attendance_day': fields.function(_total_attendance_day, method=True, string='Total Attendance'),
|
||||
'total_timesheet_day': fields.function(_total_timesheet_day, method=True, string='Total Timesheet'),
|
||||
|
@ -246,19 +286,26 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
|
|||
'total_difference': fields.function(_total_difference, method=True, string='Difference', readonly=True),
|
||||
}
|
||||
def init(self, cr):
|
||||
cr.execute("""
|
||||
create or replace view hr_timesheet_sheet_sheet_day as (
|
||||
cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as
|
||||
(
|
||||
select
|
||||
min(case when l.oid is not null then l.oid else a.oid end) as id,
|
||||
min(case when l.date is not null then l.date else a.name::date end) as name,
|
||||
(case when l.sheet_id is not null then l.sheet_id else a.sheet_id end) as sheet_id,
|
||||
min(l.oid) as id,
|
||||
l.date as name,
|
||||
l.sheet_id as sheet_id,
|
||||
sum(l.unit_amount) as total_timesheet
|
||||
from
|
||||
account_analytic_line l
|
||||
full outer join
|
||||
hr_attendance a on ((a.name::date=l.date) and l.sheet_id=a.sheet_id)
|
||||
group by l.date,a.name::date, l.sheet_id,a.sheet_id
|
||||
group by l.date, l.sheet_id
|
||||
) union (
|
||||
select
|
||||
min(a.oid) as id,
|
||||
a.name::date as name,
|
||||
a.sheet_id as sheet_id,
|
||||
0.0 as total_timesheet
|
||||
from
|
||||
hr_attendance a
|
||||
where a.name::date not in (select distinct date from account_analytic_line)
|
||||
group by a.name::date, a.sheet_id
|
||||
)""")
|
||||
hr_timesheet_sheet_sheet_day()
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<field name="date_to" />
|
||||
<field name="name" />
|
||||
<field name="total_attendance"/>
|
||||
<field name="total_timesheet"/>
|
||||
<field name="total_difference"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
|
@ -34,9 +35,9 @@
|
|||
<page string="Daily view">
|
||||
<group col="4" colspan="2">
|
||||
<field name="date_current" nolabel="1"/>
|
||||
<button string="<<" name="date_previous" type="object"/>
|
||||
<button string="GO" name="reload"/>
|
||||
<button string=">>" name="date_next" type="object"/>
|
||||
<button icon="STOCK_MEDIA_PREVIOUS" string="" name="date_previous" type="object"/>
|
||||
<button icon="STOCK_JUMP_TO" string="" name="reload"/>
|
||||
<button icon="STOCK_MEDIA_NEXT" string="" name="date_next" type="object"/>
|
||||
</group>
|
||||
<button string="Sign In" name="sign_in" type="object"/>
|
||||
<button string="Sign Out" name="sign_out" type="object"/>
|
||||
|
|
Loading…
Reference in New Issue