Skip to content

Conversation

@anthonissen-a
Copy link

Add 2 constraints to limit the range of:

  • auto_renew_interval: to be strictly positive
  • termination_notice_interval: to be positive

@OCA-git-bot
Copy link
Contributor

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

@anthonissen-a anthonissen-a force-pushed the 18.0-product_contract_add_constraints-aan branch 6 times, most recently from cfb98b3 to fe0e004 Compare October 16, 2025 09:36
Copy link
Member

@yvaucher yvaucher left a comment

Choose a reason for hiding this comment

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

Errors that will displayed to the user must be translatable.

ValidationError doesn't handle on itself the translation of the message. You must use env._ or from odoo import _

return
if product.auto_renew_interval <= 0:
raise ValidationError(
f"Value of {product._fields['auto_renew_interval'].string}"
Copy link
Member

Choose a reason for hiding this comment

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

You want to make your error message translatable by wrapping them in env._ .

Be aware that vars included in the string will be evaluated inside the source string to translate.

https://www.odoo.com/documentation/18.0/developer/howtos/translations.html

What you want should be pretty close to this:

https://github.com/odoo/odoo/blob/18.0/addons/web_editor/models/ir_ui_view.py#L84-L88

return
if product.termination_notice_interval < 0:
raise ValidationError(
f"Value of {product._fields['termination_notice_interval'].string}"
Copy link
Member

Choose a reason for hiding this comment

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

To make it translatable.

if not line.is_contract or not line.is_auto_renew:
return
if line.auto_renew_interval <= 0:
raise ValidationError(
Copy link
Member

Choose a reason for hiding this comment

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

This one as translatable too.

@anthonissen-a anthonissen-a force-pushed the 18.0-product_contract_add_constraints-aan branch 2 times, most recently from 08e1205 to 9065320 Compare October 17, 2025 14:41
Copy link
Member

@yvaucher yvaucher left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM

@anthonissen-a anthonissen-a changed the title [IMP] product_contract - add constraints [18.0][IMP] product_contract - add constraints Oct 17, 2025
@anthonissen-a anthonissen-a force-pushed the 18.0-product_contract_add_constraints-aan branch from 9065320 to 2bcf56c Compare October 17, 2025 21:03
@anthonissen-a
Copy link
Author

Also added constraints to limit the range of:

  • recurrence_number: to be strictly positive
  • recurring_interval: to be strictly positive

@anthonissen-a anthonissen-a force-pushed the 18.0-product_contract_add_constraints-aan branch from 2bcf56c to 4e4b846 Compare October 17, 2025 21:08
Copy link
Member

@mamcode mamcode left a comment

Choose a reason for hiding this comment

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

Thanks, these constraints are a very good contribution 👍🏼

@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). 🤖

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.

4 participants