Skip to content

Commit

Permalink
[IMP] beesdoo_shift: add name_get on task_template
Browse files Browse the repository at this point in the history
this allow to use generated task template name
and not add all info of the template directly in the name
  • Loading branch information
tfrancoi authored and robinkeunen committed Mar 9, 2022
1 parent fa7306c commit 8cb913d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions polln_shift/models/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@ def subscribe(self):
return res


class TaskTemplate(models.Model):
_inherit = "beesdoo.shift.template"

def name_get(self):
res = []
for rec in self:
name = "%s %s %s (%s-%s)" % (
rec.name,
rec.planning_id.name,
rec.day_nb_id.name,
float_to_time(rec.start_time),
float_to_time(rec.end_time)
)
res.append((rec.id, name))
return res

@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
domain = []
time_domain = []
FIELDS = ['planning_id', 'name', 'day_nb_id']
for n in name.split(" "):
if re.search(r"^\(\d{2}:\d{2}-\d{2}:\d{2}\)$", n):
start, end = n[1:-1].split('-')
start, end = time_to_float(start), time_to_float(end)
time_domain = [['&', ('start_time', '=', start), ('end_time', '=', end)]]
elif n.startswith('('): # Ignore missformed hour
continue
else:
domain.append(expression.OR([[(f, 'ilike', n)] for f in FIELDS]))
return self.search(expression.AND(domain + time_domain)).name_get()


class Task(models.Model):
_inherit = "beesdoo.shift.shift"

Expand Down

0 comments on commit 8cb913d

Please sign in to comment.