Improve loading wizard methods
This commit is contained in:
parent
d8de567099
commit
77ed05b83f
71
load.py
71
load.py
|
@ -2,14 +2,15 @@
|
|||
# this repository contains the full copyright notices and license terms.
|
||||
from functools import partial
|
||||
from itertools import groupby
|
||||
|
||||
from decimal import Decimal
|
||||
from trytond.rpc import RPC
|
||||
from trytond.model import fields, ModelView, Workflow, Model
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval, Bool, Not
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Wizard, StateTransition, StateView, Button
|
||||
|
||||
|
||||
__all__ = ['Configuration', 'Load', 'LoadOrder', 'LoadOrderLine',
|
||||
'LoadUnitLoad', 'LoadUnitLoadOrder', 'LoadUnitLoadData',
|
||||
'LoadSheet', 'CMR', 'RoadTransportNote', 'EditLoadOrderLine',
|
||||
|
@ -332,10 +333,13 @@ class LoadOrder:
|
|||
def run_try(cls, records):
|
||||
pass
|
||||
|
||||
def add_ul(self, unit_loads):
|
||||
def add_ul(self, unit_loads, origin_restrict=None, origin_restrict_warn=True):
|
||||
pool = Pool()
|
||||
UL = pool.get('stock.unit_load')
|
||||
|
||||
if origin_restrict is None:
|
||||
origin_restrict = self.ul_origin_restrict
|
||||
|
||||
order_lines = {}
|
||||
for unit_load in unit_loads:
|
||||
# check state
|
||||
|
@ -363,10 +367,11 @@ class LoadOrder:
|
|||
and unit_load in l.origin.unit_loads]
|
||||
if not lines:
|
||||
if all(l.origin for l in self.lines):
|
||||
if self.ul_origin_restrict:
|
||||
if origin_restrict:
|
||||
self.raise_user_error('ul_origin', unit_load.rec_name)
|
||||
self.raise_user_warning('loading_ul_origin_%s' % unit_load.id,
|
||||
'ul_origin', unit_load.rec_name)
|
||||
if origin_restrict_warn:
|
||||
self.raise_user_warning('loading_ul_origin_%s' %
|
||||
unit_load.id, 'ul_origin', unit_load.rec_name)
|
||||
lines = self.lines
|
||||
|
||||
# check data matches
|
||||
|
@ -496,6 +501,10 @@ class LoadUnitLoad(Wizard):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(LoadUnitLoad, cls).__setup__()
|
||||
cls.__rpc__.update({
|
||||
'load': RPC(readonly=False),
|
||||
'unload': RPC(readonly=False),
|
||||
})
|
||||
cls._error_messages.update({
|
||||
'invalid_ul': 'Cannot find Unit load "%s".',
|
||||
'ul_required': 'Must define an UL to load.',
|
||||
|
@ -524,26 +533,33 @@ class LoadUnitLoad(Wizard):
|
|||
res['loaded_uls'] = len(order.unit_loads)
|
||||
return res
|
||||
|
||||
def transition_load_(self):
|
||||
@classmethod
|
||||
def load(cls, order_id, ul_code, uls=[], origin_restrict=True,
|
||||
origin_restrict_warn=True):
|
||||
pool = Pool()
|
||||
Order = pool.get('carrier.load.order')
|
||||
UL = pool.get('stock.unit_load')
|
||||
|
||||
if not self.data.ul_code and not self.data.uls_to_load:
|
||||
self.raise_user_error('ul_required')
|
||||
|
||||
order, _ = self._get_load_order()
|
||||
uls = []
|
||||
if self.data.ul_code:
|
||||
ul = UL.search([('code', '=', self.data.ul_code)])
|
||||
if not ul_code and not uls:
|
||||
cls.raise_user_error('ul_required')
|
||||
if isinstance(order_id, int):
|
||||
order = Order(order_id)
|
||||
else:
|
||||
order = order_id
|
||||
if ul_code:
|
||||
ul = UL.search([('code', '=', ul_code)])
|
||||
if not ul:
|
||||
self.raise_user_error('invalid_ul', self.data.ul_code)
|
||||
cls.raise_user_error('invalid_ul', ul_code)
|
||||
uls.append(ul[0])
|
||||
if self.data.uls_to_load:
|
||||
uls.extend(self.data.uls_to_load)
|
||||
if uls:
|
||||
order.add_ul(uls)
|
||||
order.add_ul(uls, origin_restrict=origin_restrict,
|
||||
origin_restrict_warn=origin_restrict_warn)
|
||||
if order.state in ('draft', 'waiting'):
|
||||
order.run([order])
|
||||
|
||||
def transition_load_(self, order_id=None, code=None):
|
||||
order, _ = self._get_load_order()
|
||||
self.load(order, self.data.ul_code, self.data.uls_to_load)
|
||||
return 'data'
|
||||
|
||||
def transition_do_(self):
|
||||
|
@ -563,17 +579,26 @@ class LoadUnitLoad(Wizard):
|
|||
return Order(Transaction().context.get('active_id')), False
|
||||
return Order(self.order.load_order.id), True
|
||||
|
||||
def transition_unload_(self):
|
||||
@classmethod
|
||||
def unload(cls, order_id, uls=[]):
|
||||
pool = Pool()
|
||||
UnitLoad = pool.get('stock.unit_load')
|
||||
Order = pool.get('carrier.load.order')
|
||||
|
||||
if not self.data.uls_loaded:
|
||||
self.raise_user_error('unload_any')
|
||||
|
||||
order, _ = self._get_load_order()
|
||||
uls = list(self.data.uls_loaded)
|
||||
if not uls:
|
||||
cls.raise_user_error('unload_any')
|
||||
if isinstance(order_id, int):
|
||||
order = Order(order_id)
|
||||
else:
|
||||
order = order_id
|
||||
if isinstance(uls[0], int):
|
||||
uls = UnitLoad.browse(uls)
|
||||
order._update_sale(uls)
|
||||
UnitLoad.unload(uls)
|
||||
|
||||
def transition_unload_(self):
|
||||
order, _ = self._get_load_order()
|
||||
self.unload(order, list(self.data.uls_loaded))
|
||||
return 'data'
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue