From 73e92ca55185cfa981aebfda48c5e2855dc429aa Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Tue, 27 Mar 2018 15:20:01 +0200 Subject: [PATCH] =?UTF-8?q?deplacement=20des=20fonctionnalit=C3=A9s=20sur?= =?UTF-8?q?=20un=20nouveau=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_resource_option/__manifest__.py | 6 +- golem_resource_option/models/__init__.py | 4 +- .../models/golem_resource.py | 73 +--------- .../models/golem_resource_option.py | 9 +- .../models/golem_resource_option_selection.py | 43 ++++++ ..._type.py => golem_resource_reservation.py} | 23 +-- .../models/golem_resource_timetable.py | 77 ---------- ...golem_resource_option_selection_views.xml} | 26 ++-- .../views/golem_resource_option_views.xml | 36 +++++ .../golem_resource_reservation_views.xml | 131 ++---------------- .../views/golem_resource_type_views.xml | 54 -------- .../views/golem_resource_views.xml | 120 +--------------- 12 files changed, 138 insertions(+), 464 deletions(-) create mode 100644 golem_resource_option/models/golem_resource_option_selection.py rename golem_resource_option/models/{golem_resource_type.py => golem_resource_reservation.py} (60%) delete mode 100644 golem_resource_option/models/golem_resource_timetable.py rename golem_resource_option/views/{golem_resource_timetable_views.xml => golem_resource_option_selection_views.xml} (59%) create mode 100644 golem_resource_option/views/golem_resource_option_views.xml delete mode 100644 golem_resource_option/views/golem_resource_type_views.xml diff --git a/golem_resource_option/__manifest__.py b/golem_resource_option/__manifest__.py index e40d824..da1651b 100644 --- a/golem_resource_option/__manifest__.py +++ b/golem_resource_option/__manifest__.py @@ -27,5 +27,9 @@ 'application': True, 'installable': True, 'depends': ['golem_resource'], - 'data': [] + 'data': [ + 'views/golem_resource_views.xml', + 'views/golem_resource_reservation_views.xml', + 'views/golem_resource_option_views.xml', + 'views/golem_resource_option_selection_views.xml'] } diff --git a/golem_resource_option/models/__init__.py b/golem_resource_option/models/__init__.py index d3aab06..5692f80 100644 --- a/golem_resource_option/models/__init__.py +++ b/golem_resource_option/models/__init__.py @@ -16,7 +16,7 @@ # 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, \ +from . import golem_resource_option, \ + golem_resource_option_selection, \ golem_resource, \ golem_resource_reservation diff --git a/golem_resource_option/models/golem_resource.py b/golem_resource_option/models/golem_resource.py index fba69c5..1852270 100644 --- a/golem_resource_option/models/golem_resource.py +++ b/golem_resource_option/models/golem_resource.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -""" GOLEM Resources management """ +""" GOLEM Resources Option Management """ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError @@ -24,72 +24,7 @@ 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' + _inherit = 'golem.resource' - 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')) + option_ids = fields.One2many('golem.resource.option', 'resource_id', + string='Option list') diff --git a/golem_resource_option/models/golem_resource_option.py b/golem_resource_option/models/golem_resource_option.py index b9905b9..3350a22 100644 --- a/golem_resource_option/models/golem_resource_option.py +++ b/golem_resource_option/models/golem_resource_option.py @@ -19,14 +19,13 @@ """ GOLEM Resource Option """ -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError +from odoo import models, fields class GolemResourceOption(models.Model): """ GOLEM Resource Option Model """ _name = 'golem.resource.option' - _description = 'GOLEM Reservation Model' + _description = 'GOLEM Reservation Option Model' - name = fields.Char() - resource_id = fields.Many2one('golem.resource') + name = fields.Char("Option") + resource_id = fields.Many2one('golem.resource', "Resource") diff --git a/golem_resource_option/models/golem_resource_option_selection.py b/golem_resource_option/models/golem_resource_option_selection.py new file mode 100644 index 0000000..c36b1a9 --- /dev/null +++ b/golem_resource_option/models/golem_resource_option_selection.py @@ -0,0 +1,43 @@ +# -*- 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 Selection""" + + +from odoo import models, fields, api, _ + + +class GolemResourceOptionSelection(models.Model): + """ GOLEM Resource Option SelectionModel """ + _name = 'golem.resource.option.selection' + _description = 'GOLEM Resource option selection Model' + + name = fields.Char(compute="_compute_name") + option_id = fields.Many2one('golem.resource.option', 'Option', + domain="[('resource_id', '=', resource_id)]") + resource_id = fields.Many2one(related="reservation_id.resource_id") + reservation_id = fields.Many2one('golem.resource.reservation', 'Reservation') + + @api.multi + def _compute_name(self): + for selection in self: + selection.name = "{}/{}".format(selection.resource_id.name, selection.option_id.name) + + _sql_constraints = [ + ('unique_selection', "UNIQUE(resource_id, option_id, reservation_id)", + _("Not allowed, a reservation with same option and resource already exists"))] diff --git a/golem_resource_option/models/golem_resource_type.py b/golem_resource_option/models/golem_resource_reservation.py similarity index 60% rename from golem_resource_option/models/golem_resource_type.py rename to golem_resource_option/models/golem_resource_reservation.py index c13cd02..fa35285 100644 --- a/golem_resource_option/models/golem_resource_type.py +++ b/golem_resource_option/models/golem_resource_reservation.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 Type """ +""" GOLEM Resource Reservation """ -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.')] +from datetime import timedelta +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError - name = fields.Char(string='Resource Type', required=True, index=True) + +class GolemResourceReservation(models.Model): + """ GOLEM Resource Reservation Option Model """ + _inherit = 'golem.resource.reservation' + + resource_option_ids = fields.One2many(related="resource_id.option_ids") + selected_option_ids = fields.One2many('golem.resource.option.selection', 'reservation_id', + string="Selected option") diff --git a/golem_resource_option/models/golem_resource_timetable.py b/golem_resource_option/models/golem_resource_timetable.py deleted file mode 100644 index 4b6acf4..0000000 --- a/golem_resource_option/models/golem_resource_timetable.py +++ /dev/null @@ -1,77 +0,0 @@ -# -*- 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/views/golem_resource_timetable_views.xml b/golem_resource_option/views/golem_resource_option_selection_views.xml similarity index 59% rename from golem_resource_option/views/golem_resource_timetable_views.xml rename to golem_resource_option/views/golem_resource_option_selection_views.xml index fa4da10..7d1fa9d 100644 --- a/golem_resource_option/views/golem_resource_timetable_views.xml +++ b/golem_resource_option/views/golem_resource_option_selection_views.xml @@ -18,20 +18,20 @@ along with this program. If not, see . --> - - - GOLEM Resource Timetable Tree - golem.resource.timetable + + + + GOLEM Resource Option Selection Form + golem.resource.option.selection - - - - - - - +
+ + + + + + +
diff --git a/golem_resource_option/views/golem_resource_option_views.xml b/golem_resource_option/views/golem_resource_option_views.xml new file mode 100644 index 0000000..8f9665b --- /dev/null +++ b/golem_resource_option/views/golem_resource_option_views.xml @@ -0,0 +1,36 @@ + + + + + + + + GOLEM Resource Option Form + golem.resource.option + +
+ + + + +
+
+
+
+
diff --git a/golem_resource_option/views/golem_resource_reservation_views.xml b/golem_resource_option/views/golem_resource_reservation_views.xml index 03c2063..82301a0 100644 --- a/golem_resource_option/views/golem_resource_reservation_views.xml +++ b/golem_resource_option/views/golem_resource_reservation_views.xml @@ -18,129 +18,22 @@ along with this program. If not, see . --> - - - - GOLEM Resource Reservation Calendar - golem.resource.reservation - - - - - - - - - - - - GOLEM Resource Reservation Tree - golem.resource.reservation - - - - - - - - - - - - - GOLEM Resource Reservation Form + + GOLEM Resource Reservation Option Extension Form golem.resource.reservation + -
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- - -
-
+ + + + + + +
- - - - GOLEM Resource Reservation Search - golem.resource.reservation - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/golem_resource_option/views/golem_resource_type_views.xml b/golem_resource_option/views/golem_resource_type_views.xml deleted file mode 100644 index cc94a87..0000000 --- a/golem_resource_option/views/golem_resource_type_views.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - 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 index 7fb2a25..03c6bc1 100644 --- a/golem_resource_option/views/golem_resource_views.xml +++ b/golem_resource_option/views/golem_resource_views.xml @@ -18,123 +18,17 @@ along with this program. If not, see . --> - - - - GOLEM Resource Tree - golem.resource - - - - - - - - - - - - - - - GOLEM Resource Form + + GOLEM Resource Option Extention Form golem.resource + -
- -
- - -
- - - - - - - - - - - - - - - - - - -

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

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