Allow assigned move of 0 quantity using view location and delete them

This is needed to be able to ignore assignation of move from a view location,
and to delete them before all moves are set to done.

Closes #12870
This commit is contained in:
Cédric Krier
2023-12-26 16:00:06 +01:00
parent d9782d97aa
commit 5cda753f9f
3 changed files with 7 additions and 5 deletions
+4 -2
View File
@@ -28,7 +28,8 @@ STATES = {
'readonly': Eval('state').in_(['cancelled', 'assigned', 'done']),
}
LOCATION_DOMAIN = [
If(Eval('state').in_(['staging', 'draft', 'cancelled']),
If(Eval('state').in_(['staging', 'draft', 'cancelled'])
| ((Eval('state') == 'assigned') & ~Eval('quantity')),
('type', 'not in', ['warehouse']),
('type', 'not in', ['warehouse', 'view'])),
If(~Eval('state').in_(['done', 'cancelled']),
@@ -927,7 +928,8 @@ class Move(Workflow, ModelSQL, ModelView):
@classmethod
def delete(cls, moves):
for move in moves:
if move.state not in {'staging', 'draft', 'cancelled'}:
if (move.state not in {'staging', 'draft', 'cancelled'}
and move.quantity):
raise AccessError(
gettext('stock.msg_move_delete_draft_cancel',
move=move.rec_name))
+1 -1
View File
@@ -1537,7 +1537,7 @@ class ShipmentOut(
Move = pool.get('stock.move')
Move.delete([
m for s in shipments for m in s.inventory_moves
if m.state == 'staging'])
if m.state == 'staging' or not m.quantity])
Move.do([m for s in shipments for m in s.inventory_moves])
Move.draft([m for s in shipments for m in s.outgoing_moves])
cls._sync_inventory_to_outgoing(shipments, quantity=True)
@@ -181,7 +181,7 @@ Ignore non assigned moves and pack shipment::
>>> len(shipment_out.outgoing_moves)
1
>>> len(shipment_out.inventory_moves)
2
1
>>> shipment_out.inventory_moves[0].state
'done'
>>> sum([m.quantity for m in shipment_out.inventory_moves]) == \
@@ -209,7 +209,7 @@ Set the state as Done::
>>> len(shipment_out.outgoing_moves)
1
>>> len(shipment_out.inventory_moves)
2
1
>>> shipment_out.inventory_moves[0].state
'done'
>>> sum([m.quantity for m in shipment_out.inventory_moves]) == \