From d81434375822de92e360cc4199749b5c1751066f Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 7 Feb 2018 01:44:48 +0100 Subject: [PATCH 1/9] first version of golem ressource, models : resources and reservation --- golem_ressources/__init__.py | 18 ++++ golem_ressources/__manifest__.py | 33 ++++++ golem_ressources/models/__init__.py | 18 ++++ golem_ressources/models/golem_resources.py | 77 +++++++++++++ golem_ressources/security/ir.model.access.csv | 3 + .../views/golem_reservation_views.xml | 80 ++++++++++++++ .../views/golem_resources_views.xml | 102 ++++++++++++++++++ 7 files changed, 331 insertions(+) create mode 100644 golem_ressources/__init__.py create mode 100644 golem_ressources/__manifest__.py create mode 100644 golem_ressources/models/__init__.py create mode 100644 golem_ressources/models/golem_resources.py create mode 100644 golem_ressources/security/ir.model.access.csv create mode 100644 golem_ressources/views/golem_reservation_views.xml create mode 100644 golem_ressources/views/golem_resources_views.xml diff --git a/golem_ressources/__init__.py b/golem_ressources/__init__.py new file mode 100644 index 00000000..2fca3d29 --- /dev/null +++ b/golem_ressources/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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_ressources/__manifest__.py b/golem_ressources/__manifest__.py new file mode 100644 index 00000000..0ba95763 --- /dev/null +++ b/golem_ressources/__manifest__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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 non-profit resources', + 'summary': 'Extends Odoo resources for MJC', + 'version': '10.0.1.0.0', + 'category': 'GOLEM', + 'author': 'Youssef El ouahby', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_base', 'golem_activity', 'golem_season', + 'odoo_partner_merge'], + 'data': ['views/golem_resources_views.xml', + 'views/golem_reservation_views.xml', + 'security/ir.model.access.csv', + ] +} diff --git a/golem_ressources/models/__init__.py b/golem_ressources/models/__init__.py new file mode 100644 index 00000000..43371e7e --- /dev/null +++ b/golem_ressources/models/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 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 golem_resources diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py new file mode 100644 index 00000000..d0a37b41 --- /dev/null +++ b/golem_ressources/models/golem_resources.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +# Copyright 2017 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 odoo import models, fields, api + +class GolemResources(models.Model): + """ GOLEM Resources """ + _name = 'golem.resources' + _description = 'GOLEM Resources' + + name = fields.Char() + resource_type = fields.Many2one("golem.resourcetype", string="Resource type") + resource_responsible = fields.Many2one("res.partner", string="Resource Responsible") + article_link = fields.Many2one("product.template", string="Article Link") + #Configuration de disponibilité + start_of_availability_date = fields.Date(string="Start of availibility date ") + end_of_availability_date = fields.Date(string="End of availibility date ") + weekdays_of_availibility = fields.Many2many('golem.weekday', string="Weekdays of availibility") + + +class GolemReservation(models.Model): + """ GOLEM Reservation """ + _name = 'golem.reservation' + _description = 'GOLEM Reservation' + + start_date = fields.Datetime(string='Start date') + end_date = fields.Datetime(string='End date') + linked_resource = fields.Many2one('golem.resources', string="Linked resource") + user = fields.Many2one('res.users', required=True) + on_behalf_of = fields.Many2one('res.partner', required=True) + status = fields.Selection([ + ('draft', "Draft"), + ('confirmed', "Confirmed"), + ('canceled', "Canceled"), + ], default='draft') + + @api.multi + def status_draft(self): + self.status = 'draft' + + @api.multi + def status_confirm(self): + self.status = 'confirmed' + + @api.multi + def status_canceled(self): + self.status = 'canceled' + +class GolemResourceType(models.Model): + """ GOLEM Resource Type """ + _name = 'golem.resourcetype' + _description = 'GOLEM Resource Type' + + name = fields.Char(string='Resource Type') + +class GolemWeekDays(models.Model): + """ GOLEM Week Days """ + _name = 'golem.weekday' + _description = 'GOLEM Week Day' + + name = fields.Char(string='Week Day') diff --git a/golem_ressources/security/ir.model.access.csv b/golem_ressources/security/ir.model.access.csv new file mode 100644 index 00000000..a269e71f --- /dev/null +++ b/golem_ressources/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_golem_resources_user,Access GOLEM Resources User,model_golem_resources,golem_base.group_golem_user,1,0,0,0 +access_golem_resources_manager,Access GOLEM Resources Manager,model_golem_resources,golem_base.group_golem_manager,1,1,1,1 diff --git a/golem_ressources/views/golem_reservation_views.xml b/golem_ressources/views/golem_reservation_views.xml new file mode 100644 index 00000000..12883e5a --- /dev/null +++ b/golem_ressources/views/golem_reservation_views.xml @@ -0,0 +1,80 @@ + + + + + + reservation.calendar + golem.reservation + + + + + + + + + + reservation.tree + golem.reservation + + + + + + + + + + + + + reservation.form + golem.reservation + +
+
+
+ + + + + + + + + +
+
+
+ + Reservation + golem.reservation + tree,form,calendar + + +
+
diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml new file mode 100644 index 00000000..6008b34b --- /dev/null +++ b/golem_ressources/views/golem_resources_views.xml @@ -0,0 +1,102 @@ + + + + + + Sunday + + + Monday + + + Tuesday + + + wednesday + + + Thursday + + + Friday + + + Saturday + + + resource.search + golem.resources + + + + + + + + + + + resource.tree + golem.resources + + + + + + + + + + + + + + resource.form + golem.resources + +
+ + + + + + + + + + + + + + + + +
+
+
+ + + Resources + golem.resources + tree,form,search + + + +
+
From 7eda2d4a98036a73a00036aab046c6355c8df723 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 7 Feb 2018 10:16:12 +0100 Subject: [PATCH 2/9] Comments added to models --- golem_ressources/models/golem_resources.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index d0a37b41..907a56dc 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -18,7 +18,7 @@ from odoo import models, fields, api - +#modèle de base : ressources class GolemResources(models.Model): """ GOLEM Resources """ _name = 'golem.resources' @@ -28,12 +28,13 @@ class GolemResources(models.Model): resource_type = fields.Many2one("golem.resourcetype", string="Resource type") resource_responsible = fields.Many2one("res.partner", string="Resource Responsible") article_link = fields.Many2one("product.template", string="Article Link") - #Configuration de disponibilité + + #Configuration de disponibilité(période, jours et horaire) start_of_availability_date = fields.Date(string="Start of availibility date ") end_of_availability_date = fields.Date(string="End of availibility date ") weekdays_of_availibility = fields.Many2many('golem.weekday', string="Weekdays of availibility") - +#modèle gestion des reservation class GolemReservation(models.Model): """ GOLEM Reservation """ _name = 'golem.reservation' @@ -62,6 +63,7 @@ class GolemReservation(models.Model): def status_canceled(self): self.status = 'canceled' +#modèle de base pour identifier le type de la ressource class GolemResourceType(models.Model): """ GOLEM Resource Type """ _name = 'golem.resourcetype' @@ -69,8 +71,9 @@ class GolemResourceType(models.Model): name = fields.Char(string='Resource Type') -class GolemWeekDays(models.Model): - """ GOLEM Week Days """ +#modèle de base pour stocker les jours de la semaine +class GolemWeekDay(models.Model): + """ GOLEM Week Day """ _name = 'golem.weekday' _description = 'GOLEM Week Day' From 25acf52d5ec0dd5ebfe59d8f9f1ec0945e672297 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 7 Feb 2018 18:13:02 +0100 Subject: [PATCH 3/9] =?UTF-8?q?Ajout=20d'un=20mod=C3=A8le=20hour=20pour=20?= =?UTF-8?q?la=20gestion=20des=20horaires=20de=20disponibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_ressources/models/golem_resources.py | 19 +++++++++++++++++++ .../views/golem_resources_views.xml | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index 907a56dc..5f929c56 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -25,6 +25,7 @@ class GolemResources(models.Model): _description = 'GOLEM Resources' name = fields.Char() + active = fields.Boolean(default=False) resource_type = fields.Many2one("golem.resourcetype", string="Resource type") resource_responsible = fields.Many2one("res.partner", string="Resource Responsible") article_link = fields.Many2one("product.template", string="Article Link") @@ -33,6 +34,13 @@ class GolemResources(models.Model): start_of_availability_date = fields.Date(string="Start of availibility date ") end_of_availability_date = fields.Date(string="End of availibility date ") weekdays_of_availibility = fields.Many2many('golem.weekday', string="Weekdays of availibility") + #horaire = fields.Many2many("golem.hour", string="horaire ") + + @api.multi + def active_change(self): + self.active = not self.active + + #modèle gestion des reservation class GolemReservation(models.Model): @@ -78,3 +86,14 @@ class GolemWeekDay(models.Model): _description = 'GOLEM Week Day' name = fields.Char(string='Week Day') + +#modèle de gestion horaire +class GolemHour(models.Model): + """ Golem Hour """ + _name = "golem.hour" + _description = "Golem Hour" + + resource_id = fields.Many2one("golem.resources", required=True) + name = fields.Many2one("golem.weekday", required=True) + start_time = fields.Float(required=True) + end_time = fields.Float(required=True) diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml index 6008b34b..bbadd715 100644 --- a/golem_ressources/views/golem_resources_views.xml +++ b/golem_ressources/views/golem_resources_views.xml @@ -70,6 +70,12 @@ along with this program. If not, see . golem.resources
+
+ +
@@ -83,6 +89,7 @@ along with this program. If not, see . + From 4cec86337287ca62c4153a323b0cb5e14a6b4aea Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 8 Feb 2018 00:58:23 +0100 Subject: [PATCH 4/9] Adding comments to views and fixing the availibility configuration --- golem_ressources/models/golem_resources.py | 10 ++--- .../views/golem_reservation_views.xml | 2 +- .../views/golem_resources_views.xml | 38 ++++++++++++++----- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index 5f929c56..e2570493 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -34,7 +34,7 @@ class GolemResources(models.Model): start_of_availability_date = fields.Date(string="Start of availibility date ") end_of_availability_date = fields.Date(string="End of availibility date ") weekdays_of_availibility = fields.Many2many('golem.weekday', string="Weekdays of availibility") - #horaire = fields.Many2many("golem.hour", string="horaire ") + timetable = fields.One2many("golem.timetable", "resource_id", string="Availibility timetable") @api.multi def active_change(self): @@ -88,10 +88,10 @@ class GolemWeekDay(models.Model): name = fields.Char(string='Week Day') #modèle de gestion horaire -class GolemHour(models.Model): - """ Golem Hour """ - _name = "golem.hour" - _description = "Golem Hour" +class GolemTimetable(models.Model): + """ Golem Timetable """ + _name = "golem.timetable" + _description = "Golem Timetable" resource_id = fields.Many2one("golem.resources", required=True) name = fields.Many2one("golem.weekday", required=True) diff --git a/golem_ressources/views/golem_reservation_views.xml b/golem_ressources/views/golem_reservation_views.xml index 12883e5a..867579f9 100644 --- a/golem_ressources/views/golem_reservation_views.xml +++ b/golem_ressources/views/golem_reservation_views.xml @@ -1,6 +1,6 @@ + Sunday @@ -38,6 +39,9 @@ along with this program. If not, see . Saturday + + + resource.search golem.resources @@ -50,6 +54,8 @@ along with this program. If not, see . + + resource.tree golem.resources @@ -65,6 +71,8 @@ along with this program. If not, see . + + resource.form golem.resources @@ -79,17 +87,24 @@ along with this program. If not, see . - - - - + + + + - - - - - + + + + + + + + + + + + @@ -97,11 +112,14 @@ along with this program. If not, see . + Resources golem.resources tree,form,search + + From 3a42ea0a5451612f7ea58c68c5efdc4acaed7d48 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 8 Feb 2018 12:02:46 +0100 Subject: [PATCH 5/9] finalisation du smart button et contraint d'heure --- golem_ressources/__manifest__.py | 4 ++-- golem_ressources/models/golem_resources.py | 6 ++++++ golem_ressources/views/golem_resources_views.xml | 12 ++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/golem_ressources/__manifest__.py b/golem_ressources/__manifest__.py index 0ba95763..f42d1e1c 100644 --- a/golem_ressources/__manifest__.py +++ b/golem_ressources/__manifest__.py @@ -24,8 +24,8 @@ 'license': 'AGPL-3', 'application': True, 'installable': True, - 'depends': ['golem_base', 'golem_activity', 'golem_season', - 'odoo_partner_merge'], + 'depends': ['product', + ], 'data': ['views/golem_resources_views.xml', 'views/golem_reservation_views.xml', 'security/ir.model.access.csv', diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index e2570493..e653e038 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -97,3 +97,9 @@ class GolemTimetable(models.Model): name = fields.Many2one("golem.weekday", required=True) start_time = fields.Float(required=True) end_time = fields.Float(required=True) + + @api.constraint('start_time','end_time') + def _check_time_consistency(self): + for r in self: + if r.end_time < r.start_time: + raise ValidationError("End time should be higher than start time") diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml index a3b6614a..d2074763 100644 --- a/golem_ressources/views/golem_resources_views.xml +++ b/golem_ressources/views/golem_resources_views.xml @@ -78,13 +78,13 @@ along with this program. If not, see . golem.resources -
- -
+
+ +
From 15a23e460f2d48d3a404bc58529f0e01f9427afb Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 8 Feb 2018 12:22:52 +0100 Subject: [PATCH 6/9] =?UTF-8?q?Am=C3=A9liorations=20syntaxiques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_ressources/models/golem_resources.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index e653e038..c5084e5e 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -17,7 +17,7 @@ -from odoo import models, fields, api +from odoo import models, fields, api, exceptions #modèle de base : ressources class GolemResources(models.Model): """ GOLEM Resources """ @@ -98,8 +98,8 @@ class GolemTimetable(models.Model): start_time = fields.Float(required=True) end_time = fields.Float(required=True) - @api.constraint('start_time','end_time') + @api.constrains('start_time', 'end_time') def _check_time_consistency(self): for r in self: if r.end_time < r.start_time: - raise ValidationError("End time should be higher than start time") + raise exceptions.ValidationError('End time should be higher than start time') From 7dc2213593c8c5dc1a76791641a1c7821b31ee6b Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 8 Feb 2018 23:21:33 +0100 Subject: [PATCH 7/9] =?UTF-8?q?R=C3=A9alisation=20des=20am=C3=A9liorations?= =?UTF-8?q?=20propos=C3=A9s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_ressources/models/golem_resources.py | 40 +++++++++++-------- .../views/golem_resources_views.xml | 34 +++++++++++++--- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index c5084e5e..4a2b2e65 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -17,23 +17,22 @@ -from odoo import models, fields, api, exceptions +from odoo import models, fields, api, _, exceptions #modèle de base : ressources class GolemResources(models.Model): """ GOLEM Resources """ _name = 'golem.resources' _description = 'GOLEM Resources' - name = fields.Char() - active = fields.Boolean(default=False) - resource_type = fields.Many2one("golem.resourcetype", string="Resource type") - resource_responsible = fields.Many2one("res.partner", string="Resource Responsible") - article_link = fields.Many2one("product.template", string="Article Link") + name = fields.Char(required=True) + active = fields.Boolean(default=True) + resource_type = fields.Many2one("golem.resourcetype") + resource_responsible = fields.Many2one("res.partner") + article_link = fields.Many2one("product.template") #Configuration de disponibilité(période, jours et horaire) - start_of_availability_date = fields.Date(string="Start of availibility date ") - end_of_availability_date = fields.Date(string="End of availibility date ") - weekdays_of_availibility = fields.Many2many('golem.weekday', string="Weekdays of availibility") + start_of_availability_date = fields.Date(required=True) + end_of_availability_date = fields.Date(required=True) timetable = fields.One2many("golem.timetable", "resource_id", string="Availibility timetable") @api.multi @@ -48,9 +47,9 @@ class GolemReservation(models.Model): _name = 'golem.reservation' _description = 'GOLEM Reservation' - start_date = fields.Datetime(string='Start date') - end_date = fields.Datetime(string='End date') - linked_resource = fields.Many2one('golem.resources', string="Linked resource") + start_date = fields.Datetime() + end_date = fields.Datetime() + linked_resource = fields.Many2one('golem.resources', required=True) user = fields.Many2one('res.users', required=True) on_behalf_of = fields.Many2one('res.partner', required=True) status = fields.Selection([ @@ -65,19 +64,27 @@ class GolemReservation(models.Model): @api.multi def status_confirm(self): - self.status = 'confirmed' + #self.status = 'confirmed' + exceptions.ValidationError('not allowed') @api.multi def status_canceled(self): self.status = 'canceled' + @api.constrains('status') + def _onConfirmReservation(self): + if(self.status == 'confrimed'): + exceptions.UserError('not allowed') + #exceptions.ValidationError('not allowed') + + #modèle de base pour identifier le type de la ressource class GolemResourceType(models.Model): """ GOLEM Resource Type """ _name = 'golem.resourcetype' _description = 'GOLEM Resource Type' - name = fields.Char(string='Resource Type') + name = fields.Char(string='Resource Type',required=True) #modèle de base pour stocker les jours de la semaine class GolemWeekDay(models.Model): @@ -100,6 +107,5 @@ class GolemTimetable(models.Model): @api.constrains('start_time', 'end_time') def _check_time_consistency(self): - for r in self: - if r.end_time < r.start_time: - raise exceptions.ValidationError('End time should be higher than start time') + if self.end_time < self.start_time: + raise exceptions.ValidationError(_('End time should be higher than start time')) diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml index d2074763..3e4f74ab 100644 --- a/golem_ressources/views/golem_resources_views.xml +++ b/golem_ressources/views/golem_resources_views.xml @@ -67,7 +67,6 @@ along with this program. If not, see . - @@ -92,14 +91,17 @@ along with this program. If not, see . + - - - - + +
From 3766f49805d4c0f2854f2f3319c11624948ef043 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Sat, 10 Feb 2018 00:05:36 +0100 Subject: [PATCH 8/9] =?UTF-8?q?1er=20version=20du=20mod=C3=A8le=20reservat?= =?UTF-8?q?ion,=20avec=20contraintes=20de=20disponibilit=C3=A9=20operation?= =?UTF-8?q?nelles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_ressources/models/golem_resources.py | 20 ++++++++++++++----- .../views/golem_reservation_views.xml | 7 ++++++- .../views/golem_resources_views.xml | 12 +++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index 4a2b2e65..a57d17d2 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -18,6 +18,9 @@ from odoo import models, fields, api, _, exceptions +import logging + +_logger = logging.getLogger(__name__) #modèle de base : ressources class GolemResources(models.Model): """ GOLEM Resources """ @@ -34,6 +37,7 @@ class GolemResources(models.Model): start_of_availability_date = fields.Date(required=True) end_of_availability_date = fields.Date(required=True) timetable = fields.One2many("golem.timetable", "resource_id", string="Availibility timetable") + reservation = fields.One2many("golem.reservation", "linked_resource") @api.multi def active_change(self): @@ -52,6 +56,7 @@ class GolemReservation(models.Model): linked_resource = fields.Many2one('golem.resources', required=True) user = fields.Many2one('res.users', required=True) on_behalf_of = fields.Many2one('res.partner', required=True) + #statut=fields.Char() status = fields.Selection([ ('draft', "Draft"), ('confirmed', "Confirmed"), @@ -64,8 +69,8 @@ class GolemReservation(models.Model): @api.multi def status_confirm(self): - #self.status = 'confirmed' - exceptions.ValidationError('not allowed') + self.status = 'confirmed' + @api.multi def status_canceled(self): @@ -73,9 +78,14 @@ class GolemReservation(models.Model): @api.constrains('status') def _onConfirmReservation(self): - if(self.status == 'confrimed'): - exceptions.UserError('not allowed') - #exceptions.ValidationError('not allowed') + if self.status == 'confirmed': + if(self.start_date < self.linked_resource.start_of_availability_date or self.end_date > self.linked_resource.end_of_availability_date ): + raise exceptions.UserError('Not allowed, the resource is not available in this period, please choose another périod before confirming %s' % self.linked_resource.start_of_availability_date) + else : + for reservation in self.linked_resource.reservation : + if(self.id != reservation.id and reservation.status == 'confirmed' and not (self.end_date < reservation.start_date or self.start_date > reservation.end_date)): + raise exceptions.UserError("Not allowed, the resource is taken during this period, please choose another période before confirming ") + #modèle de base pour identifier le type de la ressource diff --git a/golem_ressources/views/golem_reservation_views.xml b/golem_ressources/views/golem_reservation_views.xml index 867579f9..bd38ff02 100644 --- a/golem_ressources/views/golem_reservation_views.xml +++ b/golem_ressources/views/golem_reservation_views.xml @@ -17,6 +17,7 @@ along with this program. If not, see . --> + reservation.calendar golem.reservation @@ -29,6 +30,8 @@ along with this program. If not, see . + + reservation.tree golem.reservation @@ -39,10 +42,12 @@ along with this program. If not, see . - + + + reservation.form golem.reservation diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml index 3e4f74ab..790009c9 100644 --- a/golem_ressources/views/golem_resources_views.xml +++ b/golem_ressources/views/golem_resources_views.xml @@ -108,6 +108,18 @@ along with this program. If not, see . + + + + + + + + + + + + From 6e4cae64f4939ccac68aa3db1387290a7d942a86 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Mon, 12 Feb 2018 16:05:52 +0100 Subject: [PATCH 9/9] =?UTF-8?q?prendre=20en=20compte=20les=20remarques=20r?= =?UTF-8?q?elatives=20aux=20r=C3=A9servation=20sur=20une=20p=C3=A9riode=20?= =?UTF-8?q?d'indisponibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_ressources/models/golem_resources.py | 25 +++++++++++- .../views/golem_resources_views.xml | 40 +++++++++---------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/golem_ressources/models/golem_resources.py b/golem_ressources/models/golem_resources.py index a57d17d2..7fc6b207 100644 --- a/golem_ressources/models/golem_resources.py +++ b/golem_ressources/models/golem_resources.py @@ -54,8 +54,8 @@ class GolemReservation(models.Model): start_date = fields.Datetime() end_date = fields.Datetime() linked_resource = fields.Many2one('golem.resources', required=True) - user = fields.Many2one('res.users', required=True) - on_behalf_of = fields.Many2one('res.partner', required=True) + user = fields.Many2one('res.users', required=True, default=lambda self: self.env.user) + on_behalf_of = fields.Many2one('res.partner', required=True, default=lambda self: self.env['res.partner']) #statut=fields.Char() status = fields.Selection([ ('draft', "Draft"), @@ -79,9 +79,29 @@ class GolemReservation(models.Model): @api.constrains('status') def _onConfirmReservation(self): if self.status == 'confirmed': + #verifyin is the reservation is taking place out of the resource availibility period if(self.start_date < self.linked_resource.start_of_availability_date or self.end_date > self.linked_resource.end_of_availability_date ): raise exceptions.UserError('Not allowed, the resource is not available in this period, please choose another périod before confirming %s' % self.linked_resource.start_of_availability_date) else : + #verifying if the reservation is taking place out the availibility timetable + #defining a boolean flag, which will determine if the day of the reservation is available + r_allowed = False + for day in self.linked_resource.timetable : + #if the day is available, look for the time if it's inside the resource timetable availibility + if day.name.id_day == fields.Datetime.from_string(self.start_date).weekday(): + start_hour = fields.Datetime.from_string(self.start_date).hour + start_min = float(fields.Datetime.from_string(self.start_date).minute) #+(int(fields.Datetime.from_string(self.start_date).min))/100 + start_time_r = start_hour + start_min/100 + start_hour = fields.Datetime.from_string(self.end_date).hour + start_min = float(fields.Datetime.from_string(self.end_date).minute) #+(int(fields.Datetime.from_string(self.start_date).min))/100 + end_time_r = start_hour + start_min/100 + #if the time is suitable, the flag state is changed + if(start_time_r > day.start_time and end_time_r < day.end_time): + r_allowed = True + #if the flag is changed no erreur is raised. + if(not r_allowed): + raise exceptions.UserError("Not allowed, the resource is not available during this timetable, please choose another time before confirming ") + #verifying if the resource is already taken during this period for reservation in self.linked_resource.reservation : if(self.id != reservation.id and reservation.status == 'confirmed' and not (self.end_date < reservation.start_date or self.start_date > reservation.end_date)): raise exceptions.UserError("Not allowed, the resource is taken during this period, please choose another période before confirming ") @@ -103,6 +123,7 @@ class GolemWeekDay(models.Model): _description = 'GOLEM Week Day' name = fields.Char(string='Week Day') + id_day = fields.Integer() #modèle de gestion horaire class GolemTimetable(models.Model): diff --git a/golem_ressources/views/golem_resources_views.xml b/golem_ressources/views/golem_resources_views.xml index 790009c9..48057d17 100644 --- a/golem_ressources/views/golem_resources_views.xml +++ b/golem_ressources/views/golem_resources_views.xml @@ -18,26 +18,34 @@ along with this program. If not, see . - + + Sunday + 6 + + + Monday + 0 + + + Tuesday + 1 - Monday + wednesday + 2 - Tuesday + Thursday + 3 - wednesday + Friday + 4 - Thursday - - - Friday - - Saturday + 5 @@ -108,18 +116,6 @@ along with this program. If not, see .
- - - - - - - - - - - -