shift_registration.py 1.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# -*- coding: utf-8 -*-

from openerp import _, api, models, fields
import logging

_logger = logging.getLogger(__name__)

class ShiftRegistration(models.Model):
    _inherit = 'shift.registration'

    is_late = fields.Boolean(
        "Was the registration validated within grace period ?",
        default= False)
    is_makeup = fields.Boolean(
        "Is this registration a consequence of a makeup to do",
        default= False)
Etienne Freiss committed
17 18 19 20

    associate_registered = fields.Char(
        "Who will do the shift, partner, associate or both",
        default= False)
21
    
22 23 24
    should_increment_extra_shift_done = fields.Boolean(
        "Set to True when partners are both present. Used to detect if extra_shift_done is to be incremented when recording presences",
        default= False)
25

26 27 28
    cancellation_description = fields.Char(
        "So that the bdm can explain the reason for the registration cancellation and sign"
    )
29 30 31

    @api.multi
    def write(self, vals):
32 33 34
        conf = self.env['ir.config_parameter']
        absence_status = conf.get_param("lacagette_membership.absence_status")
        if 'state' in vals and vals['state'] == absence_status:
35 36 37
            if self.ids:
                for s in self.env['shift.registration']\
                         .search([('id', 'in', self.ids)]):
38 39 40
                    # it is the case when called from "absence cron job" run in external third-party
                    to_add = 2 if absence_status == 'absent' else 1

41 42 43
                    # Missing a makeup leads to have an additional makeup (the shift you initialy missed + the makeup you missed)
                    if s.is_makeup is True:
                        to_add += 1
44
                    new_makeups_to_do = s.partner_id.makeups_to_do + to_add
45
                    s.partner_id.update({'makeups_to_do': new_makeups_to_do})
46
        return super(ShiftRegistration, self).write(vals)