Ajout des contraintes et des vues necessaires

This commit is contained in:
eloyoussef 2018-03-22 11:32:14 +01:00
parent 1967ab5ced
commit 1f295ec9c7
9 changed files with 108 additions and 13 deletions

View File

@ -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']
}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,38 @@
<?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="name" invisible="1"/>
<field name="resource_id" invisible="1" />
<field name="reservation_id" invisible="1"/>
<field name="option_id"/>
</group>
</form>
</field>
</record>
</data>
</odoo>

View File

@ -0,0 +1,36 @@
<?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_form">
<field name="name">GOLEM Resource Option Form</field>
<field name="model">golem.resource.option</field>
<field name="arch" type="xml">
<form >
<group>
<field name="name" />
<field name="resource_id" invisible="1" />
</group>
</form>
</field>
</record>
</data>
</odoo>

View File

@ -73,6 +73,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group string="Resource">
<field name="id" invisible="1" />
<field name="resource_id" options="{'no_create': True}" />
<field name="resource_option_ids" widget="many2many_tags" readonly="1"/>
<field name="resource_avaibility_24_7" readonly="1" />
<field name="resource_avaibility_start" readonly="1" />
<field name="resource_avaibility_stop" readonly="1" />
@ -89,6 +90,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
placeholder="Notes, optional subject for the reservation, reason" />
<field name="rejection_reason"
attrs="{'invisible': [('state', '!=', 'rejected')]}"/>
<field name="selected_option_ids"
context="{'default_reservation_id': active_id}"
widget="many2many_tags">
<tree>
<field name="option_id"/>
</tree>
</field>
</group>
</group>
</group>

View File

@ -62,10 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="name" />
<field name="type_id" />
<field name="product_tmpl_id" options="{'no_create': True}" />
<field name="supervisor_id" />
<field name="validation_required" />
</group>
<group>
<field name="validation_required" />
<field name="supervisor_id" />
<field name="option_ids" widget="many2many_tags"
context="{'default_resource_id': active_id}" />
</group>
</group>
<group string="Availibility configuration">