Skip to content
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

Merged

Conversation

chienandalu
Copy link
Member

@chienandalu chienandalu commented Mar 24, 2022

@pedrobaeza pedrobaeza added this to the 14.0 milestone Mar 26, 2022
@pedrobaeza
Copy link
Member

/ocabot migration event_session_registration_multi_qty

Please rebase

@OCA-git-bot OCA-git-bot mentioned this pull request Mar 26, 2022
13 tasks
@chienandalu chienandalu force-pushed the 14.0-mig-event_session_registration_multi_qty branch from 54b45d6 to ee3cd91 Compare March 28, 2022 08:10
@chienandalu
Copy link
Member Author

Rebased

Comment on lines +11 to +13
for session in self:
if not session.event_id.registration_multi_qty:
return super()._compute_seats()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member Author

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),
Copy link
Contributor

@ivantodorovich ivantodorovich Apr 12, 2022

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

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza
Copy link
Member

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 14.0-ocabot-merge-pr-267-by-pedrobaeza-bump-nobump, awaiting test results.

@pedrobaeza
Copy link
Member

Oh, sorry, I didn't see the last comment. The improvement can go in a new PR though.

@OCA-git-bot OCA-git-bot merged commit 675819d into OCA:14.0 Apr 25, 2022
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at c3deb17. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants