Fix searcher of UL load_order field.

This commit refs #21735
This commit is contained in:
Sergio Morillo 2022-01-18 11:59:08 +01:00
parent 8cfdddc6ca
commit 65d81f861c
2 changed files with 46 additions and 16 deletions

View File

@ -211,6 +211,10 @@ Starting load wizard::
Check UL loading restrictions:: Check UL loading restrictions::
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', None)]))
True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '!=', None)]))
False
>>> start_load.form.ul_code = ul.code >>> start_load.form.ul_code = ul.code
>>> start_load.execute('load_') >>> start_load.execute('load_')
Traceback (most recent call last): Traceback (most recent call last):
@ -223,6 +227,14 @@ Check UL loading restrictions::
>>> not Unitload.find([('id', '=', ul.id), ('available', '=', False)]) >>> not Unitload.find([('id', '=', ul.id), ('available', '=', False)])
True True
>>> start_load.execute('load_') >>> start_load.execute('load_')
>>> bool(Unitload.find([('id', '=', ul.id), ('available', '=', False)]))
True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', None)]))
False
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '!=', None)]))
True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', order)]))
True
>>> start_load.form.loaded_uls >>> start_load.form.loaded_uls
1 1
>>> order.reload() >>> order.reload()
@ -236,6 +248,14 @@ Check UL loading restrictions::
False False
>>> not Unitload.find([('id', '=', order.unit_loads[0].id), ('available', '=', True)]) >>> not Unitload.find([('id', '=', order.unit_loads[0].id), ('available', '=', True)])
True True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', None)]))
False
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '!=', None)]))
True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', order.id)]))
True
>>> bool(Unitload.find([('id', '=', ul.id), ('load_order', '=', order)]))
True
>>> start_load.form.ul_code = ul.code >>> start_load.form.ul_code = ul.code
>>> start_load.execute('load_') >>> start_load.execute('load_')
Traceback (most recent call last): Traceback (most recent call last):

View File

@ -72,23 +72,33 @@ class UnitLoad(metaclass=PoolMeta):
@classmethod @classmethod
def search_load_order(cls, name, clause): def search_load_order(cls, name, clause):
_field = 'load_line.%s' % clause[0].replace(name, 'order', 1) join_operator = 'OR'
_field2 = 'load_lines.%s' % clause[0].replace(name, 'order', 1) cond1, cond2 = [], []
if '.' not in clause[0] and clause[2] is not None:
if clause[2] is None or isinstance(clause[2], ( def get_field(_field):
int, list, tuple, set, Model)): return '%s.%s' % (
_field += '.id' _field,
_field2 += '.id' clause[0].replace(name, 'order', 1))
if '.' not in clause[0]:
if clause[2] is None:
if clause[1] == '=':
join_operator = 'AND'
cond1.append(('load_line', ) + tuple(clause[1:]))
cond2.append(('load_lines', ) + tuple(clause[1:]))
else: else:
_field += '.rec_name' cond1.append((get_field('load_line'), ) + tuple(clause[1:]))
_field2 += '.rec_name' cond2.extend([
return ['OR', ('load_lines', '!=', None),
[ (get_field('load_lines'), ) + tuple(clause[1:])
(_field, ) + tuple(clause[1:]), ])
], [ else:
('load_line', '=', None), cond1.append((get_field('load_line'), ) + tuple(clause[1:]))
(_field2, ) + tuple(clause[1:]) cond2.append((get_field('load_lines'), ) + tuple(clause[1:]))
]
return [join_operator,
cond1,
cond2
] ]
@classmethod @classmethod