changeset 1fb939a35728 in modules/sale_shipment_tolerance:default
details:
https://hg.tryton.org/modules/sale_shipment_tolerance?cmd=changeset;node=1fb939a35728
description:
Add ir.message and use custom exceptions
issue3672
diffstat:
exceptions.py | 8 ++++++++
message.xml | 10 ++++++++++
sale.py | 21 ++++++++++-----------
tests/scenario_sale_over_shipment_tolerance.rst | 2 +-
tryton.cfg | 1 +
5 files changed, 30 insertions(+), 12 deletions(-)
diffs (95 lines):
diff -r 924e3b74b065 -r 1fb939a35728 exceptions.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py Sat Dec 29 14:20:29 2018 +0100
@@ -0,0 +1,8 @@
+# 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.exceptions import UserWarning
+
+
+class OverShipmentWarning(UserWarning):
+ pass
diff -r 924e3b74b065 -r 1fb939a35728 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,10 @@
+<?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_over_shipment">
+ <field name="text">The sale line "%(line)s" exceeds the over
shipment tolerance.</field>
+ </record>
+ </data>
+</tryton>
diff -r 924e3b74b065 -r 1fb939a35728 sale.py
--- a/sale.py Mon Oct 01 13:34:06 2018 +0200
+++ b/sale.py Sat Dec 29 14:20:29 2018 +0100
@@ -1,21 +1,16 @@
# 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.pool import PoolMeta, Pool
+from .exceptions import OverShipmentWarning
+
__all__ = ['SaleLine']
class SaleLine(metaclass=PoolMeta):
__name__ = 'sale.line'
- @classmethod
- def __setup__(cls):
- super(SaleLine, cls).__setup__()
- cls._error_messages.update({
- 'over_shipment': (
- 'The Sale Line "%s" exceed the over shipment tolerance.'),
- })
-
def _test_under_shipment_tolerance(self, quantity):
pool = Pool()
Configuration = pool.get('sale.configuration')
@@ -50,6 +45,7 @@
def check_over_shipment(self):
pool = Pool()
Configuration = pool.get('sale.configuration')
+ Warning = pool.get('res.user.warning')
config = Configuration(1)
if self.quantity >= 0:
@@ -61,6 +57,9 @@
if tolerance is not None:
maximal_quantity = abs(self.quantity * tolerance)
if shipped_quantity > maximal_quantity:
- self.raise_user_warning(
- 'over_shipment_sale_line_%d' % self.id,
- 'over_shipment', self.rec_name)
+ name = 'over_shipment_sale_line_%d' % self.id
+ if Warning.check(name):
+ raise OverShipmentWarning(
+ name,
+ gettext('sale_shipment_tolerance.msg_over_shipment',
+ line=self.rec_name))
diff -r 924e3b74b065 -r 1fb939a35728
tests/scenario_sale_over_shipment_tolerance.rst
--- a/tests/scenario_sale_over_shipment_tolerance.rst Mon Oct 01 13:34:06
2018 +0200
+++ b/tests/scenario_sale_over_shipment_tolerance.rst Sat Dec 29 14:20:29
2018 +0100
@@ -86,7 +86,7 @@
>>> shipment.click('pack') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
- UserWarning: ...
+ OverShipmentWarning: ...
Over ship 12 products::
diff -r 924e3b74b065 -r 1fb939a35728 tryton.cfg
--- a/tryton.cfg Mon Oct 01 13:34:06 2018 +0200
+++ b/tryton.cfg Sat Dec 29 14:20:29 2018 +0100
@@ -6,3 +6,4 @@
stock
xml:
configuration.xml
+ message.xml