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

[15.0][OU-ADD] commission: Migration scripts #426

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

chienandalu
Copy link
Member

@chienandalu chienandalu commented May 18, 2023

cc @Tecnativa TT43411

@OCA-git-bot
Copy link
Contributor

Hi @pedrobaeza,
some modules you are maintaining are being modified, check this out!

@pedrobaeza
Copy link
Member

This should be tagged as [OU-ADD], not [IMP].

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

The rest is OK and no more changes detected by my side.

@pedrobaeza pedrobaeza added this to the 15.0 milestone May 18, 2023
@chienandalu
Copy link
Member Author

@pedrobaeza
Copy link
Member

It's a one2many, so no schema changed. You can call though to rename_fields for benefiting of the future feature of changing domains in filters and exports.

@chienandalu chienandalu force-pushed the 15.0-imp-commission-migration-scripts branch from ddd349e to e29bfa6 Compare May 19, 2023 07:26
@chienandalu
Copy link
Member Author

It's a one2many, so no schema changed. You can call though to rename_fields for benefiting of the future feature of changing domains in filters and exports.

But it was a m2m before

@pedrobaeza
Copy link
Member

OK, then you must convert the other part of the inverse name. Or is it already there in previous version?

@pedrobaeza pedrobaeza mentioned this pull request May 23, 2023
5 tasks
@hildickethan
Copy link
Member

OK, then you must convert the other part of the inverse name. Or is it already there in previous version?

It isn't there in the previous version, but it seems a bit complicated logistically to not either lose data or break it.
If we add extra settlement lines so all the agent lines keep their link, it adds incorrect data to the settlement. I think we just take the first agent line per settlement line to migrate it

env.cr.execute("""
SELECT DISTINCT ON (agent_line_id), settlement_id
FROM settlement_agent_line_rel
ORDER BY agent_line_id
""")
for agent_line_id, settlement_id in env.cr.fetchall():
    env["commission.settlement.line"].browse(settlement_id).invoice_agent_line_id = agent_line_id

This should work, but I don't have a db to migrate to test it atm

@chienandalu chienandalu force-pushed the 15.0-imp-commission-migration-scripts branch from e29bfa6 to 6897b81 Compare July 4, 2023 14:41
@chienandalu chienandalu changed the title [15.0][IMP] commission: Migration scripts [15.0][OU-ADD] commission: Migration scripts Jul 4, 2023
@chienandalu chienandalu marked this pull request as ready for review July 4, 2023 14:53
@chienandalu
Copy link
Member Author

hildickethan-S73

Thanks. Take a look on post-migration for a performant version of your proposal :)

@hildickethan
Copy link
Member

Looks good! Looking to try it out soon but I was thinking, wouldn't these scripts need to be in hooks rather than migration scripts?

For instance a new database that is migrating from 14 to 15 I imagine gets to the point where it updates sale_commission, sees that theres a new commission dependency, which is when we need to adapt the data before it creates all the tables and models messing up the rename methods

I think it should be a hooks with a table_exists before it, since I'm not sure how the method acts when it doesn't exist but I assume it errors

@pedrobaeza
Copy link
Member

OpenUpgrade runs the migration scripts also for newly installed modules. Hooks are designed for other purposes and can't have things like version discrimination.

@hildickethan
Copy link
Member

OpenUpgrade runs the migration scripts also for newly installed modules. Hooks are designed for other purposes and can't have things like version discrimination.

Ah I didn't know OU did some magic there, I was thinking of normal upgrading. No problem then
Our real migration test will be some time next week, but it LGTM!

@chienandalu
Copy link
Member Author

I just run it in a customer test migrations and it looks good :)

@pedrobaeza pedrobaeza force-pushed the 15.0-imp-commission-migration-scripts branch from 6897b81 to 2619d22 Compare August 10, 2023 10:26
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

I have added a missing piece for the computed stored commission_id field in commission.settlement.line.

Copy link
Member

@hildickethan hildickethan left a comment

Choose a reason for hiding this comment

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

Worked for us too

@pedrobaeza pedrobaeza merged commit 74d1760 into OCA:15.0 Aug 10, 2023
6 checks passed
@pedrobaeza pedrobaeza deleted the 15.0-imp-commission-migration-scripts branch August 10, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants