HR_TIMESHEET_SHEET, CLIENT, KERNEL: improve hr_timesheet_sheet, add context to one2many, improve error message for orm

bzr revid: ced-45596d43ab63775e008e5e629bebb06564ebbfa2
This commit is contained in:
ced 2007-03-26 13:52:53 +00:00
parent 45674fbabe
commit 089863c406
9 changed files with 401 additions and 81 deletions

View File

@ -124,7 +124,7 @@ class hr_employee(osv.osv):
res = {'action':'action', 'employee_id':emp.id}
if dt:
res['name'] = dt
att_id = self.pool.get('hr.attendance').create(cr, uid, res)
att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
return True
def sign_out(self, cr, uid, ids, context={}, dt=False, *args):
@ -135,8 +135,8 @@ class hr_employee(osv.osv):
res = {'action':'sign_out', 'employee_id':emp.id}
if dt:
res['name'] = dt
att_id = self.pool.get('hr.attendance').create(cr, uid, res)
self.write(cr, uid, [emp.id], {'state':'absent'})
att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
self.write(cr, uid, [emp.id], {'state':'absent'}, context=context)
id = att_id
return id
@ -153,8 +153,8 @@ class hr_employee(osv.osv):
res = {'action':'sign_in', 'employee_id':emp.id}
if dt:
res['name'] = dt
id = self.pool.get('hr.attendance').create(cr, uid, res)
self.write(cr, uid, [emp.id], {'state':'present'})
id = self.pool.get('hr.attendance').create(cr, uid, res, context=context)
self.write(cr, uid, [emp.id], {'state':'present'}, context=context)
return id
hr_employee()

View File

@ -147,102 +147,102 @@
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance1">
<field name="name">2005-05-04 08:21</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance2">
<field name="name">2005-05-04 11:51</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance3">
<field name="name">2005-05-04 12:47</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance4">
<field name="name">2005-05-04 19:53</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance5">
<field name="name">2005-05-05 07:32</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance6">
<field name="name">2005-05-05 12:32</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance7">
<field name="name">2005-05-05 14:01</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance8">
<field name="name">2005-05-05 17:21</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance9">
<field name="name">2005-05-06 09:10</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance10">
<field name="name">2005-05-06 12:42</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance11">
<field name="name">2005-05-06 13:10</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance12">
<field name="name">2005-05-06 18:34</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance13">
<field name="name">2005-05-07 08:21</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance14">
<field name="name">2005-05-07 18:21</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance15">
<field name="name">2005-05-08 08:21</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance16">
<field name="name">2005-05-08 12:54</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance17">
<field name="name">2005-05-08 13:32</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance18">
<field name="name">2005-05-08 19:31</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance19">
<field name="name">2005-05-26 07:10</field>
<field name="action">sign_in</field>
<field name="employee_id" ref="employee1" />
</record>
<record model="hr.attendance">
<record model="hr.attendance" id="attendance20">
<field name="name">2005-05-26 12:34</field>
<field name="action">sign_out</field>
<field name="employee_id" ref="employee1" />

View File

@ -5,9 +5,9 @@
"category" : "Generic Modules/Human Resources",
"website" : "http://tinyerp.com/module_hr.html",
"description": "Timesheet system, completly integrated with the cost accounting module. It allows you to set up a management by affair.",
"depends" : ["account", "hr"],
"depends" : ["account", "hr", "base",],
"init_xml" : ["hr_timesheet_data.xml"],
"demo_xml" : ["hr_timesheet_demo.xml","hr.analytic.timesheet.csv"],
"demo_xml" : ["hr_timesheet_demo.xml",],
"update_xml" : ["hr_timesheet_view.xml", "hr_timesheet_report.xml","hr_timesheet_wizard.xml"],
"active": False,
"installable": True

View File

