Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
c790dfed2e
commit
8a40432043
4 files changed
+32
-17
No files matched your search
+16
@@ -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>
|
||||
+7
-9
@@ -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()
|
||||
|
||||
@@ -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'])
|
||||
|
||||
|
||||
@@ -12,3 +12,4 @@ xml:
|
||||
stock.xml
|
||||
sale.xml
|
||||
purchase.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user