Skip to content

Commit 01974fb

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 0837010 commit 01974fb

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
@@ -41,6 +41,39 @@ def subscribe(self):
4141
return res
4242

4343

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

0 commit comments

Comments
 (0)