Set moves planned dates when updating internal shipment planned date

issue9334
review299681002
This commit is contained in:
Sergi Almacellas Abellana committed 2020-06-17 14:09:55 +02:00
1 parent 51b4786235
commit b0cd64e7ca
1 file changed
+45 -1
+45 -1
View File
@@ -2152,7 +2152,14 @@ class ShipmentInternal(ShipmentMixin, Workflow, ModelSQL, ModelView):
if values.get('number') is None:
values['number'] = Sequence.get_id(
config.shipment_internal_sequence.id)
return super(ShipmentInternal, cls).create(vlist)
shipments = super().create(vlist)
cls._set_move_planned_date(shipments)
return shipments
@classmethod
def write(cls, *args):
super().write(*args)
cls._set_move_planned_date(sum(args[::2], []))
@classmethod
def delete(cls, shipments):
@@ -2400,6 +2407,43 @@ class ShipmentInternal(ShipmentMixin, Workflow, ModelSQL, ModelView):
Move.assign([m for s in shipments for m in s.outgoing_moves])
cls.assign(shipments)
@property
def _move_planned_date(self):
'''
Return the planned date for incoming moves and inventory_moves
'''
return self.planned_start_date, self.planned_date
@classmethod
def _set_move_planned_date(cls, shipments):
'''
Set planned date of moves for the shipments
'''
Move = Pool().get('stock.move')
to_write = []
for shipment in shipments:
dates = shipment._move_planned_date
outgoing_date, incoming_date = dates
outgoing_moves = [m for m in shipment.outgoing_moves
if (m.state not in ('assigned', 'done', 'cancelled')
and m.planned_date != outgoing_date)]
if outgoing_moves:
to_write.append(outgoing_moves)
to_write.append({
'planned_date': outgoing_date,
})
if shipment.transit_location:
incoming_moves = [m for m in shipment.incoming_moves
if (m.state not in ('assigned', 'done', 'cancelled')
and m.planned_date != incoming_date)]
if incoming_moves:
to_write.append(incoming_moves)
to_write.append({
'planned_date': incoming_date,
})
if to_write:
Move.write(*to_write)
class Address(metaclass=PoolMeta):
__name__ = 'party.address'