Commit d97664b4 authored by Jérome Perrin's avatar Jérome Perrin

reimplement PackingList.isPacked using ZODB (to get rid of movement table dependancy)

parent e2e4f433
......@@ -86,25 +86,40 @@ class PackingList(Delivery):
'isPacked')
def isPacked(self):
"""
Returns 0 if all quantity resource on packing list line
are not in container.
It works only if a Resource is not on 2 PackingListLine.
Returns true if all quantities for all variations of resources are in
containers.
FIXME: this method does not support packing list with 2 movements of
same resource.
"""
# build a mapping of
# (resource, variation_text) -> quantity
container_dict = dict()
for container in self.contentValues(
portal_type=self.getPortalContainerTypeList()):
for container_line in container.contentValues(
portal_type=self.getPortalContainerLineTypeList(),):
if container_line.hasCellContent(base_id='movement'):
for container_cell in container_line.contentValues(
portal_type=self.getPortalContainerLineTypeList(),):
key = (container_cell.getResource(),
container_cell.getVariationText())
container_dict[key] = container_dict.get(key, 0) +\
container_cell.getQuantity()
else:
key = (container_line.getResource(),
container_line.getVariationText())
container_dict[key] = container_dict.get(key, 0) +\
container_line.getQuantity()
if not container_dict:
return False
# Check that all movements are packed.
for movement in self.getMovementList():
key = (movement.getResource(),
movement.getVariationText())
if container_dict.get(key, None) != movement.getQuantity():
return False
return True
quantity = movement.getQuantity()
query_kw = {
'portal_type': self.getPortalContainerLineTypeList(),
'movement.explanation_uid': self.getUid(),
'movement.resource_uid': movement.getResourceUid(),
'movement.variation_text': movement.getVariationText(),
'has_cell_content': 0,
}
container_mvt_list = self.portal_catalog(**query_kw)
packed_quantity = sum([x.getQuantity() for x in container_mvt_list \
if x.getQuantity() is not None])
if quantity != packed_quantity:
return 0
return 1
......@@ -932,8 +932,8 @@ class TestPackingListMixin(TestOrderMixin):
not equals to the quantity of the packing list
"""
packing_list = sequence.get('packing_list')
self.assertEquals(0,packing_list.isPacked())
self.assertEquals('missing',packing_list.getContainerState())
self.assertFalse(packing_list.isPacked())
self.assertEquals('missing', packing_list.getContainerState())
def stepCheckPackingListIsPacked(self,sequence=None, sequence_list=None,
packing_list=None,**kw):
......@@ -944,8 +944,8 @@ class TestPackingListMixin(TestOrderMixin):
if packing_list is None:
packing_list = sequence.get('packing_list')
self.commit()
self.assertEquals(1,packing_list.isPacked())
self.assertEquals('packed',packing_list.getContainerState())
self.assertTrue(packing_list.isPacked())
self.assertEquals('packed', packing_list.getContainerState())
def stepCheckNewPackingListIsPacked(self,sequence=None, sequence_list=None, **kw):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment