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.

34 lines
1.7 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'].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'].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. extension_date = fields.Date.from_string(status_id.extension_start_time)
  24. today = fields.Date.from_string(status_id.today)
  25. today_delay = (today - extension_date).days - grace_delay
  26. if today_delay < 0:
  27. raise UserError(_('You should not start a manual extension during the grace delay'))
  28. status_id.sudo().write({'time_extension': self.extension_days + today_delay})