[IMP] attendance_ids at default value
This commit is contained in:
@@ -11,29 +11,64 @@ class ResourceCalendar(models.Model):
|
|||||||
|
|
||||||
name = fields.Char(compute='_compute_name', store=True)
|
name = fields.Char(compute='_compute_name', store=True)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
"'attendance_ids' field default value"
|
||||||
|
values = super(ResourceCalendar, self).default_get(fields_list)
|
||||||
|
vals = []
|
||||||
|
params = self.get_my_calendar_data()
|
||||||
|
for hours in range(0, params.endday):
|
||||||
|
mapping = self._populate_attendance(
|
||||||
|
hours, params.hour_from, params.hour_to)
|
||||||
|
vals.append((0, 0, mapping))
|
||||||
|
if params.hour_from2 and params.hour_to2:
|
||||||
|
mapping = self._populate_attendance(
|
||||||
|
hours, params.hour_from2, params.hour_to2)
|
||||||
|
vals.append((0, 0, mapping))
|
||||||
|
values['attendance_ids'] = vals
|
||||||
|
return values
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('attendance_ids')
|
@api.depends('attendance_ids')
|
||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.attendance_ids:
|
if rec.attendance_ids:
|
||||||
info = []
|
info = []
|
||||||
for day in rec.attendance_ids:
|
dayofweek = ''
|
||||||
selection = day._fields['dayofweek'].selection
|
for hours in rec.attendance_ids:
|
||||||
string_day = self.map_day()[
|
if hours.dayofweek != dayofweek:
|
||||||
selection[int(day.dayofweek)][1]]
|
selection = hours._fields['dayofweek'].selection
|
||||||
|
str_day = self.map_day()[
|
||||||
|
selection[int(hours.dayofweek)][1]]
|
||||||
info.append(
|
info.append(
|
||||||
'%s %s/%s'
|
self.string_format(main_string=True) % (
|
||||||
% (string_day, int(day.hour_from), int(day.hour_to)))
|
str_day, int(hours.hour_from),
|
||||||
rec.name = ', '.join(info) or '_'
|
int(hours.hour_to)))
|
||||||
else:
|
else:
|
||||||
rec.name = '_'
|
# We are on the same day but with another hour range
|
||||||
|
# we concatenate on the first string of the day
|
||||||
|
position = info.index(info[-1:][0])
|
||||||
|
info[position] = self.string_format() % (
|
||||||
|
info[-1:][0], int(hours.hour_from),
|
||||||
|
int(hours.hour_to))
|
||||||
|
dayofweek = hours.dayofweek
|
||||||
|
rec.name = ', '.join(info)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def string_format(self, main_string=None):
|
||||||
|
'Override me to customize calendar name'
|
||||||
|
if main_string:
|
||||||
|
# ie: 'Lu 8-12'
|
||||||
|
return '%s %s-%s'
|
||||||
|
# ie: 'Lu 8-12 and 13-17'
|
||||||
|
return '%s / %s-%s'
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def map_day(self):
|
def map_day(self):
|
||||||
'Override me to customize calendar name'
|
'Override me to customize calendar name'
|
||||||
return {'Monday': 'L', 'Tuesday': 'Ma', 'Wednesday': 'Me',
|
return {'Monday': 'Lu', 'Tuesday': 'Ma', 'Wednesday': 'Me',
|
||||||
'Thursday': 'J', 'Friday': 'V', 'Saturday': 'S',
|
'Thursday': 'Je', 'Friday': 'Ve', 'Saturday': 'Sa',
|
||||||
'Sunday': 'D'}
|
'Sunday': 'Di'}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_my_calendar_data(self):
|
def get_my_calendar_data(self):
|
||||||
@@ -50,26 +85,10 @@ class ResourceCalendar(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _populate_attendance(self, day, hour_from, hour_to):
|
def _populate_attendance(self, hours, hour_from, hour_to):
|
||||||
return {
|
return {
|
||||||
'hour_from': hour_from,
|
'hour_from': hour_from,
|
||||||
'hour_to': hour_to,
|
'hour_to': hour_to,
|
||||||
'name': '.',
|
'name': '.',
|
||||||
'dayofweek': str(day),
|
'dayofweek': str(hours),
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
|
||||||
def create(self, vals):
|
|
||||||
if not vals.get('attendance_ids'):
|
|
||||||
values = []
|
|
||||||
params = self.get_my_calendar_data()
|
|
||||||
for day in range(0, params.endday):
|
|
||||||
mapping = self._populate_attendance(
|
|
||||||
day, params.hour_from, params.hour_to)
|
|
||||||
values.append((0, 0, mapping))
|
|
||||||
if params.hour_from2 and params.hour_to2:
|
|
||||||
mapping = self._populate_attendance(
|
|
||||||
day, params.hour_from2, params.hour_to2)
|
|
||||||
values.append((0, 0, mapping))
|
|
||||||
vals['attendance_ids'] = values
|
|
||||||
return super(ResourceCalendar, self).create(vals)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user