From 300676c204f80c05339b622cd638d808b0a8b06e Mon Sep 17 00:00:00 2001 From: Youssef ELOUAHBY Date: Thu, 21 May 2020 23:32:10 +0000 Subject: [PATCH 1/3] small improvement on resource form to fit with resource holiday --- golem_resource/views/golem_resource_views.xml | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/golem_resource/views/golem_resource_views.xml b/golem_resource/views/golem_resource_views.xml index 48331c9..d723f68 100644 --- a/golem_resource/views/golem_resource_views.xml +++ b/golem_resource/views/golem_resource_views.xml @@ -68,24 +68,28 @@ along with this program. If not, see . - - - - - - - -

- Please save the resource before fixing the timetable availability" -

- - - -
+ + + + + + + + + +

+ Please save the resource before fixing the timetable availability" +

+ + + +
+
+
-- 2.40.1 From 517d7432576985c5969abc04c8935e9eef649055 Mon Sep 17 00:00:00 2001 From: Youssef ELOUAHBY Date: Thu, 21 May 2020 23:32:49 +0000 Subject: [PATCH 2/3] create module golem_resource_holiday --- golem_resource_holiday/__init__.py | 19 ++++ golem_resource_holiday/__manifest__.py | 38 ++++++++ golem_resource_holiday/models/__init__.py | 21 +++++ .../models/golem_resource.py | 28 ++++++ .../models/golem_resource_holiday.py | 52 +++++++++++ .../models/golem_resource_holiday_period.py | 33 +++++++ ...golem_resource_holiday_period_selection.py | 32 +++++++ .../security/ir.model.access.csv | 7 ++ .../golem_resource_holiday_period_views.xml | 79 ++++++++++++++++ .../views/golem_resource_holiday_views.xml | 89 +++++++++++++++++++ .../views/golem_resource_views.xml | 44 +++++++++ 11 files changed, 442 insertions(+) create mode 100644 golem_resource_holiday/__init__.py create mode 100644 golem_resource_holiday/__manifest__.py create mode 100644 golem_resource_holiday/models/__init__.py create mode 100644 golem_resource_holiday/models/golem_resource.py create mode 100644 golem_resource_holiday/models/golem_resource_holiday.py create mode 100644 golem_resource_holiday/models/golem_resource_holiday_period.py create mode 100644 golem_resource_holiday/models/golem_resource_holiday_period_selection.py create mode 100644 golem_resource_holiday/security/ir.model.access.csv create mode 100644 golem_resource_holiday/views/golem_resource_holiday_period_views.xml create mode 100644 golem_resource_holiday/views/golem_resource_holiday_views.xml create mode 100644 golem_resource_holiday/views/golem_resource_views.xml diff --git a/golem_resource_holiday/__init__.py b/golem_resource_holiday/__init__.py new file mode 100644 index 0000000..3c60092 --- /dev/null +++ b/golem_resource_holiday/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Youssef El Ouahby +# Copyright 2020 Fabien Bourgeois +# +# 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 . + +from . import models diff --git a/golem_resource_holiday/__manifest__.py b/golem_resource_holiday/__manifest__.py new file mode 100644 index 0000000..5076c1c --- /dev/null +++ b/golem_resource_holiday/__manifest__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Youssef El Ouahby +# Copyright 2020 Fabien Bourgeois +# +# 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 . + +{ + 'name': 'GOLEM resources holiday', + 'summary': 'GOLEM resources holiday', + 'description': ''' GOLEM resources holiday ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_resource'], + 'data': [ + #security + 'security/ir.model.access.csv', + #views + 'views/golem_resource_views.xml', + 'views/golem_resource_holiday_views.xml', + 'views/golem_resource_holiday_period_views.xml' + ] +} diff --git a/golem_resource_holiday/models/__init__.py b/golem_resource_holiday/models/__init__.py new file mode 100644 index 0000000..be75a73 --- /dev/null +++ b/golem_resource_holiday/models/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + + +from . import ( golem_resource_holiday, golem_resource_holiday_period, + golem_resource, golem_resource_holiday_period_selection) diff --git a/golem_resource_holiday/models/golem_resource.py b/golem_resource_holiday/models/golem_resource.py new file mode 100644 index 0000000..cf9f619 --- /dev/null +++ b/golem_resource_holiday/models/golem_resource.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + +""" GOLEM Resources Adaptations """ + +from odoo import models, fields + + +class GolemResource(models.Model): + """ GOLEM Resource Model """ + _inherit = 'golem.resource' + + holiday_period_selection = fields.One2many('golem.resource.holiday.period.selection', 'resource_id') diff --git a/golem_resource_holiday/models/golem_resource_holiday.py b/golem_resource_holiday/models/golem_resource_holiday.py new file mode 100644 index 0000000..48b7829 --- /dev/null +++ b/golem_resource_holiday/models/golem_resource_holiday.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + +""" GOLEM Resource holiday Management""" + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceHoliday(models.Model): + """ GOLEM Resource Holiday Management """ + _name = 'golem.resource.holiday' + _description = 'GOLEM Resource Holiday Managementl' + _inherit = 'mail.thread' + _order = 'name asc' + + name = fields.Char(compute='_compute_name', store=True) + period_id = fields.Many2one('golem.resource.holiday.period', string='Holiday period', + ondelete='cascade') + date_start = fields.Date('Holiday start') + date_end = fields.Date('Holiday end') + + @api.depends('period_id', 'date_start') + def _compute_name(self): + """ Computes holiday name """ + for holiday in self: + holiday.name = u'{}/{}/{}'.format(holiday.period_id.name, + holiday.date_start, + holiday.id) + + @api.constrains('date_start', 'date_end') + def _check_date_consistency(self): + """ Checks date consistency """ + for holiday in self: + if holiday.date_end <= holiday.date_start: + raise ValidationError(_('Date end should be after than ' + 'date start')) diff --git a/golem_resource_holiday/models/golem_resource_holiday_period.py b/golem_resource_holiday/models/golem_resource_holiday_period.py new file mode 100644 index 0000000..bc9756b --- /dev/null +++ b/golem_resource_holiday/models/golem_resource_holiday_period.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + +""" GOLEM Resource holiday period Management """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceHolidayPeriod(models.Model): + """ GOLEM Resource Holiday Period """ + _name = 'golem.resource.holiday.period' + _description = 'GOLEM Resource Holiday Period Managementl' + _inherit = 'mail.thread' + _order = 'name asc' + + name = fields.Char(required=True, index=True) + active = fields.Boolean(default=True) diff --git a/golem_resource_holiday/models/golem_resource_holiday_period_selection.py b/golem_resource_holiday/models/golem_resource_holiday_period_selection.py new file mode 100644 index 0000000..9b2d40a --- /dev/null +++ b/golem_resource_holiday/models/golem_resource_holiday_period_selection.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + +""" GOLEM Resource Holiday Period Selection Management """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceHolidayPeriodSelection(models.Model): + """ GOLEM Resource Holiday Period Selection""" + _name = 'golem.resource.holiday.period.selection' + _description = 'GOLEM Resource Holiday Period Selection Managementl' + + holiday_period_id = fields.Many2one('golem.resource.holiday.period', required=True) + resource_id = fields.Many2one('golem.resource', required=True) + is_reservation_possible = fields.Boolean() diff --git a/golem_resource_holiday/security/ir.model.access.csv b/golem_resource_holiday/security/ir.model.access.csv new file mode 100644 index 0000000..527bca9 --- /dev/null +++ b/golem_resource_holiday/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_golem_resource_holiday_user,Access GOLEM Resource Holiday User,model_golem_resource_holiday,golem_base.group_golem_user,1,0,0,0 +access_golem_resource_holiday_period_user,Access GOLEM Resource Holiday Period User,model_golem_resource_holiday_period,golem_base.group_golem_user,1,0,0,0 +access_golem_resource_holiday_period_selection_user,Access GOLEM Resource Holiday Period Selection User,model_golem_resource_holiday_period_selection,golem_base.group_golem_user,1,0,0,0 +access_golem_resource_holiday_manager,Access GOLEM Resource Holiday Manager,model_golem_resource_holiday,golem_base.group_golem_manager,1,1,1,1 +access_golem_resource_holiday_period_manager,Access GOLEM Resource Holiday Period Manager,model_golem_resource_holiday_period,golem_base.group_golem_manager,1,1,1,1 +access_golem_resource_holiday_period_selection_manager,Access GOLEM Resource Holiday Period Selection Manager,model_golem_resource_holiday_period_selection,golem_base.group_golem_manager,1,1,1,1 diff --git a/golem_resource_holiday/views/golem_resource_holiday_period_views.xml b/golem_resource_holiday/views/golem_resource_holiday_period_views.xml new file mode 100644 index 0000000..237b956 --- /dev/null +++ b/golem_resource_holiday/views/golem_resource_holiday_period_views.xml @@ -0,0 +1,79 @@ + + + + + + + + GOLEM Resource Holiday Period Tree + golem.resource.holiday.period + + + + + + + + + + GOLEM Resource Holiday Period Form + golem.resource.holiday.period + +
+ + + + + + + + + + +
+ + +
+
+
+
+ + + + GOLEM Resource Holiday Period search + golem.resource.holiday.period + + + + + + + + + + + + + +
+
diff --git a/golem_resource_holiday/views/golem_resource_holiday_views.xml b/golem_resource_holiday/views/golem_resource_holiday_views.xml new file mode 100644 index 0000000..7403e71 --- /dev/null +++ b/golem_resource_holiday/views/golem_resource_holiday_views.xml @@ -0,0 +1,89 @@ + + + + + + + + GOLEM Resource Holiday Tree + golem.resource.holiday + + + + + + + + + + + + + GOLEM Resource Holiday Form + golem.resource.holiday + +
+ + + + + + + + + + + +
+ + +
+
+
+
+ + + + GOLEM Resource Holiday search + golem.resource.holiday + + + + + + + + + + + + + + + + +
+
diff --git a/golem_resource_holiday/views/golem_resource_views.xml b/golem_resource_holiday/views/golem_resource_views.xml new file mode 100644 index 0000000..a426014 --- /dev/null +++ b/golem_resource_holiday/views/golem_resource_views.xml @@ -0,0 +1,44 @@ + + + + + + + GOLEM Resource Form inherit GOLEM Resource Holiday + golem.resource + + + + + + + + + + + + + + + + + + + -- 2.40.1 From 0eddaab896da9adbde3ba03ad3e663ac0cafcd0c Mon Sep 17 00:00:00 2001 From: Youssef ELOUAHBY Date: Fri, 22 May 2020 19:53:24 +0000 Subject: [PATCH 3/3] huge improvement --- golem_resource_holiday/models/__init__.py | 3 +- .../models/golem_resource.py | 33 ++++++++++++++- .../models/golem_resource_holiday.py | 6 +-- ...py => golem_resource_holiday_selection.py} | 15 +++---- .../models/golem_resource_reservation.py | 41 +++++++++++++++++++ .../views/golem_resource_holiday_views.xml | 4 +- .../views/golem_resource_views.xml | 9 ++-- 7 files changed, 93 insertions(+), 18 deletions(-) rename golem_resource_holiday/models/{golem_resource_holiday_period_selection.py => golem_resource_holiday_selection.py} (66%) create mode 100644 golem_resource_holiday/models/golem_resource_reservation.py diff --git a/golem_resource_holiday/models/__init__.py b/golem_resource_holiday/models/__init__.py index be75a73..fc1cacc 100644 --- a/golem_resource_holiday/models/__init__.py +++ b/golem_resource_holiday/models/__init__.py @@ -18,4 +18,5 @@ 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) diff --git a/golem_resource_holiday/models/golem_resource.py b/golem_resource_holiday/models/golem_resource.py index cf9f619..95a51ae 100644 --- a/golem_resource_holiday/models/golem_resource.py +++ b/golem_resource_holiday/models/golem_resource.py @@ -18,11 +18,40 @@ """ GOLEM Resources Adaptations """ -from odoo import models, fields +from odoo import models, fields, api, _ class GolemResource(models.Model): """ GOLEM Resource Model """ _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, + }) diff --git a/golem_resource_holiday/models/golem_resource_holiday.py b/golem_resource_holiday/models/golem_resource_holiday.py index 48b7829..0ddae15 100644 --- a/golem_resource_holiday/models/golem_resource_holiday.py +++ b/golem_resource_holiday/models/golem_resource_holiday.py @@ -35,13 +35,13 @@ class GolemResourceHoliday(models.Model): date_start = fields.Date('Holiday start') date_end = fields.Date('Holiday end') - @api.depends('period_id', 'date_start') + @api.depends('period_id', 'date_start', 'date_end') def _compute_name(self): """ Computes holiday name """ for holiday in self: - holiday.name = u'{}/{}/{}'.format(holiday.period_id.name, + holiday.name = u'{}/{}:{}'.format(holiday.period_id.name, holiday.date_start, - holiday.id) + holiday.date_end) @api.constrains('date_start', 'date_end') def _check_date_consistency(self): diff --git a/golem_resource_holiday/models/golem_resource_holiday_period_selection.py b/golem_resource_holiday/models/golem_resource_holiday_selection.py similarity index 66% rename from golem_resource_holiday/models/golem_resource_holiday_period_selection.py rename to golem_resource_holiday/models/golem_resource_holiday_selection.py index 9b2d40a..b303bd8 100644 --- a/golem_resource_holiday/models/golem_resource_holiday_period_selection.py +++ b/golem_resource_holiday/models/golem_resource_holiday_selection.py @@ -16,17 +16,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -""" GOLEM Resource Holiday Period Selection Management """ +""" GOLEM Resource Holiday Selection Management """ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError -class GolemResourceHolidayPeriodSelection(models.Model): - """ GOLEM Resource Holiday Period Selection""" - _name = 'golem.resource.holiday.period.selection' - _description = 'GOLEM Resource Holiday Period Selection Managementl' +class GolemResourceHolidaySelection(models.Model): + """ GOLEM Resource Holiday Selection""" + _name = 'golem.resource.holiday.selection' + _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) - 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) diff --git a/golem_resource_holiday/models/golem_resource_reservation.py b/golem_resource_holiday/models/golem_resource_reservation.py new file mode 100644 index 0000000..ea041e7 --- /dev/null +++ b/golem_resource_holiday/models/golem_resource_reservation.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Fabien Bourgeois +# Copyright 2020 Youssef El Ouahby +# +# 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 . + +""" 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 + )) diff --git a/golem_resource_holiday/views/golem_resource_holiday_views.xml b/golem_resource_holiday/views/golem_resource_holiday_views.xml index 7403e71..adc0c09 100644 --- a/golem_resource_holiday/views/golem_resource_holiday_views.xml +++ b/golem_resource_holiday/views/golem_resource_holiday_views.xml @@ -42,7 +42,7 @@ along with this program. If not, see . - + @@ -78,7 +78,7 @@ along with this program. If not, see . . - - + + + - + -- 2.40.1