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

[18.0][MIG] partner_vat_unique: Migration to 18.0 #1906

Open
wants to merge 48 commits into
base: 18.0
Choose a base branch
from

Conversation

lef-adhoc
Copy link

No description provided.

Ismael Calvo and others added 30 commits November 28, 2024 15:55
Currently translated at 100.0% (2 of 2 strings)

Translation: partner-contact-12.0/partner-contact-12.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_vat_unique/es/
Currently translated at 100.0% (2 of 2 strings)

Translation: partner-contact-12.0/partner-contact-12.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_vat_unique/it/
Currently translated at 100.0% (2 of 2 strings)

Translation: partner-contact-12.0/partner-contact-12.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_vat_unique/pt/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: partner-contact-13.0/partner-contact-13.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-partner_vat_unique/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-14.0/partner-contact-14.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-14-0/partner-contact-14-0-partner_vat_unique/es/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/de/
weblate and others added 15 commits November 28, 2024 15:55
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/hr/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/es/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/pt/
Currently translated at 100.0% (4 of 4 strings)

Translation: partner-contact-16.0/partner-contact-16.0-partner_vat_unique
Translate-URL: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_vat_unique/it/
@lef-adhoc lef-adhoc changed the title 18.0 mig partner vat unique [18.0][MIG] partner_vat_unique: Migration to 18.0 Nov 28, 2024
@lef-adhoc lef-adhoc mentioned this pull request Nov 28, 2024
46 tasks
@rousseldenis
Copy link
Contributor

/ocabot migration partner_vat_unique

@@ -24,5 +24,6 @@ def _check_vat_unique(self):
continue
if record.same_vat_partner_id:
raise ValidationError(
_("The VAT %s already exists in another partner.") % record.vat
self.env._("The VAT %s already exists in another partner.")
Copy link
Contributor

Choose a reason for hiding this comment

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

@lef-adhoc Please use translation function arguments instead.

self.env._("The VAT %(vat)s already exists in another partner.", vat=record.vat)

Copy link
Author

Choose a reason for hiding this comment

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

Done!

for record in self:
if record.parent_id or not record.vat:
continue
test_condition = config["test_enable"] and not self.env.context.get(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not really good practice. Instead, a configuration parameter is better to enable the constraint.

Copy link
Author

@lef-adhoc lef-adhoc Nov 29, 2024

Choose a reason for hiding this comment

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

Thanks for the feedback! Do you have an example of how to properly implement this with a configuration parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

In ResConfigSettings model:

partner_vat_unique = fields.Boolean(
    config_parameter="partner_vat_unique.partner_vat_unique',
    help="Check this if you want to constrain VAT number to be unique"
)

Then, here, before the loop:

if  self.env["ir.config_parameter"]
            .sudo()
            .get_param("partner_vat_unique.partner_vat_unique', False):

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, remove all things about test_enable.

And adapt tests accordingly.

Then, put that in a separate commit.

Copy link
Author

Choose a reason for hiding this comment

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

I’ve added a commit implementing the configuration parameter for the unique VAT constraint as you suggested. Could you please take a look and let me know if this approach works for you?

@lef-adhoc lef-adhoc force-pushed the 18.0-mig-partner_vat_unique branch from 19a7fff to 422297f Compare November 29, 2024 11:13
@lef-adhoc lef-adhoc force-pushed the 18.0-mig-partner_vat_unique branch 2 times, most recently from 1fce377 to 3dcfa24 Compare November 29, 2024 14:58
"test_vat"
)
if test_condition:
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Put it outside the loop. If deactivated, don't enter in it at all.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

…constraint

- Defined `partner_vat_unique` as a boolean configuration parameter.
- Updated `res.partner` to validate VAT uniqueness based on this parameter.
- Added a new section in ResConfigSettings for enabling/disabling the constraint.
- Updated tests to include scenarios with the configuration parameter.
@lef-adhoc lef-adhoc force-pushed the 18.0-mig-partner_vat_unique branch from 3dcfa24 to 1a7c237 Compare November 29, 2024 15:36
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.