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.

37 lines
1.7 KiB

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