shift_counter_event.py 1.76 KB
Newer Older
François C. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import api, fields, models


class ShiftCounterEvent(models.Model):
    _name = 'shift.counter.event'
    _order = 'create_date desc, partner_id asc'

    TYPE_SELECTION = [
        ('standard', 'Standard'),
        ('ftop', 'FTOP'),
    ]

    name = fields.Char(string="Description", required=True)
    shift_id = fields.Many2one(comodel_name='shift.shift', string="Shift")
    type = fields.Selection(
        string='Type', required=True, selection=TYPE_SELECTION)
    partner_id = fields.Many2one(
        string='Partner', comodel_name='res.partner', required=True,
        select=True)
    is_manual = fields.Boolean('Manual', readonly=True, default=True)
    point_qty = fields.Integer(string='Point Quantity', required=True)
    ignored = fields.Boolean(
        string="Ignored",
        readonly=True,
        help="Don't take into account when evaluating the member's status")
    notes = fields.Text(string="Notes")
    is_changed = fields.Boolean("Changed",
                                compute="_compute_is_changed")

    @api.model
    def create(self, vals):
        '''
        Overwrite the function to
            - Update manual update
        '''
        context = self._context
        if context.get('automatic', False):
            vals['is_manual'] = False

        return super(ShiftCounterEvent, self).create(vals)

    @api.multi
    @api.depends('create_date', 'write_date')
    def _compute_is_changed(self):
        for record in self:
            if record.create_date != record.write_date:
                record.is_changed = True