@ -1,10 +0,0 @@
amount,date,name,unit_amount,account_id,product_id,product_uom_id,user_id,journal_id,general_account_id
-240.0,2007-01-02,Letters,8.0,Administratif,DEV,Hour,admin,Timesheet Journal,%
-120.0,2007-01-03,Support by phone,4.0,Seagate P1,DEV,Hour,admin,Timesheet Journal,%
-120.0,2007-01-03,Support,4.0,Seagate P2,DEV,Hour,admin,Timesheet Journal,%
-240.0,2007-01-04,Repport on this,8.0,Seagate P1,DEV,Hour,admin,Timesheet Journal,%
-240.0,2007-01-05,Repport on that,8.0,Seagate P1,DEV,Hour,admin,Timesheet Journal,%
-240.0,2007-01-08,Phone support,8.0,Sednacom,DEV,Hour,admin,Timesheet Journal,%
-210.0,2007-01-09,Phone support on reporting engine,7.0,Camp To Camp,DEV,Hour,admin,Timesheet Journal,%
-240.0,2007-01-10,Quotation 234 done,8.0,Agrolait,DEV,Hour,demo,Timesheet Journal,%
-240.0,2007-01-11,Quotation 356,8.0,Agrolait,DEV,Hour,admin,Timesheet Journal,%
1 amount date name unit_amount account_id product_id product_uom_id user_id journal_id general_account_id
2 -240.0 2007-01-02 Letters 8.0 Administratif DEV Hour admin Timesheet Journal %
3 -120.0 2007-01-03 Support by phone 4.0 Seagate P1 DEV Hour admin Timesheet Journal %
4 -120.0 2007-01-03 Support 4.0 Seagate P2 DEV Hour admin Timesheet Journal %
5 -240.0 2007-01-04 Repport on this 8.0 Seagate P1 DEV Hour admin Timesheet Journal %
6 -240.0 2007-01-05 Repport on that 8.0 Seagate P1 DEV Hour admin Timesheet Journal %
7 -240.0 2007-01-08 Phone support 8.0 Sednacom DEV Hour admin Timesheet Journal %
8 -210.0 2007-01-09 Phone support on reporting engine 7.0 Camp To Camp DEV Hour admin Timesheet Journal %
9 -240.0 2007-01-10 Quotation 234 done 8.0 Agrolait DEV Hour demo Timesheet Journal %
10 -240.0 2007-01-11 Quotation 356 8.0 Agrolait DEV Hour admin Timesheet Journal %

View File

@ -31,5 +31,115 @@
<field name="product_id" ref="product_consultant"/>
<field name="journal_id" ref="analytic_journal"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet1">
<field name="amount">-240.0</field>
<field name="date">2005-05-04</field>
<field name="name">Letters</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Administratif')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet2">
<field name="amount">-120.0</field>
<field name="date">2005-05-05</field>
<field name="name">Support by phone</field>
<field name="unit_amount">4.0</field>
<field name="account_id" search="[('name','=', 'Seagate P1')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet3">
<field name="amount">-120.0</field>
<field name="date">2005-05-05</field>
<field name="name">Support</field>
<field name="unit_amount">4.0</field>
<field name="account_id" search="[('name','=', 'Seagate P2')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet4">
<field name="amount">-240.0</field>
<field name="date">2005-05-06</field>
<field name="name">Repport on this</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Seagate P1')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet5">
<field name="amount">-240.0</field>
<field name="date">2005-05-06</field>
<field name="name">Repport on that</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Seagate P1')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet6">
<field name="amount">-240.0</field>
<field name="date">2005-05-07</field>
<field name="name">Phone support</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Sednacom')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet7">
<field name="amount">-210.0</field>
<field name="date">2005-05-08</field>
<field name="name">Phone support on reporting engine</field>
<field name="unit_amount">7.0</field>
<field name="account_id" search="[('name','=', 'Camp To Camp')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet8">
<field name="amount">-210.0</field>
<field name="date">2005-05-09</field>
<field name="name">Quotation 234 done</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Agrolait')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
<record model="hr.analytic.timesheet" id="analytic_timesheet9">
<field name="amount">-210.0</field>
<field name="date">2005-05-10</field>
<field name="name">Quotation 356</field>
<field name="unit_amount">8.0</field>
<field name="account_id" search="[('name','=', 'Agrolait')]" model="account.analytic.account"/>
<field name="product_id" ref="hr_timesheet.product_consultant"/>
<field name="product_uom_id" ref="hr_timesheet.uom_hour"/>
<field name="user_id" ref="base.user_admin"/>
<field name="journal_id" ref="analytic_journal"/>
<field name="general_account_id" ref="account.a_recv"/>
</record>
</data>
</terp>

View File

