changeset 40a6ead117c5 in modules/sale_supply_drop_shipment:default details: https://hg.tryton.org/modules/sale_supply_drop_shipment?cmd=changeset;node=40a6ead117c5 description: Add ir.message and use custom exceptions
issue3672 diffstat: message.xml | 16 ++++++++++++++++ purchase.py | 16 +++++++--------- stock.py | 16 ++++++++-------- tryton.cfg | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) diffs (117 lines): diff -r fa60fcbb921e -r 40a6ead117c5 message.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/message.xml Sat Dec 29 14:20:29 2018 +0100 @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<!-- This file is part of Tryton. The COPYRIGHT file at the top level of +this repository contains the full copyright notices and license terms. --> +<tryton> + <data group="1"> + <record model="ir.message" id="msg_delivery_address_required_quotation_purchase"> + <field name="text">To get a quotation for purchase "%(purchase)s" you must provide a delivery address.</field> + </record> + <record model="ir.message" id="msg_reset_move"> + <field name="text">You cannot reset move "%(move)s" to draft because it was generated by a sale or a purchase.</field> + </record> + <record model="ir.message" id="msg_drop_shipment_delete_cancel"> + <field name="text">To delete drop shipment "%(shipment)s" you must cancel it.</field> + </record> + </data> +</tryton> diff -r fa60fcbb921e -r 40a6ead117c5 purchase.py --- a/purchase.py Sun Nov 18 12:11:19 2018 +0100 +++ b/purchase.py Sat Dec 29 14:20:29 2018 +0100 @@ -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 @@ }, 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 @@ 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 -r fa60fcbb921e -r 40a6ead117c5 stock.py --- a/stock.py Sun Nov 18 12:11:19 2018 +0100 +++ b/stock.py Sat Dec 29 14:20:29 2018 +0100 @@ -8,7 +8,9 @@ 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 @@ '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 @@ 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 @@ 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 -r fa60fcbb921e -r 40a6ead117c5 tryton.cfg --- a/tryton.cfg Sun Nov 18 12:11:19 2018 +0100 +++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100 @@ -12,3 +12,4 @@ stock.xml sale.xml purchase.xml + message.xml