Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to use more explicit names in our loops, such as for template in self: or for shift_template in self:. Don't you use that at Odoo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you use that at Odoo ?
There is no specific guidelines for that in odoo (you can grep for rec in self, for record in self)
Personnaly when the record come from a search it makes sense to specify the object
when they come from self, you already know in which model you are, it's less important

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide an example(s) of matched pattern for readability ?
Also, nitpicking, shouldn't you compile the pattern out of the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide an example(s) of matched pattern for readability ?
Yes we are looking for the time (generated by the name get) for example 12:30-15h30

Also, nitpicking, shouldn't you compile the pattern out of the loop?
From the perf point of view the number of iteration depends on the number of token in the search term so between 1 and 4. I don't think it really matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks!

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