-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MIG] event_session_registration_multi_qty: Migration to 14.0 #267
[MIG] event_session_registration_multi_qty: Migration to 14.0 #267
Conversation
/ocabot migration event_session_registration_multi_qty Please rebase |
54b45d6
to
ee3cd91
Compare
Rebased |
for session in self: | ||
if not session.event_id.registration_multi_qty: | ||
return super()._compute_seats() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for session in self: | |
if not session.event_id.registration_multi_qty: | |
return super()._compute_seats() | |
records = self.filtered("event_id.registration_multi_qty") | |
super(EventSession, self - records)._compute_seats() | |
for session in records: |
Better to call super outside of the loop, otherwise you loose all the recordset optimizations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ivantodorovich I'll try to get some time and check your comments :)
} | ||
registrations = self.env["event.registration"].read_group( | ||
[ | ||
("session_id", "=", session.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to do this from outside the loop, to reduce the number of queries to compute this thing.
Otherwise you run a query per record, that's not efficient.
You probably need to use raw sql to achieve it, like it's done in the original method
Somthing like this perhaps
state_field = {
'draft': 'seats_unconfirmed',
'open': 'seats_reserved',
'done': 'seats_used',
}
if self.ids:
query = """
SELECT session_id, state, sum(qty)
FROM event_registration
WHERE session_id IN %s
AND state IN ('draft', 'open', 'done')
GROUP BY session_id, state
"""
self.env['event.registration'].flush(['session_id', 'state', 'qty'])
self.env.cr.execute(query, (tuple(self.ids),))
res = self.env.cr.fetchall()
for session_id, state, qty in res:
results[session_id][state_field[state]] = num
This PR has the |
/ocabot merge nobump |
This PR looks fantastic, let's merge it! |
Oh, sorry, I didn't see the last comment. The improvement can go in a new PR though. |
Congratulations, your PR was merged at c3deb17. Thanks a lot for contributing to OCA. ❤️ |
Standard migration.
Depending on:
cc @Tecnativa TT34352
please review @ernestotejeda @pedrobaeza