Fix shipment report when locations are the same or transit location is used

The inventory moves is empty when the locations of the shipment are the same.
The other moves field must be used.
When a transit location is used for internal shipment, the moves field to use
depend of the state. If it is already shipped then the incoming moves is used
to know where to store products and if it is not yet shipped than the outgoing
moves is used to pick the products.

issue7881
review50641002
This commit is contained in:
Cédric Krier committed 2018-12-17 23:08:09 +01:00
1 parent e8653f0815
commit d5ac1e8337
2 files changed
+44 -10

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Change move attribute of ShipmentReport for a method
* Rename inventory count quantity_resulting to total_quantity
Version 5.0.0 - 2018-10-01
+43 -10
View File
@@ -2485,7 +2485,6 @@ class DeliveryNote(CompanyReport):
class ShipmentReport(CompanyReport):
move_attribute = 'inventory_moves'
@classmethod
def execute(cls, ids, data):
@@ -2493,25 +2492,29 @@ class ShipmentReport(CompanyReport):
return super(ShipmentReport, cls).execute(ids, data)
@classmethod
def get_context(cls, records, data):
report_context = super(ShipmentReport, cls).get_context(records, data)
def moves(cls, shipment):
raise NotImplementedError
compare_context = cls.get_compare_context(records, data)
@classmethod
def get_context(cls, shipments, data):
report_context = super().get_context(shipments, data)
compare_context = cls.get_compare_context(shipments, data)
sorted_moves = {}
for shipment in records:
for shipment in shipments:
sorted_moves[shipment.id] = sorted(
getattr(shipment, cls.move_attribute),
cls.moves(shipment),
key=functools.partial(cls.get_compare_key, compare_context))
report_context['moves'] = sorted_moves
return report_context
@classmethod
def get_compare_context(cls, objects, data):
def get_compare_context(cls, shipments, data):
from_location_ids = set()
to_location_ids = set()
for obj in objects:
for move in getattr(obj, cls.move_attribute):
for shipment in shipments:
for move in cls.moves(shipment):
from_location_ids.add(move.from_location.id)
to_location_ids.add(move.to_location.id)
@@ -2532,18 +2535,48 @@ class PickingList(ShipmentReport):
'Picking List'
__name__ = 'stock.shipment.out.picking_list'
@classmethod
def moves(cls, shipment):
if shipment.warehouse_storage == shipment.warehouse_output:
return shipment.outgoing_moves
else:
return shipment.inventory_moves
class SupplierRestockingList(ShipmentReport):
'Supplier Restocking List'
__name__ = 'stock.shipment.in.restocking_list'
@classmethod
def moves(cls, shipment):
if shipment.warehouse_input == shipment.warehouse_storage:
return shipment.incoming_moves
else:
return shipment.inventory_moves
class CustomerReturnRestockingList(ShipmentReport):
'Customer Return Restocking List'
__name__ = 'stock.shipment.out.return.restocking_list'
@classmethod
def moves(cls, shipment):
if shipment.warehouse_input == shipment.warehouse_storage:
return shipment.incoming_moves
else:
return shipment.inventory_moves
class InteralShipmentReport(ShipmentReport):
'Interal Shipment Report'
__name__ = 'stock.shipment.internal.report'
move_attribute = 'moves'
@classmethod
def moves(cls, shipment):
if shipment.transit_location:
if shipment.state == 'shipped':
return shipment.incoming_moves
else:
return shipment.outgoing_moves
else:
return shipment.moves