huge improvement

This commit is contained in:
Youssef Elouahby 2020-05-22 19:53:24 +00:00
parent 517d743257
commit 0eddaab896
7 changed files with 93 additions and 18 deletions

View File

@ -18,4 +18,5 @@
from . import ( golem_resource_holiday, golem_resource_holiday_period, from . import ( golem_resource_holiday, golem_resource_holiday_period,
golem_resource, golem_resource_holiday_period_selection) golem_resource, golem_resource_holiday_selection,
golem_resource_reservation)

View File

@ -18,11 +18,40 @@
""" GOLEM Resources Adaptations """ """ GOLEM Resources Adaptations """
from odoo import models, fields from odoo import models, fields, api, _
class GolemResource(models.Model): class GolemResource(models.Model):
""" GOLEM Resource Model """ """ GOLEM Resource Model """
_inherit = 'golem.resource' _inherit = 'golem.resource'
holiday_period_selection = fields.One2many('golem.resource.holiday.period.selection', 'resource_id') 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,
})

View File

@ -35,13 +35,13 @@ class GolemResourceHoliday(models.Model):
date_start = fields.Date('Holiday start') date_start = fields.Date('Holiday start')
date_end = fields.Date('Holiday end') date_end = fields.Date('Holiday end')
@api.depends('period_id', 'date_start') @api.depends('period_id', 'date_start', 'date_end')
def _compute_name(self): def _compute_name(self):
""" Computes holiday name """ """ Computes holiday name """
for holiday in self: for holiday in self:
holiday.name = u'{}/{}/{}'.format(holiday.period_id.name, holiday.name = u'{}/{}:{}'.format(holiday.period_id.name,
holiday.date_start, holiday.date_start,
holiday.id) holiday.date_end)
@api.constrains('date_start', 'date_end') @api.constrains('date_start', 'date_end')
def _check_date_consistency(self): def _check_date_consistency(self):

View File

@ -16,17 +16,18 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" GOLEM Resource Holiday Period Selection Management """ """ GOLEM Resource Holiday Selection Management """
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
class GolemResourceHolidayPeriodSelection(models.Model): class GolemResourceHolidaySelection(models.Model):
""" GOLEM Resource Holiday Period Selection""" """ GOLEM Resource Holiday Selection"""
_name = 'golem.resource.holiday.period.selection' _name = 'golem.resource.holiday.selection'
_description = 'GOLEM Resource Holiday Period Selection Managementl' _description = 'GOLEM Resource Holiday Selection Management'
holiday_period_id = fields.Many2one('golem.resource.holiday.period', required=True) holiday_id = fields.Many2one('golem.resource.holiday', 'Holiday', required=True)
resource_id = fields.Many2one('golem.resource', required=True) resource_id = fields.Many2one('golem.resource', required=True)
is_reservation_possible = fields.Boolean() is_reservation_possible = fields.Boolean(string='Reservation during holiday')
period_id = fields.Many2one(related='holiday_id.period_id', store=True)

View File

@ -0,0 +1,41 @@
# -*- 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 Reservation Adaptations """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemResourceReservation(models.Model):
""" GOLEM Resource Reservation Model """
_inherit = 'golem.resource.reservation'
@api.constrains('resource_id', 'date_start', 'date_stop')
def check_resource_holiday_date(self):
for reservation in self:
resource_holiday = reservation.resource_id.holiday_selection_ids.filtered(lambda s: not s.is_reservation_possible)
if resource_holiday:
for holiday in resource_holiday:
if (holiday.holiday_id.date_start < reservation.date_start < holiday.holiday_id.date_end) or \
(holiday.holiday_id.date_start < reservation.date_stop < holiday.holiday_id.date_end):
raise ValidationError(_('This resource cannot be reserved during the'
' period between {} and {}, as there is a holiday, please choose '
'another date').format(holiday.holiday_id.date_start,
holiday.holiday_id.date_end
))

View File

@ -42,7 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<sheet> <sheet>
<group> <group>
<group> <group>
<field name="period_id"/> <field name="period_id" options="{'no_create': True}"/>
</group> </group>
<group> <group>
<field name="date_start"/> <field name="date_start"/>
@ -78,7 +78,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Menus --> <!-- Menus -->
<menuitem id="resource_holiday_root_menu" name="Resources Holiday" <menuitem id="resource_holiday_root_menu" name="Resources Holiday"
parent="golem_resource.golem_resource_menu" parent="golem_resource.resource_configuration_menu"
sequence="50"/> sequence="50"/>
<menuitem id="resource_holiday_menu" name="Holiday" <menuitem id="resource_holiday_menu" name="Holiday"
parent="resource_holiday_root_menu" parent="resource_holiday_root_menu"

View File

@ -28,10 +28,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<page name="availability" position="after"> <page name="availability" position="after">
<page name="holiday_period_selection" string="Holiday Period Selection"> <page name="holiday_period_selection" string="Holiday Period Selection">
<group> <group>
<field name="holiday_period_selection" context="{'default_resource_id': active_id}"> <field name="holiday_period_ids" widget="many2many_tags" options="{'no_create': True}"/>
<tree editable="top"> <field name="holiday_selection_ids"
context="{'default_resource_id': active_id}"
attrs="{'invisible': [('holiday_period_ids', '=', [])]}">
<tree create="false" edit="true" delete="false" editable="top">
<field name="resource_id" invisible="1"/> <field name="resource_id" invisible="1"/>
<field name="holiday_period_id"/> <field name="holiday_id" readonly="1"/>
<field name="is_reservation_possible"/> <field name="is_reservation_possible"/>
</tree> </tree>
</field> </field>