Commit ce2669f1 by François C.

Merge branch 'fix_change_service_state_on_leave_creation' into 'dev_principale'

Manage moved shift registration state modification (shift registration which are…

See merge request !10
parents 2c0b3517 03edb93e
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{ {
'name': 'Coop Shift', 'name': 'Coop Shift',
'version': '9.0.7.0.0', 'version': '9.0.7.0.1',
'category': 'Tools', 'category': 'Tools',
'author': 'Julien WESTE, Sylvain LE GAL, Cyril Gaspard, La Louve', 'author': 'Julien WESTE, Sylvain LE GAL, Cyril Gaspard, La Louve',
'website': 'http://www.lalouve.net', 'website': 'http://www.lalouve.net',
......
...@@ -104,19 +104,33 @@ class ShiftLeaveWizard(models.TransientModel): ...@@ -104,19 +104,33 @@ class ShiftLeaveWizard(models.TransientModel):
existed_line = line_obj.search([ existed_line = line_obj.search([
('registration_id', '=', registration_id), ('registration_id', '=', registration_id),
('date_begin', '=', leave_s_date), ('date_begin', '=', leave_s_date),
('state', '!=', 'waiting'), ('state', 'not in', ['waiting', 'cancel']),
]) ])
if existed_line: if existed_line:
existed_line.with_context(bypass_leave_change_check=True)\ existed_line.with_context(bypass_leave_change_check=True)\
.write({'state': 'waiting', 'leave_id': leave.id}) .write({'state': 'waiting', 'leave_id': leave.id})
else: else:
# Create new registration lines (type 'waiting') # Create new registration lines (type 'waiting')
line_obj.create({ try:
'registration_id': registration_id, line_obj.create({
'date_begin': leave_s_date, 'registration_id': registration_id,
'date_end': leave_e_date, 'date_begin': leave_s_date,
'state': 'waiting', 'date_end': leave_e_date,
'leave_id': leave.id, 'state': 'waiting',
}) 'leave_id': leave.id,
})
except:
# may occur when a shift registration has been canceled
pass
# Need to consider shift_registration made before member ask for leave
sr_obj = self.env['shift.registration']
shift_regs_to_modify = sr_obj.search([
('partner_id', '=', self.partner_id.id),
('state', 'not in', ['waiting', 'cancel']),
('date_begin', '>', leave_s_date),
('date_begin', '<=', leave_e_date)
])
for sr in shift_regs_to_modify:
sr.write({'state': 'waiting'})
leave.state = 'done' leave.state = 'done'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment