From 7af41f07c7ef21be618573eb37022b0f81f45b1d Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 21 Mar 2018 01:36:29 +0100 Subject: [PATCH] initialisation resource option --- golem_resource_option/__init__.py | 19 +++ golem_resource_option/__manifest__.py | 31 ++++ golem_resource_option/models/__init__.py | 22 +++ .../models/golem_resource.py | 95 ++++++++++++ .../models/golem_resource_option.py | 32 ++++ .../models/golem_resource_timetable.py | 77 +++++++++ .../models/golem_resource_type.py | 32 ++++ .../golem_resource_reservation_views.xml | 146 ++++++++++++++++++ .../views/golem_resource_timetable_views.xml | 38 +++++ .../views/golem_resource_type_views.xml | 54 +++++++ .../views/golem_resource_views.xml | 140 +++++++++++++++++ 11 files changed, 686 insertions(+) create mode 100644 golem_resource_option/__init__.py create mode 100644 golem_resource_option/__manifest__.py create mode 100644 golem_resource_option/models/__init__.py create mode 100644 golem_resource_option/models/golem_resource.py create mode 100644 golem_resource_option/models/golem_resource_option.py create mode 100644 golem_resource_option/models/golem_resource_timetable.py create mode 100644 golem_resource_option/models/golem_resource_type.py create mode 100644 golem_resource_option/views/golem_resource_reservation_views.xml create mode 100644 golem_resource_option/views/golem_resource_timetable_views.xml create mode 100644 golem_resource_option/views/golem_resource_type_views.xml create mode 100644 golem_resource_option/views/golem_resource_views.xml diff --git a/golem_resource_option/__init__.py b/golem_resource_option/__init__.py new file mode 100644 index 0000000..1fced20 --- /dev/null +++ b/golem_resource_option/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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_option/__manifest__.py b/golem_resource_option/__manifest__.py new file mode 100644 index 0000000..e40d824 --- /dev/null +++ b/golem_resource_option/__manifest__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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 option', + 'summary': 'GOLEM resources option', + 'description': ''' GOLEM resources option ''', + 'version': '10.0.0.0.0', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_resource'], + 'data': [] +} diff --git a/golem_resource_option/models/__init__.py b/golem_resource_option/models/__init__.py new file mode 100644 index 0000000..d3aab06 --- /dev/null +++ b/golem_resource_option/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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_resource_type, \ + golem_resource_timetable, \ + golem_resource, \ + golem_resource_reservation diff --git a/golem_resource_option/models/golem_resource.py b/golem_resource_option/models/golem_resource.py new file mode 100644 index 0000000..fba69c5 --- /dev/null +++ b/golem_resource_option/models/golem_resource.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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 . + +""" GOLEM Resources management """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResource(models.Model): + """ GOLEM Resource Model """ + _name = 'golem.resource' + _description = 'GOLEM Resource Model' + _inherit = 'mail.thread' + _order = 'name asc' + + name = fields.Char(required=True, index=True) + active = fields.Boolean(default=True) + validation_required = fields.Boolean(default=False, + string='Is validation required ?') + type_id = fields.Many2one('golem.resource.type', + index=True, string='Resource Type') + supervisor_id = fields.Many2one('res.partner', index=True, string='Supervisor') + product_tmpl_id = fields.Many2one('product.template', index=True, + string='Linked product', + help='A generic product can be linked, in ' + 'order to sell reservations (work in ' + 'progress)') + + avaibility_start = fields.Date(required=True, string='Availibility start date') + avaibility_stop = fields.Date(required=True, string='Availibility stop date') + availibility_24_7 = fields.Boolean(string='24/7 availibility') + timetable_ids = fields.One2many('golem.resource.timetable', 'resource_id', + string='Availibility timetable') + reservation_ids = fields.One2many('golem.resource.reservation', 'resource_id', + string='Reservations') + reservation_count = fields.Integer(compute='_compute_reservation_count') + + @api.depends('reservation_ids') + def _compute_reservation_count(self): + for resource in self: + resource.reservation_count = len(resource.reservation_ids) + + @api.multi + def reservation_calendar(self): + """ current resource reservation calendar """ + self.ensure_one() + return { + 'name': _('Resource Reservation'), + 'view_mode': 'calendar,tree,form', + 'res_model': 'golem.resource.reservation', + 'context': {'search_default_resource_id': self[0].id}, + 'type': 'ir.actions.act_window' + } + + @api.multi + def reserveration_list(self): + """ current resource reservation list """ + self.ensure_one() + return { + 'name': _('Resource Reservation list'), + 'view_mode': 'tree,form,calendar', + 'res_model': 'golem.resource.reservation', + 'context': {'search_default_resource_id': self[0].id}, + 'type': 'ir.actions.act_window' + } + + @api.multi + def active_toggle(self): + """ Toggles active boolean """ + for resource in self: + resource.active = not resource.active + + @api.constrains('avaibility_start', 'avaibility_stop') + def _check_date_consistency(self): + """ Checks date consistency """ + for resource in self: + if resource.avaibility_stop <= resource.avaibility_start: + raise ValidationError(_('End availibility should be after than ' + 'start availibility')) diff --git a/golem_resource_option/models/golem_resource_option.py b/golem_resource_option/models/golem_resource_option.py new file mode 100644 index 0000000..b9905b9 --- /dev/null +++ b/golem_resource_option/models/golem_resource_option.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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 . + +""" GOLEM Resource Option """ + + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class GolemResourceOption(models.Model): + """ GOLEM Resource Option Model """ + _name = 'golem.resource.option' + _description = 'GOLEM Reservation Model' + + name = fields.Char() + resource_id = fields.Many2one('golem.resource') diff --git a/golem_resource_option/models/golem_resource_timetable.py b/golem_resource_option/models/golem_resource_timetable.py new file mode 100644 index 0000000..4b6acf4 --- /dev/null +++ b/golem_resource_option/models/golem_resource_timetable.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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 . + +""" GOLEM Resource Timetable """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class GolemTimetable(models.Model): + """ Golem Timetable """ + _name = "golem.resource.timetable" + _description = "Golem Timetable" + _rec_name = 'weekday' + _order = 'weekday asc,time_start asc' + + resource_id = fields.Many2one('golem.resource', required=True, + string='Linked resource') + weekday = fields.Selection([('0', _('Monday')), + ('1', _('Tuesday')), + ('2', _('Wednesday')), + ('3', _('Thursday')), + ('4', _('Friday')), + ('5', _('Saturday')), + ('6', _('Sunday'))], required=True) + time_start = fields.Float(string='Start') + time_stop = fields.Float(string='Stop') + availibility_24 = fields.Boolean(string="All day") + + @api.onchange('availibility_24') + def onchange_availibility_24(self): + """ fill time_start et time_stop if availibility_24 is True """ + for line in self: + if line.availibility_24: + line.update({'time_start': 0.0, 'time_stop': 23.98}) + + @api.onchange('time_start') + def onchange_time_start(self): + """ Propose automatically stop hour after start hour had been filled """ + for line in self: + if line.time_start and not line.time_stop: + line.time_stop = line.time_start + 1 + + @api.constrains('availibility_24') + def check_avaibility24(self): + """ Checks hour consistency against avaibility 24 """ + for line in self: + if line.availibility_24: + line.write({'time_start': 0.0, 'time_stop': 23.98}) + + @api.constrains('time_start', 'time_stop') + def _check_time_consistency(self): + """ Checks time consistency """ + for line in self: + if line.time_stop <= line.time_start: + raise ValidationError(_('End time should be after than start time')) + + @api.constrains('time_start', 'time_stop') + def _check_time_all_day(self): + """ Checks time all day availibility """ + for timetable in self: + if timetable.time_stop > 23.98 and timetable.time_start == 0: + timetable.write({'availibility_24': True}) diff --git a/golem_resource_option/models/golem_resource_type.py b/golem_resource_option/models/golem_resource_type.py new file mode 100644 index 0000000..c13cd02 --- /dev/null +++ b/golem_resource_option/models/golem_resource_type.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 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 . + +""" GOLEM Resource Type """ + +from odoo import models, fields + +class GolemResourceType(models.Model): + """ GOLEM Resource Type """ + _name = 'golem.resource.type' + _description = 'GOLEM Resource Type' + _order = 'name asc' + _sql_constraints = [('golem_resource_type_name_uniq', + 'UNIQUE (name)', + 'Resource type must be unique.')] + + name = fields.Char(string='Resource Type', required=True, index=True) diff --git a/golem_resource_option/views/golem_resource_reservation_views.xml b/golem_resource_option/views/golem_resource_reservation_views.xml new file mode 100644 index 0000000..03c2063 --- /dev/null +++ b/golem_resource_option/views/golem_resource_reservation_views.xml @@ -0,0 +1,146 @@ + + + + + + + + GOLEM Resource Reservation Calendar + golem.resource.reservation + + + + + + + + + + + + GOLEM Resource Reservation Tree + golem.resource.reservation + + + + + + + + + + + + + + GOLEM Resource Reservation Form + golem.resource.reservation + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ + + + GOLEM Resource Reservation Search + golem.resource.reservation + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/golem_resource_option/views/golem_resource_timetable_views.xml b/golem_resource_option/views/golem_resource_timetable_views.xml new file mode 100644 index 0000000..fa4da10 --- /dev/null +++ b/golem_resource_option/views/golem_resource_timetable_views.xml @@ -0,0 +1,38 @@ + + + + + + + GOLEM Resource Timetable Tree + golem.resource.timetable + + + + + + + + + + + + diff --git a/golem_resource_option/views/golem_resource_type_views.xml b/golem_resource_option/views/golem_resource_type_views.xml new file mode 100644 index 0000000..cc94a87 --- /dev/null +++ b/golem_resource_option/views/golem_resource_type_views.xml @@ -0,0 +1,54 @@ + + + + + + + + GOLEM Resource Type Tree + golem.resource.type + + + + + + + + + + GOLEM Resource Type Search + golem.resource.type + + + + + + + + + + + + + + + diff --git a/golem_resource_option/views/golem_resource_views.xml b/golem_resource_option/views/golem_resource_views.xml new file mode 100644 index 0000000..7fb2a25 --- /dev/null +++ b/golem_resource_option/views/golem_resource_views.xml @@ -0,0 +1,140 @@ + + + + + + + + GOLEM Resource Tree + golem.resource + + + + + + + + + + + + + + + + GOLEM Resource Form + golem.resource + +
+ +
+ + +
+ + + + + + + + + + + + + + + + + + +

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

+ + + +
+
+
+ + +
+
+
+
+ + + + GOLEM Resource search + golem.resource + + + + + + + + + + + + + + + + + + + + + + + + + +
+