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

[ADD] delete_constraint_safely: method to delete constraints #299

Merged

Conversation

MiquelRForgeFlow
Copy link
Contributor

To be used on v14 onward.

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.

Several comments:

  • Isn't the same for previous versions?
  • Can we deduce the constraint name from the field instead of having to put the exact name?

@MiquelRForgeFlow
Copy link
Contributor Author

  • Isn't the same for previous versions?

In v13 and previous versions, the constrains don't have an xmlid. So, to make the method compatible with previous versions, I could do:

if version_info[0] > 13:
    delete_records_safely_by_xml_id(
        env, [module + ".constraint_" + table + "_" + name]
    )

but, is it worth? Previous versions are already done so I think this method won't be used in them.

  • Can we deduce the constraint name from the field instead of having to put the exact name?

No, the 'name' in the ir.model.constraint model is equivalent with what in this method is table + "_" + name. So a 'table' and a 'name' will be introduced as variables one way or the other. My way is a sum and your way would have to do a left trim. Thus, if I have the choice, I prefer the sum. Moreover, my "name" way is straightforward as is the same as it's declared:
Selection_493

@pedrobaeza
Copy link
Member

Ok, please document the arguments in the docstring with these details for future references.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the master-add-delete_constraint_safely branch from ffc140c to dfc16d7 Compare July 20, 2022 09:24
@MiquelRForgeFlow
Copy link
Contributor Author

Ready

@pedrobaeza pedrobaeza merged commit 14ffca6 into OCA:master Jul 20, 2022
@MiquelRForgeFlow MiquelRForgeFlow deleted the master-add-delete_constraint_safely branch July 21, 2022 08:19
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.

3 participants