diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..1a1751f5ae --- /dev/null +++ b/exceptions.py @@ -0,0 +1,12 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +from trytond.model.exceptions import ValidationError, AccessError + + +class FormulaError(ValidationError): + pass + + +class ShippingBlocked(AccessError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..fede7c28e1 --- /dev/null +++ b/message.xml @@ -0,0 +1,13 @@ + + + + + + Invalid formula "%(formula)s" in term line "%(term_line)s" with exception "%(exception)s". + + + To pack shipments the customer must paid the advance payment for sale "%(sale)s". + + + diff --git a/sale.py b/sale.py index 9bcf6ccc14..66eb0e0f52 100644 --- a/sale.py +++ b/sale.py @@ -4,6 +4,7 @@ from decimal import Decimal from simpleeval import simple_eval from itertools import chain +from trytond.i18n import gettext from trytond.pool import Pool, PoolMeta from trytond.model import ( ModelSQL, ModelView, Workflow, DeactivableMixin, fields) @@ -12,6 +13,8 @@ from trytond.tools import decistmt from trytond.transaction import Transaction from trytond.modules.company.model import CompanyMultiValueMixin, CompanyValueMixin +from .exceptions import FormulaError + __all__ = [ 'AdvancePaymentTerm', 'AdvancePaymentTermLine', 'AdvancePaymentTermLineAccount', @@ -80,14 +83,6 @@ class AdvancePaymentTermLine(ModelView, ModelSQL, CompanyMultiValueMixin): "- total_amount: The total amount of the sale.\n" "- untaxed_amount: The total untaxed amount of the sale.") - @classmethod - def __setup__(cls): - super(AdvancePaymentTermLine, cls).__setup__() - cls._error_messages.update({ - 'invalid_formula': ('Invalid formula "%(formula)s" with' - ' exception "%(exception)s".'), - }) - @fields.depends('formula') def pre_validate(self, **names): super(AdvancePaymentTermLine, self).pre_validate() @@ -96,10 +91,11 @@ class AdvancePaymentTermLine(ModelView, ModelSQL, CompanyMultiValueMixin): if not isinstance(self.compute_amount(**names), Decimal): raise Exception('The formula does not return a Decimal') except Exception as exception: - self.raise_user_error('invalid_formula', { - 'formula': self.formula, - 'exception': exception, - }) + raise FormulaError( + gettext('sale_advance_payment.msg_term_line_invalid_formula', + formula=self.formula, + term_line=self.rec_name, + exception=exception)) from exception def get_compute_amount_context(self, **names): return { diff --git a/stock.py b/stock.py index aff4eb79cd..b35483e927 100644 --- a/stock.py +++ b/stock.py @@ -1,24 +1,18 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from trytond.i18n import gettext from trytond.model import ModelView, Workflow from trytond.pool import Pool, PoolMeta +from .exceptions import ShippingBlocked + __all__ = ['ShipmentOut'] class ShipmentOut(metaclass=PoolMeta): __name__ = 'stock.shipment.out' - @classmethod - def __setup__(cls): - super(ShipmentOut, cls).__setup__() - cls._error_messages.update({ - 'advance_payment_not_paid': ('The customer has not paid the' - ' required advance payment amount for the sale' - ' "%(sale)s".'), - }) - @classmethod @ModelView.button @Workflow.transition('packed') @@ -32,7 +26,7 @@ class ShipmentOut(metaclass=PoolMeta): if isinstance(move.origin, SaleLine)} for sale in Sale.browse([s.id for s in sales]): if sale.shipping_blocked: - cls.raise_user_error('advance_payment_not_paid', { - 'sale': sale.rec_name, - }) + raise ShippingBlocked( + gettext('sale_advance_payment.msg_shipping_blocked', + sale=sale.rec_name)) super(ShipmentOut, cls).pack(shipments) diff --git a/tests/scenario_advance_payment.rst b/tests/scenario_advance_payment.rst index 5b53107bab..65006bc0ec 100644 --- a/tests/scenario_advance_payment.rst +++ b/tests/scenario_advance_payment.rst @@ -252,7 +252,7 @@ Let's try to pack it:: >>> shipment.click('pack') # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ... + ShippingBlocked: ... Let's pay the advance payment invoice:: diff --git a/tryton.cfg b/tryton.cfg index 2558bfb48b..236a51c82a 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -9,3 +9,4 @@ extras_depend: sale_supply xml: sale.xml + message.xml