You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.6 KiB

  1. from odoo import models, fields, api, _
  2. from odoo.exceptions import UserError
  3. class Subscribe(models.TransientModel):
  4. _name = 'beesdoo.shift.extension'
  5. _inherit = 'beesdoo.shift.action_mixin'
  6. def _get_default_extension_delay(self):
  7. return int(self.env['ir.config_parameter'].sudo().get_param('default_extension_delay', 28))
  8. extension_start_date = fields.Date(string="Start date for the extension", default=fields.Date.today, readonly=True)
  9. auto = fields.Boolean("Auto Extension", default=False)
  10. extension_days = fields.Integer(default=_get_default_extension_delay)
  11. @api.multi
  12. def auto_ext(self):
  13. self = self._check(group='beesdoo_shift.group_shift_attendance')
  14. status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
  15. status_id.sudo().write({'extension_start_time': self.extension_start_date})
  16. @api.multi
  17. def extension(self):
  18. self = self._check() #maybe a different group
  19. grace_delay = int(self.env['ir.config_parameter'].sudo().get_param('default_grace_delay', 10))
  20. status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
  21. if not status_id.extension_start_time:
  22. raise UserError(_('You should not make a manual extension when the grace delay has not been triggered yet'))
  23. today_delay = (status_id.today - status_id.extension_start_time).days - grace_delay
  24. if today_delay < 0:
  25. raise UserError(_('You should not start a manual extension during the grace delay'))
  26. status_id.sudo().write({'time_extension': self.extension_days + today_delay})