[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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
{ {
'name': 'GOLEM resources option', 'name': 'GOLEM resources options',
'summary': 'GOLEM resources option', 'summary': 'GOLEM resources options',
'description': ''' GOLEM resources option ''', 'description': ''' GOLEM resources options management :
'version': '10.0.0.0.0', - create 1:n options per resource ;
- choose option on reservations ''',
'version': '10.0.0.1.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois', 'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': True, 'application': True,
'installable': True, 'installable': True,
'depends': ['golem_resource'], 'depends': ['golem_resource'],
'data': [ 'data': ['views/golem_resource_views.xml',
'views/golem_resource_views.xml', 'views/golem_resource_reservation_views.xml',
'views/golem_resource_reservation_views.xml', 'views/golem_resource_option_views.xml',
'views/golem_resource_option_views.xml', 'views/golem_resource_option_selection_views.xml']
'views/golem_resource_option_selection_views.xml']
} }

View File

@ -18,8 +18,7 @@
""" GOLEM Resources Option Management """ """ GOLEM Resources Option Management """
from odoo import models, fields, api, _ from odoo import models, fields
from odoo.exceptions import ValidationError
class GolemResource(models.Model): class GolemResource(models.Model):
@ -27,4 +26,4 @@ class GolemResource(models.Model):
_inherit = 'golem.resource' _inherit = 'golem.resource'
option_ids = fields.One2many('golem.resource.option', 'resource_id', 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' _name = 'golem.resource.option'
_description = 'GOLEM Reservation Option Model' _description = 'GOLEM Reservation Option Model'
name = fields.Char("Option") name = fields.Char('Option', index=True)
resource_id = fields.Many2one('golem.resource', "Resource") 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 """ """ GOLEM Resource Option SelectionModel """
_name = 'golem.resource.option.selection' _name = 'golem.resource.option.selection'
_description = 'GOLEM Resource option selection Model' _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 = [ _sql_constraints = [
('unique_selection', "UNIQUE(resource_id, option_id, reservation_id)", ('unique_selection', 'UNIQUE(resource_id, option_id, reservation_id)',
_("Not allowed, a reservation with same option and resource already exists"))] _('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 """ """ GOLEM Resource Reservation """
from datetime import timedelta from odoo import models, fields
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemResourceReservation(models.Model): class GolemResourceReservation(models.Model):
@ -29,5 +27,6 @@ class GolemResourceReservation(models.Model):
_inherit = 'golem.resource.reservation' _inherit = 'golem.resource.reservation'
resource_option_ids = fields.One2many(related="resource_id.option_ids") resource_option_ids = fields.One2many(related="resource_id.option_ids")
selected_option_ids = fields.One2many('golem.resource.option.selection', 'reservation_id', selected_option_ids = fields.One2many('golem.resource.option.selection',
string="Selected option") '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"> <field name="arch" type="xml">
<form > <form >
<group> <group>
<field name="name" invisible="1"/>
<field name="resource_id" invisible="1" /> <field name="resource_id" invisible="1" />
<field name="reservation_id" invisible="1"/> <field name="reservation_id" invisible="1"/>
<field name="option_id"/> <field name="option_id"/>

View File

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

View File

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