Do not cancel shipment when ULs have later moves.

This commit refs #25579
This commit is contained in:
ramon.vidal 2023-01-19 10:27:07 +01:00 committed by Sergio Morillo
parent 7ca145b144
commit 80a2b096b0
5 changed files with 87 additions and 7 deletions

View File

@ -55,6 +55,9 @@ def register():
module='stock_unit_load', type_='report')
Pool.register(
stock.Move2,
shipment.ShipmentInternalDone2Cancel,
shipment.ShipmentOutDone2Cancel,
shipment.ShipmentOutReturnDone2Cancel,
module='stock_unit_load', type_='model',
depends=['stock_move_done2cancel'])
Pool.register(

View File

@ -77,7 +77,10 @@ for dep in info.get('depends', []):
requires.append(get_require_version('trytond'))
tests_require = [get_require_version('proteus')]
tests_require = [
get_require_version('proteus'),
get_require_version('datalife_stock_move_done2cancel')
]
if minor_version % 2:
# Add development index for testing with proteus

View File

@ -346,3 +346,61 @@ class Assign(metaclass=PoolMeta):
self.record.assign_force()
return 'end'
return super().transition_start()
class ShipmentInternalDone2Cancel(metaclass=PoolMeta):
__name__ = 'stock.shipment.internal'
@classmethod
def cancel(cls, records):
for record in records:
record._check_cancel_ul_moves()
super().cancel(records)
def _check_cancel_ul_moves(self):
for unit_load in self.unit_loads:
unit_load.check_to_move(
self.from_location,
self.to_location,
self.date_time_,
check_state=False)
class ShipmentOutDone2Cancel(metaclass=PoolMeta):
__name__ = 'stock.shipment.out'
@classmethod
def cancel(cls, records):
for record in records:
record._check_cancel_ul_moves()
super().cancel(records)
def _check_cancel_ul_moves(self):
from_location = self.warehouse_output
to_location = self.customer_location
for unit_load in self.unit_loads:
unit_load.check_to_move(
from_location,
to_location,
self.end_date,
check_state=False)
class ShipmentOutReturnDone2Cancel(metaclass=PoolMeta):
__name__ = 'stock.shipment.out.return'
@classmethod
def cancel(cls, records):
for record in records:
record._check_cancel_ul_moves()
super().cancel(records)
def _check_cancel_ul_moves(self):
from_location = self.customer_location
to_location = self.warehouse_storage
for unit_load in self.unit_loads:
unit_load.check_to_move(
from_location,
to_location,
self.end_date,
check_state=False)

View File

@ -19,7 +19,7 @@ Imports::
Install unit load Module::
>>> config = activate_modules('stock_unit_load')
>>> config = activate_modules(['stock_unit_load', 'stock_move_done2cancel'])
Create company::
@ -187,3 +187,20 @@ Check unit load state::
True
>>> unit_load.at_warehouse == wh2
True
Add moves to Unit Load::
>>> unit_load.reload()
>>> move_try = Wizard('stock.unit_load.do_move', [unit_load])
>>> move_try.form.location = warehouse_loc.storage_location
>>> move_try.execute('move_')
Cancel Shipment Internal::
>>> shipment_internal.reload()
>>> shipment_internal.state
'done'
>>> shipment_internal.click('cancel') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
trytond.exceptions.UserError: Cannot move unit load "..." at date "..." because later moves exist. -

View File

@ -454,7 +454,6 @@ class UnitLoad(ModelSQL, ModelView):
'stock_unit_load.msg_stock_unit_load_ul_not_available',
unit_load=record.rec_name))
def get_rec_name(self, name):
if Transaction().context.get('ul_extended_rec_name', False):
cases_string = self.fields_get(fields_names=['cases_quantity'])[
@ -926,13 +925,14 @@ class UnitLoad(ModelSQL, ModelView):
location_type=from_location.type)
return new_moves
def check_to_move(self, from_location, to_location, at_date):
def check_to_move(self, from_location, to_location, at_date,
check_state=True):
if not from_location:
raise UserError(gettext(
'stock_unit_load.msg_stock_unit_load_missing_location',
unit_load=self.rec_name))
if self.state != 'done':
if check_state and self.state != 'done':
raise UserError(gettext(
'stock_unit_load.msg_stock_unit_load_wrong_state',
unit_load=self.rec_name))
@ -941,6 +941,7 @@ class UnitLoad(ModelSQL, ModelView):
'stock_unit_load.msg_stock_unit_load_wrong_move_location',
unit_load=self.rec_name,
location=to_location.rec_name))
_max_date = max(m.end_date for m in self.last_moves)
if from_location.type == 'storage' and \
@ -1275,7 +1276,6 @@ class UnitLoad(ModelSQL, ModelView):
@classmethod
@ModelView.button
def assign(cls, records):
origin_moves = [m for r in records for m in r.moves
if m.state in ('draft', 'assigned')]
for move in origin_moves:
@ -1447,7 +1447,6 @@ class UnitLoad(ModelSQL, ModelView):
@fields.depends('production_moves',
methods=['_get_production_move', '_check_production_data'])
def _explode_production_moves(self):
if not self._check_production_data():
self.production_moves = []
return