@ -7,7 +7,7 @@
"description": "Timesheet by sheets",
"depends" : ["hr_timesheet", "hr_timesheet_project", "hr_timesheet_invoice"],
"init_xml" : [],
"demo_xml" : [],
"demo_xml" : ["hr_timesheet_sheet_demo.xml",],
"update_xml" : ["hr_timesheet_sheet_view.xml", "hr_timesheet_workflow.xml"],
"active": False,
"installable": True

View File

@ -161,46 +161,56 @@ class hr_timesheet_sheet(osv.osv):
return True
def date_today(self, cr, uid, ids, context):
self.write(cr, uid, ids, {
'date_current': time.strftime('%Y-%m-%d')
})
for sheet in self.browse(cr, uid, ids, context):
if DateTime.now() <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
elif DateTime.now() >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
else:
self.write(cr, uid, [sheet.id], {'date_current': time.strftime('%Y-%m-%d')})
return True
def date_previous(self, cr, uid, ids, context):
for sheet in self.browse(cr, uid, ids, context):
self.write(cr, uid, [sheet.id], {
'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=-1)).strftime('%Y-%m-%d'),
})
if DateTime.strptime(sheet.date_current, '%Y-%m-%d') <= DateTime.strptime(sheet.date_from, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,})
else:
self.write(cr, uid, [sheet.id], {
'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=-1)).strftime('%Y-%m-%d'),
})
return True
def date_next(self, cr, uid, ids, context):
for sheet in self.browse(cr, uid, ids, context):
self.write(cr, uid, [sheet.id], {
'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d'),
})
if DateTime.strptime(sheet.date_current, '%Y-%m-%d') >= DateTime.strptime(sheet.date_to, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,})
else:
self.write(cr, uid, [sheet.id], {
'date_current': (DateTime.strptime(sheet.date_current, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d'),
})
return True
def sign_in(self, cr, uid, ids, context):
emp_obj = self.pool.get('hr.employee')
emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
success = emp_obj.sign_in(cr, uid, emp_id)
self.pool.get('hr.attendance').write(cr, uid, [success], {'sheet_id': ids[0]})
context['sheet_id']=ids[0]
success = emp_obj.sign_in(cr, uid, emp_id, context=context)
return True
def sign_out(self, cr, uid, ids, context):
emp_obj = self.pool.get('hr.employee')
emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
success = emp_obj.sign_out(cr, uid, emp_id)
self.pool.get('hr.attendance').write(cr, uid, [success], {'sheet_id': ids[0]})
context['sheet_id']=ids[0]
success = emp_obj.sign_out(cr, uid, emp_id, context=context)
return True
_columns = {
'name': fields.char('Description', size=64, select=1),
'user_id': fields.many2one('res.users', 'User', required=True, select=1),
'date_from': fields.date('Date from', required=True, select=1),
'date_to': fields.date('Date to', required=True, select=1),
'date_from': fields.date('Date from', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
'date_to': fields.date('Date to', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
'date_current': fields.date('Current date', required=True),
'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),
'timesheet_ids' : one2many_mod('hr.analytic.timesheet', 'sheet_id', 'Timesheets', domain=[('date','=',time.strftime('%Y-%m-%d'))], readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
'state' : fields.selection([('new', 'New'),('draft','Draft'),('confirm','Confirmed'),('done','Done')], 'state', select=True, required=True, readonly=True),
'state_attendance' : fields.function(_state_attendance, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present'),('none','No employee defined')], string='Current state'),
'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'),
@ -236,18 +246,50 @@ class hr_timesheet_sheet(osv.osv):
'date_from' : _default_date_from,
'date_current' : lambda *a: time.strftime('%Y-%m-%d'),
'date_to' : _default_date_to,
'state': lambda *a: 'draft'
'state': lambda *a: 'new',
}
def create(self, cr, uid, vals, *args, **kwargs):
if 'state' in vals and vals['state'] == 'new':
vals['state']='draft'
cr.execute('select id from hr_timesheet_sheet_sheet where (date_from < %s and %s < date_to) or (date_from < %s and %s <date_to) or (date_from >= %s and date_to <= %s)', (vals['date_from'], vals['date_from'], vals['date_to'], vals['date_to'], vals['date_from'], vals['date_to']))
if cr.fetchall():
raise osv.except_osv('Error !', 'A timesheet sheet already exists in this period')
return super(hr_timesheet_sheet, self).create(cr, uid, vals, *args, **kwargs)
hr_timesheet_sheet()
def _get_current_sheet(self, cr, uid, context={}):
ts=self.pool.get('hr_timesheet_sheet.sheet')
ids = ts.search(cr, uid, [('user_id','=',uid),('state','=','draft'),('date_from','<=',time.strftime('%Y-%m-%d')), ('date_to','>=',time.strftime('%Y-%m-%d'))])
if ids:
return ids[0]
return False
class hr_timesheet_line(osv.osv):
_inherit = "account.analytic.line"
_inherit = "hr.analytic.timesheet"
def _get_default_date(self, cr, uid, context={}):
if 'date' in context:
return context['date']
return time.strftime('%Y-%m-%d')
def _sheet_date(self, cr, uid, ids):
timesheet_lines = self.browse(cr, uid, ids)
for l in timesheet_lines:
if l.date < l.sheet_id.date_from:
return False
if l.date > l.sheet_id.date_to:
return False
return True
_columns = {
'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', ondelete='set null', relate=True)
'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', ondelete='set null', required=True, relate=True)
}
_default = {
'sheet_id': lambda *a: False
_defaults = {
'sheet_id': _get_current_sheet,
'date': _get_default_date,
}
_constraints = [(_sheet_date, 'Error: the timesheet line date must be in the sheet\'s dates', ['date'])]
def create(self, cr, uid, vals, *args, **kwargs):
if 'sheet_id' in vals:
ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, vals['sheet_id'])
@ -269,24 +311,45 @@ hr_timesheet_line()
class hr_attendance(osv.osv):
_inherit = "hr.attendance"
def _get_default_date(self, cr, uid, context={}):
if 'name' in context:
return context['name'] + time.strftime(' %H:%M:%S')
return time.strftime('%Y-%m-%d %H:%M:%S')
def _sheet_date(self, cr, uid, ids):
attendances = self.browse(cr, uid, ids)
for att in attendances:
if att.name < att.sheet_id.date_from:
return False
if att.name > att.sheet_id.date_to:
return False
return True
_columns = {
'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', ondelete='set null', relate=True)
'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', ondelete='set null', required=True, relate=True)
}
_default = {
'sheet_id': lambda *a: False
_defaults = {
'sheet_id': _get_current_sheet,
'name': _get_default_date,
}
def create(self, cr, uid, vals, *args, **kwargs):
_constraints = [(_sheet_date, 'Error: the attendance date must be in the sheet\'s dates', ['name'])]
def create(self, cr, uid, vals, context={}):
if 'sheet_id' in context:
vals['sheet_id']=context['sheet_id']
if 'sheet_id' in vals:
ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, vals['sheet_id'])
if ts.state<>'draft':
raise osv.except_osv('Error !', 'You can not modify an entry in a confirmed timesheet !')
return super(hr_attendance,self).create(cr, uid, vals, *args, **kwargs)
return super(hr_attendance,self).create(cr, uid, vals, context=context)
def unlink(self, cr, uid, ids, *args, **kwargs):
self._check(cr, uid, ids)
return super(hr_attendance,self).unlink(cr, uid, ids,*args, **kwargs)
def write(self, cr, uid, ids, *args, **kwargs):
def write(self, cr, uid, ids, vals, context={}):
if 'sheet_id' in context:
vals['sheet_id']=context['sheet_id']
self._check(cr, uid, ids)
return super(hr_attendance,self).write(cr, uid, ids,*args, **kwargs)
return super(hr_attendance,self).write(cr, uid, ids, vals, context=context)
def _check(self, cr, uid, ids):
for att in self.browse(cr, uid, ids):
if att.sheet_id and att.sheet_id.state<>'draft':
@ -307,7 +370,7 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
def _total_attendance(self, cr, uid, ids, name, args, context):
result = {}
for day in self.browse(cr, uid, ids, context):
cr.execute('select name,action from hr_attendance where name>=%s and name<=%s order by name', (day.name, day.name+' 23:59:59'))
cr.execute('select name,action from hr_attendance where name>=%s and name<=%s and sheet_id=%d order by name', (day.name, day.name+' 23:59:59', day.sheet_id))
attendences = cr.dictfetchall()
wh = 0
if attendences and attendences[0]['action'] == 'sign_out':
@ -336,13 +399,14 @@ class hr_timesheet_sheet_sheet_day(osv.osv):
cr.execute("""create or replace view hr_timesheet_sheet_sheet_day as
(
select
min(l.oid) as id,
min(hrt.id) as id,
l.date as name,
l.sheet_id as sheet_id,
hrt.sheet_id as sheet_id,
sum(l.unit_amount) as total_timesheet
from
account_analytic_line l
group by l.date, l.sheet_id
hr_analytic_timesheet hrt
left join account_analytic_line l on (l.id = hrt.line_id)
group by l.date, hrt.sheet_id
) union (
select
min(a.oid) as id,
@ -370,13 +434,14 @@ class hr_timesheet_sheet_sheet_account(osv.osv):
def init(self, cr):
cr.execute("""create or replace view hr_timesheet_sheet_sheet_account as (
select
min(id) as id,
account_id as name,
sheet_id as sheet_id,
sum(unit_amount) as total
min(hrt.id) as id,
l.account_id as name,
hrt.sheet_id as sheet_id,
sum(l.unit_amount) as total
from
account_analytic_line
group by account_id, sheet_id
hr_analytic_timesheet hrt
left join account_analytic_line l on (l.id = hrt.line_id)
group by l.account_id, hrt.sheet_id
)""")
hr_timesheet_sheet_sheet_account()

View File

@ -0,0 +1,101 @@
<?xml version="1.0"?>
<terp>
<data noupdate="1">
<record model="hr_timesheet_sheet.sheet" id="sheet1">
<field name="name">Sheet 1</field>
<field name="user_id" search="[('login','=','admin')]" model="res.users"/>
<field name="date_from">2005-05-01</field>
<field name="date_to">2005-05-31</field>
<field name="date_current">2005-05-04</field>
</record>
<record model="hr.attendance" id="hr.attendance1">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance2">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance3">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance4">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance5">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance6">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance7">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance8">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance9">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance10">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance11">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance12">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance13">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance14">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance15">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance16">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance17">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance18">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance19">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.attendance" id="hr.attendance20">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet1">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet2">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet3">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet4">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet5">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet6">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet7">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet8">
<field name="sheet_id" ref="sheet1"/>
</record>
<record model="hr.analytic.timesheet" id="hr_timesheet.analytic_timesheet9">
<field name="sheet_id" ref="sheet1"/>
</record>
</data>
</terp>

View File

@ -56,7 +56,7 @@
</group>
<button string="Sign In" name="sign_in" type="object"/>
<button string="Sign Out" name="sign_out" type="object"/>
<field name="attendances_ids" colspan="4" nolabel="1">
<field name="attendances_ids" colspan="4" nolabel="1" context="name=date_current">
<tree string="Attendances">
<field name="employee_id"/>
<field name="name"/>
@ -65,7 +65,7 @@
</field>
<field name="state_attendance"/>
<field name="total_attendance_day" widget="float_time"/>
<field name="timesheet_ids" colspan="4" nolabel="1" domain="[('name','=',date_current)]">
<field name="timesheet_ids" colspan="4" nolabel="1" domain="[('name','=',date_current)]" context="date=date_current">
<tree string="Timesheet" editable="top">
<field name="user_id" required="1"/>
<field name="date" />
@ -200,5 +200,59 @@
</field>
</record>
<!--
hr.analytic.timesheet inheritancy
-->
<record model="ir.ui.view" id="hr_timesheet_line_tree">
<field name="name">hr.analytic.timesheet.tree</field>
<field name="model">hr.analytic.timesheet</field>
<field name="type">tree</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="sheet_id"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="hr_timesheet_line_form">
<field name="name">hr.analytic.timesheet.form</field>
<field name="model">hr.analytic.timesheet</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_form"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="sheet_id"/>
</field>
</field>
</record>
<!--
hr.attendance inheritancy
-->
<record model="ir.ui.view" id="view_attendance_form">
<field name="name">hr.attendance.form</field>
<field name="model">hr.attendance</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr.view_attendance_form"/>
<field name="arch" type="xml">
<field name="action_desc" position="after">
<field name="sheet_id"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_attendance_tree">
<field name="name">hr.attendance.tree</field>
<field name="model">hr.attendance</field>
<field name="type">tree</field>
<field name="inherit_id" ref="hr.view_attendance_tree"/>
<field name="arch" type="xml">
<field name="action_desc" position="after">
<field name="sheet_id"/>
</field>
</field>
</record>
</data>
</terp>