forked from Yaltik/golem
58 lines
2.4 KiB
Python
58 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2020 Fabien Bourgeois <fabien@yaltik.com>
|
|
# Copyright 2020 Youssef El Ouahby <youssef@yaltik.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
""" GOLEM Resources Adaptations """
|
|
|
|
from odoo import models, fields, api, _
|
|
|
|
|
|
class GolemResource(models.Model):
|
|
""" GOLEM Resource Model """
|
|
_inherit = 'golem.resource'
|
|
|
|
holiday_period_ids = fields.Many2many('golem.resource.holiday.period', string='Holiday period list')
|
|
|
|
holiday_selection_ids = fields.One2many('golem.resource.holiday.selection', 'resource_id',
|
|
string='Holiday selection')
|
|
|
|
@api.constrains('holiday_period_ids')
|
|
def synchronise_holiday_selection(self):
|
|
""" Synchronise holiday selection """
|
|
for resource in self:
|
|
period_ids = resource.holiday_period_ids.ids
|
|
|
|
#compute selections 2 remove from list if any
|
|
self.env['golem.resource.holiday.selection'].search([
|
|
('resource_id', '=', resource.id),
|
|
('period_id', 'not in', period_ids)
|
|
]).unlink()
|
|
#selection_2_remove.unlink()
|
|
|
|
#compute selection to add to list if any
|
|
if resource.holiday_period_ids:
|
|
existing_holiday = self.env['golem.resource.holiday.selection'].search([
|
|
('resource_id', '=', resource.id)]).mapped('holiday_id')
|
|
holiday_2_add = self.env['golem.resource.holiday'].search([
|
|
('period_id', 'in', period_ids)]) - existing_holiday
|
|
|
|
for holiday in holiday_2_add:
|
|
self.env['golem.resource.holiday.selection'].create({
|
|
'holiday_id' : holiday.id,
|
|
'resource_id': resource.id,
|
|
})
|