From 8a4043204341ba0015b71e665503ee72c99f60f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Dec 2018 14:20:29 +0100 Subject: [PATCH] Add ir.message and use custom exceptions issue3672 --- message.xml | 16 ++++++++++++++++ purchase.py | 16 +++++++--------- stock.py | 16 ++++++++-------- tryton.cfg | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 message.xml diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..ab9f105e91 --- /dev/null +++ b/message.xml @@ -0,0 +1,16 @@ + + + + + + To get a quotation for purchase "%(purchase)s" you must provide a delivery address. + + + You cannot reset move "%(move)s" to draft because it was generated by a sale or a purchase. + + + To delete drop shipment "%(shipment)s" you must cancel it. + + + diff --git a/purchase.py b/purchase.py index 8f5226c5d0..cc44aab973 100644 --- a/purchase.py +++ b/purchase.py @@ -3,7 +3,9 @@ from decimal import Decimal from trytond import backend +from trytond.i18n import gettext from trytond.model import ModelSQL, ValueMixin, fields +from trytond.model.exceptions import RequiredValidationError from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction @@ -111,14 +113,6 @@ class Purchase(metaclass=PoolMeta): }, depends=['customer']) - @classmethod - def __setup__(cls): - super(Purchase, cls).__setup__() - cls._error_messages.update({ - 'delivery_address_required': ('A delivery address must be ' - 'defined for quotation of purchase "%s".'), - }) - @staticmethod def default_drop_location(): pool = Pool() @@ -147,7 +141,11 @@ class Purchase(metaclass=PoolMeta): def check_for_quotation(self): super(Purchase, self).check_for_quotation() if self.customer and not self.delivery_address: - self.raise_user_error('delivery_address_required', self.rec_name) + raise RequiredValidationError( + gettext('sale_supply_drop_shipment' + '.msg_delivery_address_required_quotation_purchase') % { + 'purchase': self.rec_name, + }) def create_move(self, move_type): pool = Pool() diff --git a/stock.py b/stock.py index a54bf2e662..26944f748a 100644 --- a/stock.py +++ b/stock.py @@ -8,7 +8,9 @@ from sql.operators import Concat from sql.aggregate import Count from trytond import backend +from trytond.i18n import gettext from trytond.model import Workflow, ModelView, ModelSQL, fields +from trytond.model.exceptions import AccessError from trytond.pyson import Eval, If from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction @@ -277,12 +279,6 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): 'depends': ['state'], }, }) - cls._error_messages.update({ - 'reset_move': ('You cannot reset to draft move "%s" which was ' - 'generated by a sale or a purchase.'), - 'delete_cancel': ('Drop Shipment "%(shipment)s" must be ' - 'cancelled before deletion.'), - }) @staticmethod def default_state(): @@ -364,7 +360,9 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): cls.cancel(shipments) for shipment in shipments: if shipment.state != 'cancel': - cls.raise_user_error('delete_cancel', { + raise AccessError( + gettext('sale_supply_drop_shipment' + '.msg_drop_shipment_delete_cancel') % { 'shipment': shipment.rec_name, }) Move.delete([m for s in shipments for m in s.supplier_moves]) @@ -395,7 +393,9 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): for move in shipment.moves: if (move.state == 'cancel' and isinstance(move.origin, (PurchaseLine, SaleLine))): - cls.raise_user_error('reset_move', (move.rec_name,)) + raise AccessError( + gettext('sale_supply_drop_shipment.msg_reset_move', + move=move.rec_name)) Move.draft([m for s in shipments for m in s.moves if m.state != 'staging']) diff --git a/tryton.cfg b/tryton.cfg index 58b9a64ef9..83547f79b1 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -12,3 +12,4 @@ xml: stock.xml sale.xml purchase.xml + message.xml