[REF] hr_timesheet_sheet: replace workflow by python code
Note that to copy the workflow, just after creating the state is updated to draft. The 'New' state is not used anymore in the flow. It could probably be cleaned. However in this task we only remove the workflows without changing their behavior to avoid unwanted side effects.
This commit is contained in:
committed by
Thibault Delavallée
parent
74538fbc4b
commit
ec01c4b089
@@ -66,12 +66,12 @@ class HrTimesheetSheet(models.Model):
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def button_confirm(self):
|
||||
def action_timesheet_confirm(self):
|
||||
for sheet in self:
|
||||
sheet.check_employee_attendance_state()
|
||||
di = sheet.user_id.company_id.timesheet_max_difference
|
||||
if (abs(sheet.total_difference) <= di) or not di:
|
||||
return super(HrTimesheetSheet, self).button_confirm()
|
||||
return super(HrTimesheetSheet, self).action_timesheet_confirm()
|
||||
else:
|
||||
raise UserError(_('Please verify that the total difference of the sheet is lower than %.2f.') % (di,))
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestHrTimesheetSheet(TransactionCase):
|
||||
# I confirm Gilles' timesheet with over 1 hour difference
|
||||
# in attendance and actual worked hours
|
||||
try:
|
||||
self.test_timesheet_sheet.button_confirm()
|
||||
self.test_timesheet_sheet.action_timesheet_confirm()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -67,7 +67,7 @@ class TestHrTimesheetSheet(TransactionCase):
|
||||
|
||||
# I confirm Gilles' timesheet with less than 1 hour difference
|
||||
# in attendance and actual worked hours
|
||||
self.test_timesheet_sheet.button_confirm()
|
||||
self.test_timesheet_sheet.action_timesheet_confirm()
|
||||
|
||||
# I check the state is confirmed
|
||||
assert self.test_timesheet_sheet.state == 'confirm'
|
||||
|
||||
@@ -30,7 +30,6 @@ The validation can be configured in the company:
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'security/hr_timesheet_sheet_security.xml',
|
||||
'data/hr_timesheet_workflow.xml',
|
||||
'data/hr_timesheet_sheet_data.xml',
|
||||
'views/hr_timesheet_sheet_templates.xml',
|
||||
'views/hr_timesheet_sheet_views.xml',
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Workflow definition -->
|
||||
|
||||
<record id="wkf_timesheet" model="workflow">
|
||||
<field name="name">hr_timesheet_sheet.sheet</field>
|
||||
<field name="osv">hr_timesheet_sheet.sheet</field>
|
||||
<field name="on_create">True</field>
|
||||
</record>
|
||||
|
||||
<record id="act_new" model="workflow.activity">
|
||||
<field name="wkf_id" ref="wkf_timesheet"/>
|
||||
<field name="name">new</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">write({'state':'new'})</field>
|
||||
<field name="flow_start">True</field>
|
||||
</record>
|
||||
<record id="act_draft" model="workflow.activity">
|
||||
<field name="wkf_id" ref="wkf_timesheet"/>
|
||||
<field name="name">draft</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">write({'state':'draft'})</field>
|
||||
</record>
|
||||
<record id="act_confirm" model="workflow.activity">
|
||||
<field name="wkf_id" ref="wkf_timesheet"/>
|
||||
<field name="name">confirm</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">write({'state':'confirm'})</field>
|
||||
</record>
|
||||
<record id="act_done" model="workflow.activity">
|
||||
<field name="wkf_id" ref="wkf_timesheet"/>
|
||||
<field name="name">done</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">write({'state':'done'})</field>
|
||||
<field name="flow_stop">True</field>
|
||||
</record>
|
||||
|
||||
<record id="t0" model="workflow.transition">
|
||||
<field name="act_from" ref="act_new"/>
|
||||
<field name="act_to" ref="act_draft"/>
|
||||
<field name="group_id" ref="base.group_user"/>
|
||||
</record>
|
||||
<record id="t1" model="workflow.transition">
|
||||
<field name="act_from" ref="act_draft"/>
|
||||
<field name="act_to" ref="act_confirm"/>
|
||||
<field name="signal">confirm</field>
|
||||
<field name="group_id" ref="base.group_user"/>
|
||||
</record>
|
||||
<record id="t2" model="workflow.transition">
|
||||
<field name="act_from" ref="act_confirm"/>
|
||||
<field name="act_to" ref="act_done"/>
|
||||
<field name="signal">done</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
<record id="t3" model="workflow.transition">
|
||||
<field name="act_from" ref="act_confirm"/>
|
||||
<field name="act_to" ref="act_draft"/>
|
||||
<field name="signal">cancel</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -56,6 +56,8 @@ class HrTimesheetSheet(models.Model):
|
||||
readonly=True, states={
|
||||
'draft': [('readonly', False)],
|
||||
'new': [('readonly', False)]})
|
||||
# state is created in 'new', automatically goes to 'draft' when created. Then 'new' is never used again ...
|
||||
# (=> 'new' is completely useless)
|
||||
state = fields.Selection([
|
||||
('new', 'New'),
|
||||
('draft', 'Open'),
|
||||
@@ -102,7 +104,9 @@ class HrTimesheetSheet(models.Model):
|
||||
if 'employee_id' in vals:
|
||||
if not self.env['hr.employee'].browse(vals['employee_id']).user_id:
|
||||
raise UserError(_('In order to create a timesheet for this employee, you must link him/her to a user.'))
|
||||
return super(HrTimesheetSheet, self).create(vals)
|
||||
res = super(HrTimesheetSheet, self).create(vals)
|
||||
res.write({'state': 'draft'})
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
@@ -114,19 +118,28 @@ class HrTimesheetSheet(models.Model):
|
||||
return super(HrTimesheetSheet, self).write(vals)
|
||||
|
||||
@api.multi
|
||||
def button_confirm(self):
|
||||
for sheet in self:
|
||||
if sheet.employee_id and sheet.employee_id.parent_id and sheet.employee_id.parent_id.user_id:
|
||||
self.message_subscribe_users(user_ids=[sheet.employee_id.parent_id.user_id.id])
|
||||
sheet.signal_workflow('confirm')
|
||||
def action_timesheet_draft(self):
|
||||
if not self.env.user.has_group('base.group_hr_user'):
|
||||
raise UserError(_('Only an HR Officer or Manager can refuse timesheets or reset them to draft.'))
|
||||
self.write({'state': 'draft'})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def action_set_to_draft(self):
|
||||
self.write({'state': 'draft'})
|
||||
self.create_workflow()
|
||||
def action_timesheet_confirm(self):
|
||||
for sheet in self:
|
||||
if sheet.employee_id and sheet.employee_id.parent_id and sheet.employee_id.parent_id.user_id:
|
||||
self.message_subscribe_users(user_ids=[sheet.employee_id.parent_id.user_id.id])
|
||||
self.write({'state': 'confirm'})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def action_timesheet_done(self):
|
||||
if not self.env.user.has_group('base.group_hr_user'):
|
||||
raise UserError(_('Only an HR Officer or Manager can approve timesheets.'))
|
||||
if self.filtered(lambda sheet: sheet.state != 'confirm'):
|
||||
raise UserError(_("Cannot approve a non-submitted timesheet."))
|
||||
self.write({'state': 'done'})
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
# week number according to ISO 8601 Calendar
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Timesheet">
|
||||
<header>
|
||||
<button name="button_confirm" states="draft" string="Submit to Manager" type="object" class="oe_highlight"/>
|
||||
<button name="done" states="confirm" string="Approve" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
|
||||
<button name="action_set_to_draft" states="done" string="Set to Draft" type="object" />
|
||||
<button name="cancel" states="confirm" string="Refuse" type="workflow" groups="base.group_hr_user" />
|
||||
<button name="action_timesheet_confirm" states="draft" string="Submit to Manager" type="object" class="oe_highlight"/>
|
||||
<button name="action_timesheet_done" states="confirm" string="Approve" type="object" groups="base.group_hr_user" class="oe_highlight"/>
|
||||
<button name="action_timesheet_draft" states="done" string="Set to Draft" type="object" groups="base.group_hr_user"/>
|
||||
<button name="action_timesheet_draft" states="confirm" string="Refuse" type="object" groups="base.group_hr_user"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="new,confirm,done"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
||||
Reference in New Issue
Block a user