diff --git a/golem_resource/__manifest__.py b/golem_resource/__manifest__.py index 7fec3ab..4f6c6ec 100644 --- a/golem_resource/__manifest__.py +++ b/golem_resource/__manifest__.py @@ -31,6 +31,8 @@ 'views/golem_resource_type_views.xml', 'views/golem_resource_reservation_views.xml', 'views/golem_resource_timetable_views.xml', + 'views/golem_resource_option_views.xml', + 'views/golem_resource_option_selection_views.xml', 'wizard/golem_reservation_rejection_views.xml', 'security/ir.model.access.csv'] } diff --git a/golem_resource/models/__init__.py b/golem_resource/models/__init__.py index d3aab06..7c34aaf 100644 --- a/golem_resource/models/__init__.py +++ b/golem_resource/models/__init__.py @@ -19,4 +19,6 @@ from . import golem_resource_type, \ golem_resource_timetable, \ golem_resource, \ - golem_resource_reservation + golem_resource_reservation, \ + golem_resource_option, \ + golem_resource_option_selection diff --git a/golem_resource/models/golem_resource_option.py b/golem_resource/models/golem_resource_option.py index b9905b9..3350a22 100644 --- a/golem_resource/models/golem_resource_option.py +++ b/golem_resource/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/models/golem_resource_option_selection.py b/golem_resource/models/golem_resource_option_selection.py index 64f3db8..c36b1a9 100644 --- a/golem_resource/models/golem_resource_option_selection.py +++ b/golem_resource/models/golem_resource_option_selection.py @@ -20,7 +20,6 @@ from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError class GolemResourceOptionSelection(models.Model): @@ -28,10 +27,17 @@ class GolemResourceOptionSelection(models.Model): _name = 'golem.resource.option.selection' _description = 'GOLEM Resource option selection Model' - resource_id = fields.Many2one('golem.resource', 'Resource') - option_id = fields.Many2one('golem.resource.option', 'Option') + 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/models/golem_resource_reservation.py b/golem_resource/models/golem_resource_reservation.py index 8a4cd74..c511951 100644 --- a/golem_resource/models/golem_resource_reservation.py +++ b/golem_resource/models/golem_resource_reservation.py @@ -18,7 +18,7 @@ """ GOLEM Resource Reservation """ -from math import modf + from datetime import timedelta from odoo import models, fields, api, _ from odoo.exceptions import ValidationError @@ -32,7 +32,6 @@ class GolemResourceReservation(models.Model): _order = 'day_start desc, hour_start asc' name = fields.Char(compute='_compute_name', store=True) - # TODO: handle multiple days reservation date_start = fields.Datetime('Start date', required=True, index=True, readonly=True, states={'draft': [('readonly', False)]}) @@ -67,6 +66,9 @@ class GolemResourceReservation(models.Model): default='draft', track_visibility='onchange') rejection_reason = fields.Text(readonly=True, track_visibility='onchange') + resource_option_ids = fields.One2many(related="resource_id.option_ids") + selected_option_ids = fields.One2many('golem.resource.option.selection', 'reservation_id', + string="Selected option") @api.depends('resource_id', 'date_start') def _compute_name(self): diff --git a/golem_resource/views/golem_resource_option_selection_views.xml b/golem_resource/views/golem_resource_option_selection_views.xml new file mode 100644 index 0000000..7d1fa9d --- /dev/null +++ b/golem_resource/views/golem_resource_option_selection_views.xml @@ -0,0 +1,38 @@ + + + + + + + + GOLEM Resource Option Selection Form + golem.resource.option.selection + +
+ + + + + + +
+
+
+
+
diff --git a/golem_resource/views/golem_resource_option_views.xml b/golem_resource/views/golem_resource_option_views.xml new file mode 100644 index 0000000..8f9665b --- /dev/null +++ b/golem_resource/views/golem_resource_option_views.xml @@ -0,0 +1,36 @@ + + + + + + + + GOLEM Resource Option Form + golem.resource.option + +
+ + + + +
+
+
+
+
diff --git a/golem_resource/views/golem_resource_reservation_views.xml b/golem_resource/views/golem_resource_reservation_views.xml index 03c2063..56a6226 100644 --- a/golem_resource/views/golem_resource_reservation_views.xml +++ b/golem_resource/views/golem_resource_reservation_views.xml @@ -73,6 +73,7 @@ along with this program. If not, see . + @@ -89,6 +90,13 @@ along with this program. If not, see . placeholder="Notes, optional subject for the reservation, reason" /> + + + + + diff --git a/golem_resource/views/golem_resource_views.xml b/golem_resource/views/golem_resource_views.xml index 7fb2a25..b0bdfcf 100644 --- a/golem_resource/views/golem_resource_views.xml +++ b/golem_resource/views/golem_resource_views.xml @@ -62,10 +62,12 @@ along with this program. If not, see . + + - - +