forked from Yaltik/golem
1er version du modèle reservation, avec contraintes de disponibilité operationnelles
This commit is contained in:
parent
7dc2213593
commit
3766f49805
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
|
|
||||||
from odoo import models, fields, api, _, exceptions
|
from odoo import models, fields, api, _, exceptions
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
#modèle de base : ressources
|
#modèle de base : ressources
|
||||||
class GolemResources(models.Model):
|
class GolemResources(models.Model):
|
||||||
""" GOLEM Resources """
|
""" GOLEM Resources """
|
||||||
@ -34,6 +37,7 @@ class GolemResources(models.Model):
|
|||||||
start_of_availability_date = fields.Date(required=True)
|
start_of_availability_date = fields.Date(required=True)
|
||||||
end_of_availability_date = fields.Date(required=True)
|
end_of_availability_date = fields.Date(required=True)
|
||||||
timetable = fields.One2many("golem.timetable", "resource_id", string="Availibility timetable")
|
timetable = fields.One2many("golem.timetable", "resource_id", string="Availibility timetable")
|
||||||
|
reservation = fields.One2many("golem.reservation", "linked_resource")
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def active_change(self):
|
def active_change(self):
|
||||||
@ -52,6 +56,7 @@ class GolemReservation(models.Model):
|
|||||||
linked_resource = fields.Many2one('golem.resources', required=True)
|
linked_resource = fields.Many2one('golem.resources', required=True)
|
||||||
user = fields.Many2one('res.users', required=True)
|
user = fields.Many2one('res.users', required=True)
|
||||||
on_behalf_of = fields.Many2one('res.partner', required=True)
|
on_behalf_of = fields.Many2one('res.partner', required=True)
|
||||||
|
#statut=fields.Char()
|
||||||
status = fields.Selection([
|
status = fields.Selection([
|
||||||
('draft', "Draft"),
|
('draft', "Draft"),
|
||||||
('confirmed', "Confirmed"),
|
('confirmed', "Confirmed"),
|
||||||
@ -64,8 +69,8 @@ class GolemReservation(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def status_confirm(self):
|
def status_confirm(self):
|
||||||
#self.status = 'confirmed'
|
self.status = 'confirmed'
|
||||||
exceptions.ValidationError('not allowed')
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def status_canceled(self):
|
def status_canceled(self):
|
||||||
@ -73,9 +78,14 @@ class GolemReservation(models.Model):
|
|||||||
|
|
||||||
@api.constrains('status')
|
@api.constrains('status')
|
||||||
def _onConfirmReservation(self):
|
def _onConfirmReservation(self):
|
||||||
if(self.status == 'confrimed'):
|
if self.status == 'confirmed':
|
||||||
exceptions.UserError('not allowed')
|
if(self.start_date < self.linked_resource.start_of_availability_date or self.end_date > self.linked_resource.end_of_availability_date ):
|
||||||
#exceptions.ValidationError('not allowed')
|
raise exceptions.UserError('Not allowed, the resource is not available in this period, please choose another périod before confirming %s' % self.linked_resource.start_of_availability_date)
|
||||||
|
else :
|
||||||
|
for reservation in self.linked_resource.reservation :
|
||||||
|
if(self.id != reservation.id and reservation.status == 'confirmed' and not (self.end_date < reservation.start_date or self.start_date > reservation.end_date)):
|
||||||
|
raise exceptions.UserError("Not allowed, the resource is taken during this period, please choose another période before confirming ")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#modèle de base pour identifier le type de la ressource
|
#modèle de base pour identifier le type de la ressource
|
||||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
-->
|
-->
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
|
<!--Calendrier des reservations-->
|
||||||
<record model="ir.ui.view" id="reservation_calendar_view">
|
<record model="ir.ui.view" id="reservation_calendar_view">
|
||||||
<field name="name">reservation.calendar</field>
|
<field name="name">reservation.calendar</field>
|
||||||
<field name="model">golem.reservation</field>
|
<field name="model">golem.reservation</field>
|
||||||
@ -29,6 +30,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</calendar>
|
</calendar>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!--liste des réservations -->
|
||||||
<record model="ir.ui.view" id="reservation_tree_view">
|
<record model="ir.ui.view" id="reservation_tree_view">
|
||||||
<field name="name">reservation.tree</field>
|
<field name="name">reservation.tree</field>
|
||||||
<field name="model">golem.reservation</field>
|
<field name="model">golem.reservation</field>
|
||||||
@ -39,10 +42,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<field name="linked_resource"/>
|
<field name="linked_resource"/>
|
||||||
<field name="user"/>
|
<field name="user"/>
|
||||||
<field name="on_behalf_of"/>
|
<field name="on_behalf_of"/>
|
||||||
<field name="status" widget="statusbar"/>
|
<field name="status"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!--Formulaire de réservation de ressource-->
|
||||||
<record model="ir.ui.view" id="reservation_form_view">
|
<record model="ir.ui.view" id="reservation_form_view">
|
||||||
<field name="name">reservation.form</field>
|
<field name="name">reservation.form</field>
|
||||||
<field name="model">golem.reservation</field>
|
<field name="model">golem.reservation</field>
|
||||||
|
@ -108,6 +108,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</group>
|
</group>
|
||||||
|
<group colspan="3">
|
||||||
|
<field name="reservation" >
|
||||||
|
<tree >
|
||||||
|
<field name="linked_resource" invisible="1"/>
|
||||||
|
<field name="start_date"/>
|
||||||
|
<field name="end_date" />
|
||||||
|
<field name="user" />
|
||||||
|
<field name="on_behalf_of" />
|
||||||
|
<field name="status" widget="statusbar" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user