[REF][IMP]GOLEM Resource Option : small refactoring / quality and performance

This commit is contained in:
Fabien BOURGEOIS 2018-03-29 08:07:50 +02:00
parent e7fad86347
commit 0e250ea075
8 changed files with 36 additions and 40 deletions

View File

@ -17,19 +17,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'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']
}

View File

@ -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')

View File

@ -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)

View File

@ -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)

View File

@ -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")

View File

@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="arch" type="xml">
<form >
<group>
<field name="name" invisible="1"/>
<field name="resource_id" invisible="1" />
<field name="reservation_id" invisible="1"/>
<field name="option_id"/>

View File

@ -18,8 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Forms -->
<record model="ir.ui.view" id="golem_resource_reservation_inherit_option_form">
<record model="ir.ui.view"
id="golem_resource_reservation_view_form_inherit_golem_resource_option">
<field name="name">GOLEM Resource Reservation Option Extension Form</field>
<field name="model">golem.resource.reservation</field>
<field name="inherit_id" ref="golem_resource.golem_resource_reservation_view_form"/>
@ -27,13 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="partner_id" position="after" >
<field name="selected_option_ids"
context="{'default_reservation_id': active_id}"
widget="many2many_tags">
<tree>
<field name="option_id"/>
</tree>
</field>
widget="many2many_tags" />
</field>
</field>
</record>
</data>
</odoo>

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Forms -->
<record model="ir.ui.view" id="golem_resource_inherit_option_form">
<field name="name">GOLEM Resource Option Extention Form</field>
@ -30,5 +31,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</field>
</field>
</record>
</data>
</odoo>