parent
40ae387f1f
commit
2c99d36869
|
@ -0,0 +1,23 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.exceptions import UserError, UserWarning
|
||||
|
||||
|
||||
class AddUnitLoadError(UserError):
|
||||
pass
|
||||
|
||||
|
||||
class AddUnitLoadWarning(UserWarning):
|
||||
pass
|
||||
|
||||
|
||||
class AddUnitLoadOverloadError(AddUnitLoadError):
|
||||
pass
|
||||
|
||||
|
||||
class AddUnitLoadOriginError(AddUnitLoadError):
|
||||
pass
|
||||
|
||||
|
||||
class AddUnitLoadOriginWarning(AddUnitLoadWarning):
|
||||
pass
|
26
load.py
26
load.py
|
@ -15,6 +15,8 @@ from trytond.wizard import Wizard, StateTransition, StateView, Button, \
|
|||
StateAction
|
||||
from trytond.exceptions import UserError, UserWarning
|
||||
from trytond.i18n import gettext
|
||||
from .exceptions import (AddUnitLoadError, AddUnitLoadWarning,
|
||||
AddUnitLoadOverloadError, AddUnitLoadOriginError, AddUnitLoadOriginWarning)
|
||||
try:
|
||||
import phonenumbers
|
||||
from phonenumbers import PhoneNumberFormat, NumberParseException
|
||||
|
@ -50,6 +52,24 @@ class Load(metaclass=PoolMeta):
|
|||
def search_unit_loads(cls, name, clause):
|
||||
return [('orders.unit_loads', ) + tuple(clause[1:])]
|
||||
|
||||
def add_ul(self, unit_loads, origin_restrict=None,
|
||||
origin_restrict_warn=True, force=False):
|
||||
_error = None
|
||||
for order in self.orders:
|
||||
try:
|
||||
# TODO: managed failed ULs
|
||||
order.add_ul(unit_loads,
|
||||
origin_restrict=origin_restrict,
|
||||
origin_restrict_warn=origin_restrict_warn,
|
||||
force=force)
|
||||
except (AddUnitLoadError, AddUnitLoadWarning) as e:
|
||||
_error = e
|
||||
else:
|
||||
# if works finish method
|
||||
return
|
||||
if _error:
|
||||
raise _error
|
||||
|
||||
@property
|
||||
def ul_quantity(self):
|
||||
return sum(o.ul_quantity for o in self.orders)
|
||||
|
@ -526,7 +546,7 @@ class LoadOrder(metaclass=PoolMeta):
|
|||
# load UL
|
||||
unit_load.load_line = line
|
||||
elif unit_load not in failed_uls:
|
||||
raise UserError(gettext(
|
||||
raise AddUnitLoadOverloadError(gettext(
|
||||
'carrier_load_ul.msg_carrier_load_order_ul_overload',
|
||||
order=self.rec_name))
|
||||
|
||||
|
@ -584,7 +604,7 @@ class LoadOrder(metaclass=PoolMeta):
|
|||
lines.append(line)
|
||||
else:
|
||||
if origin_restrict:
|
||||
raise UserError(gettext(
|
||||
raise AddUnitLoadOriginError(gettext(
|
||||
'carrier_load_ul.msg_carrier_load_order_ul_origin',
|
||||
unit_load=unit_load.rec_name))
|
||||
if origin_restrict_warn:
|
||||
|
@ -593,7 +613,7 @@ class LoadOrder(metaclass=PoolMeta):
|
|||
if warn:
|
||||
warning_name = 'loading_ul_origin_%s' % unit_load.id
|
||||
if Warning.check(warning_name):
|
||||
raise UserWarning(warning_name, gettext(
|
||||
raise AddUnitLoadOriginWarning(warning_name, gettext(
|
||||
'carrier_load_ul.msg_carrier_load_order_ul_origin',
|
||||
unit_load=unit_load.rec_name))
|
||||
return lines
|
||||
|
|
|
@ -246,6 +246,10 @@ Check load order::
|
|||
'Driver'
|
||||
>>> load_order.load.driver_identifier
|
||||
'ID Driver'
|
||||
>>> load_order.origins == ', '.join(l.origin.rec_name for l in load_order.lines)
|
||||
True
|
||||
>>> load.origins == ', '.join(o.origins for o in load.orders)
|
||||
True
|
||||
|
||||
Check sale::
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ Add an invalid UL::
|
|||
>>> start_load.execute('load_')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
trytond.exceptions.UserError: All valid lines of load order "1" are complete. Cannot load more ULs. -
|
||||
trytond.modules.carrier_load_ul.exceptions.AddUnitLoadOverloadError: All valid lines of load order "1" are complete. Cannot load more ULs. -
|
||||
|
||||
Unload UL::
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ Add an invalid UL::
|
|||
>>> start_load.execute('load_')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
trytond.exceptions.UserError: All valid lines of load order "1" are complete. Cannot load more ULs. -
|
||||
trytond.modules.carrier_load_ul.exceptions.AddUnitLoadOverloadError: All valid lines of load order "1" are complete. Cannot load more ULs. -
|
||||
|
||||
Unload UL::
|
||||
|
||||
|
|
Loading…
Reference in New Issue