From 0e250ea0753b03766e4378f03608b741a77b1e01 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Thu, 29 Mar 2018 08:07:50 +0200 Subject: [PATCH] [REF][IMP]GOLEM Resource Option : small refactoring / quality and performance --- golem_resource_option/__manifest__.py | 19 ++++++++------- .../models/golem_resource.py | 5 ++-- .../models/golem_resource_option.py | 5 ++-- .../models/golem_resource_option_selection.py | 24 ++++++++----------- .../models/golem_resource_reservation.py | 9 ++++--- .../golem_resource_option_selection_views.xml | 1 - .../golem_resource_reservation_views.xml | 11 ++++----- .../views/golem_resource_views.xml | 2 ++ 8 files changed, 36 insertions(+), 40 deletions(-) diff --git a/golem_resource_option/__manifest__.py b/golem_resource_option/__manifest__.py index da1651b..179e06d 100644 --- a/golem_resource_option/__manifest__.py +++ b/golem_resource_option/__manifest__.py @@ -17,19 +17,20 @@ # 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', + 'name': 'GOLEM resources options', + 'summary': 'GOLEM resources options', + 'description': ''' GOLEM resources options management : + - create 1:n options per resource ; + - choose option on reservations ''', + 'version': '10.0.0.1.0', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', 'application': True, 'installable': True, 'depends': ['golem_resource'], - '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'] + '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/golem_resource.py b/golem_resource_option/models/golem_resource.py index 1852270..258c0bc 100644 --- a/golem_resource_option/models/golem_resource.py +++ b/golem_resource_option/models/golem_resource.py @@ -18,8 +18,7 @@ """ GOLEM Resources Option Management """ -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError +from odoo import models, fields class GolemResource(models.Model): @@ -27,4 +26,4 @@ class GolemResource(models.Model): _inherit = 'golem.resource' option_ids = fields.One2many('golem.resource.option', 'resource_id', - string='Option list') + string='Options') diff --git a/golem_resource_option/models/golem_resource_option.py b/golem_resource_option/models/golem_resource_option.py index 3350a22..8b8cd3a 100644 --- a/golem_resource_option/models/golem_resource_option.py +++ b/golem_resource_option/models/golem_resource_option.py @@ -27,5 +27,6 @@ class GolemResourceOption(models.Model): _name = 'golem.resource.option' _description = 'GOLEM Reservation Option Model' - name = fields.Char("Option") - resource_id = fields.Many2one('golem.resource', "Resource") + name = fields.Char('Option', index=True) + resource_id = fields.Many2one('golem.resource', 'Resource', + index=True, required=True) diff --git a/golem_resource_option/models/golem_resource_option_selection.py b/golem_resource_option/models/golem_resource_option_selection.py index 14fb049..0c5ce8e 100644 --- a/golem_resource_option/models/golem_resource_option_selection.py +++ b/golem_resource_option/models/golem_resource_option_selection.py @@ -26,18 +26,14 @@ 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 = u"{}/{}".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"))] + ('unique_selection', 'UNIQUE(resource_id, option_id, reservation_id)', + _('Not allowed, a reservation with same option and resource already exists'))] + + name = fields.Char(related='option_id.name') + option_id = fields.Many2one('golem.resource.option', 'Option', + required=True, index=True, + domain='[("resource_id", "=", resource_id)]') + resource_id = fields.Many2one(related='reservation_id.resource_id') + reservation_id = fields.Many2one('golem.resource.reservation', 'Reservation', + required=True, index=True) diff --git a/golem_resource_option/models/golem_resource_reservation.py b/golem_resource_option/models/golem_resource_reservation.py index fa35285..4cb65fa 100644 --- a/golem_resource_option/models/golem_resource_reservation.py +++ b/golem_resource_option/models/golem_resource_reservation.py @@ -19,9 +19,7 @@ """ GOLEM Resource Reservation """ -from datetime import timedelta -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError +from odoo import models, fields class GolemResourceReservation(models.Model): @@ -29,5 +27,6 @@ class GolemResourceReservation(models.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") + selected_option_ids = fields.One2many('golem.resource.option.selection', + 'reservation_id', + string="Selected options") diff --git a/golem_resource_option/views/golem_resource_option_selection_views.xml b/golem_resource_option/views/golem_resource_option_selection_views.xml index 7d1fa9d..23a785d 100644 --- a/golem_resource_option/views/golem_resource_option_selection_views.xml +++ b/golem_resource_option/views/golem_resource_option_selection_views.xml @@ -26,7 +26,6 @@ along with this program. If not, see .
- diff --git a/golem_resource_option/views/golem_resource_reservation_views.xml b/golem_resource_option/views/golem_resource_reservation_views.xml index 82301a0..6a648e9 100644 --- a/golem_resource_option/views/golem_resource_reservation_views.xml +++ b/golem_resource_option/views/golem_resource_reservation_views.xml @@ -18,8 +18,10 @@ along with this program. If not, see . --> + - + GOLEM Resource Reservation Option Extension Form golem.resource.reservation @@ -27,13 +29,10 @@ along with this program. If not, see . - - - - + widget="many2many_tags" /> + diff --git a/golem_resource_option/views/golem_resource_views.xml b/golem_resource_option/views/golem_resource_views.xml index 03c6bc1..fed88da 100644 --- a/golem_resource_option/views/golem_resource_views.xml +++ b/golem_resource_option/views/golem_resource_views.xml @@ -18,6 +18,7 @@ along with this program. If not, see . --> + GOLEM Resource Option Extention Form @@ -30,5 +31,6 @@ along with this program. If not, see . +