Skip to content

Commit d18b0bd

Browse files
committed
[IMP] beesdoo_shift: add name_get on task_template
this allow to use generated task template name and not add all info of the template directly in the name
1 parent a4ee9c7 commit d18b0bd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

polln_shift/models/planning.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,39 @@ def subscribe(self):
3737
return res
3838

3939

40+
class TaskTemplate(models.Model):
41+
_inherit = "beesdoo.shift.template"
42+
43+
def name_get(self):
44+
res = []
45+
for rec in self:
46+
name = "%s %s %s (%s-%s)" % (
47+
rec.name,
48+
rec.planning_id.name,
49+
rec.day_nb_id.name,
50+
float_to_time(rec.start_time),
51+
float_to_time(rec.end_time)
52+
)
53+
res.append((rec.id, name))
54+
return res
55+
56+
@api.model
57+
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
58+
domain = []
59+
time_domain = []
60+
FIELDS = ['planning_id', 'name', 'day_nb_id']
61+
for n in name.split(" "):
62+
if re.search(r"^\(\d{2}:\d{2}-\d{2}:\d{2}\)$", n):
63+
start, end = n[1:-1].split('-')
64+
start, end = time_to_float(start), time_to_float(end)
65+
time_domain = [['&', ('start_time', '=', start), ('end_time', '=', end)]]
66+
elif n.startswith('('): # Ignore missformed hour
67+
continue
68+
else:
69+
domain.append(expression.OR([[(f, 'ilike', n)] for f in FIELDS]))
70+
return self.search(expression.AND(domain + time_domain)).name_get()
71+
72+
4073
class Task(models.Model):
4174
_inherit = 'beesdoo.shift.shift'
4275

0 commit comments

Comments
 (0)