[IMP]GOLEM Resource : computes day and hour start for better model sorting
This commit is contained in:
parent
ff70e46612
commit
d5cc394967
@ -29,7 +29,7 @@ class GolemResourceReservation(models.Model):
|
|||||||
_name = 'golem.resource.reservation'
|
_name = 'golem.resource.reservation'
|
||||||
_description = 'GOLEM Reservation Model'
|
_description = 'GOLEM Reservation Model'
|
||||||
_inherit = 'mail.thread'
|
_inherit = 'mail.thread'
|
||||||
_order = 'date_start desc'
|
_order = 'day_start desc, hour_start asc'
|
||||||
|
|
||||||
name = fields.Char(compute='_compute_name', store=True)
|
name = fields.Char(compute='_compute_name', store=True)
|
||||||
# TODO: handle multiple days reservation
|
# TODO: handle multiple days reservation
|
||||||
@ -39,6 +39,8 @@ class GolemResourceReservation(models.Model):
|
|||||||
date_stop = fields.Datetime('Stop date', required=True,
|
date_stop = fields.Datetime('Stop date', required=True,
|
||||||
index=True, readonly=True,
|
index=True, readonly=True,
|
||||||
states={'draft': [('readonly', False)]})
|
states={'draft': [('readonly', False)]})
|
||||||
|
day_start = fields.Date(compute='_compute_day_hour_start', store=True)
|
||||||
|
hour_start = fields.Float(compute='_compute_day_hour_start', store=True)
|
||||||
resource_id = fields.Many2one('golem.resource', required=True, index=True,
|
resource_id = fields.Many2one('golem.resource', required=True, index=True,
|
||||||
string='Resource', readonly=True,
|
string='Resource', readonly=True,
|
||||||
track_visibility='onchange',
|
track_visibility='onchange',
|
||||||
@ -73,6 +75,15 @@ class GolemResourceReservation(models.Model):
|
|||||||
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
||||||
reservation.date_start)
|
reservation.date_start)
|
||||||
|
|
||||||
|
@api.depends('date_start')
|
||||||
|
def _compute_day_hour_start(self):
|
||||||
|
""" Computes Day and Hour Start : for better sorting """
|
||||||
|
for reservation in self:
|
||||||
|
if reservation.date_start:
|
||||||
|
date_start = fields.Datetime.from_string(reservation.date_start)
|
||||||
|
reservation.day_start = date_start.date().isoformat()
|
||||||
|
reservation.hour_start = date_start.hour + date_start.minute / 60.0
|
||||||
|
|
||||||
@api.onchange('date_start')
|
@api.onchange('date_start')
|
||||||
def onchange_date_start(self):
|
def onchange_date_start(self):
|
||||||
""" Propose automatically stop hour after start hour had been filled """
|
""" Propose automatically stop hour after start hour had been filled """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user