diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..ffc2fcbfd7 --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + The lines "%(line1)s" and "%(line2)s" overlap, you must use different dates. + + + diff --git a/sale.py b/sale.py index 8568842c38..f463997237 100644 --- a/sale.py +++ b/sale.py @@ -2,7 +2,9 @@ # this repository contains the full copyright notices and license terms. from sql import Null +from trytond.i18n import gettext from trytond.model import fields, ModelSQL, ModelView, Workflow +from trytond.model.exceptions import ValidationError from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval, If, Bool from trytond.tools import grouped_slice, reduce_ids @@ -99,12 +101,6 @@ class SubscriptionLine(metaclass=PoolMeta): ] cls.quantity.depends.append('asset_lot') - cls._error_messages.update({ - 'asset_overlapping_dates': ( - 'The lines "%(line1)s" and "%(line2)s" ' - 'for the same lot overlap.'), - }) - @fields.depends('service') def on_change_with_asset_lot_required(self, name=None): if not self.service: @@ -161,7 +157,7 @@ class SubscriptionLine(metaclass=PoolMeta): overlapping = cursor.fetchone() if overlapping: sline1, sline2 = cls.browse(overlapping) - cls.raise_user_error('asset_overlapping_dates', { - 'line1': sline1.rec_name, - 'line2': sline2.rec_name, - }) + raise ValidationError( + gettext('sale_subscription_asset.msg_asset_line_overlap', + line1=sline1.rec_name, + line2=sline2.rec_name)) diff --git a/tests/scenario_sale_subscription_asset.rst b/tests/scenario_sale_subscription_asset.rst index 169c79b9f8..4c9180da7a 100644 --- a/tests/scenario_sale_subscription_asset.rst +++ b/tests/scenario_sale_subscription_asset.rst @@ -104,7 +104,7 @@ Subscribe:: >>> subscription.click('run') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + RequiredValidationError: ... >>> subscription.click('draft') >>> line, = subscription.lines @@ -137,7 +137,7 @@ Creating an overlapping line won't work:: >>> overlapping.save() # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: .... + DomainValidationError: .... Cancelling the subscription will remove lot from the lines thus making it available again:: diff --git a/tryton.cfg b/tryton.cfg index a553667cb3..76b52920e7 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: xml: sale.xml stock.xml + message.xml