[REF][ADD]GOLEM Resource Option : options tree under configuration, active for options and m2m for reservation (finally), multiple small enhancements

This commit is contained in:
Fabien BOURGEOIS 2018-03-29 08:35:19 +02:00
parent 0e250ea075
commit 8ea116675e
9 changed files with 54 additions and 90 deletions

View File

@ -31,6 +31,5 @@
'depends': ['golem_resource'], 'depends': ['golem_resource'],
'data': ['views/golem_resource_views.xml', 'data': ['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']
} }

View File

@ -16,7 +16,4 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import golem_resource_option, \ from . import golem_resource_option, golem_resource, golem_resource_reservation
golem_resource_option_selection, \
golem_resource, \
golem_resource_reservation

View File

@ -19,14 +19,19 @@
""" GOLEM Resource Option """ """ GOLEM Resource Option """
from odoo import models, fields from odoo import models, fields, _
class GolemResourceOption(models.Model): class GolemResourceOption(models.Model):
""" GOLEM Resource Option Model """ """ GOLEM Resource Option Model """
_name = 'golem.resource.option' _name = 'golem.resource.option'
_description = 'GOLEM Reservation Option Model' _description = 'GOLEM Reservation Option Model'
_order = 'name asc, resource_id asc'
_sql_constraints = [('golem_resource_option_name_uniq',
'UNIQUE (name, resource_id)',
_('An option has already this name for this resource.'))]
name = fields.Char('Option', index=True) name = fields.Char('Option', required=True, index=True)
resource_id = fields.Many2one('golem.resource', 'Resource', resource_id = fields.Many2one('golem.resource', 'Resource',
index=True, required=True) index=True, required=True)
active = fields.Boolean(default=True)

View File

@ -1,39 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
""" 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'
_sql_constraints = [
('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

@ -27,6 +27,7 @@ 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', selected_option_ids = fields.Many2many(
'reservation_id', 'golem.resource.option', string='Selected options',
string="Selected options") index=True, readonly=True, domain='[("resource_id", "=", resource_id)]',
states={'draft': [('readonly', False)], 'confirmed': [('readonly', False)]})

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
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 <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Form -->
<record model="ir.ui.view" id="golem_resource_option_selection_form">
<field name="name">GOLEM Resource Option Selection Form</field>
<field name="model">golem.resource.option.selection</field>
<field name="arch" type="xml">
<form >
<group>
<field name="resource_id" invisible="1" />
<field name="reservation_id" invisible="1"/>
<field name="option_id"/>
</group>
</form>
</field>
</record>
</data>
</odoo>

View File

@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="name">GOLEM Resource Option Form</field> <field name="name">GOLEM Resource Option Form</field>
<field name="model">golem.resource.option</field> <field name="model">golem.resource.option</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form > <form>
<group> <group>
<field name="name" /> <field name="name" />
<field name="resource_id" invisible="1" /> <field name="resource_id" invisible="1" />
@ -32,5 +32,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</form> </form>
</field> </field>
</record> </record>
<!-- Tree -->
<record model="ir.ui.view" id="golem_resource_option_tree">
<field name="name">GOLEM Resource Option Tree</field>
<field name="model">golem.resource.option</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="name" />
<field name="resource_id" options="{'no_create': True}" />
<field name="active" />
</tree>
</field>
</record>
<!-- Search -->
<record model="ir.ui.view" id="golem_resource_option_search">
<field name="name">GOLEM Resource Option Search</field>
<field name="model">golem.resource.option</field>
<field name="arch" type="xml">
<search>
<field name="name" />
<field name="resource_id" />
<filter name="inactive" string="Inactive"
domain="[('active', '=', False)]" />
<filter name="group_resource" string="By resource"
context="{'group_by': 'resource_id'}" />
</search>
</field>
</record>
<!-- Action -->
<act_window id="golem_resource_option_action" name="Options"
res_model="golem.resource.option" view_mode="tree" />
<!-- Menu -->
<menuitem id="golem_resource_option_menu" name="Options"
parent="golem_resource.resource_configuration_menu"
action="golem_resource_option_action" sequence="15" />
</data> </data>
</odoo> </odoo>

View File

@ -29,7 +29,7 @@ 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_checkboxes" />
</field> </field>
</field> </field>

View File

@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="model">golem.resource</field> <field name="model">golem.resource</field>
<field name="inherit_id" ref="golem_resource.golem_resource_view_form"/> <field name="inherit_id" ref="golem_resource.golem_resource_view_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="supervisor_id" position="after"> <field name="product_tmpl_id" position="after">
<field name="option_ids" widget="many2many_tags" <field name="option_ids" widget="many2many_tags"
context="{'default_resource_id': active_id}" /> context="{'default_resource_id': active_id}" />
</field> </field>