Commit da756e44 authored by Romain Courteaud's avatar Romain Courteaud

Wrap to 80 characters.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16612 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e58b124d
...@@ -64,12 +64,13 @@ class Inventory(Delivery): ...@@ -64,12 +64,13 @@ class Inventory(Delivery):
security.declarePublic('alternateReindexObject') security.declarePublic('alternateReindexObject')
def alternateReindexObject(self, **kw): def alternateReindexObject(self, **kw):
"""This method is called when an inventory object is included in a """
This method is called when an inventory object is included in a
group of catalogged objects. group of catalogged objects.
""" """
return self.immediateReindexObject(**kw) return self.immediateReindexObject(**kw)
def immediateReindexObject(self,temp_constructor=None,**kw): def immediateReindexObject(self, temp_constructor=None, **kw):
""" """
Rewrite reindexObject so that we can insert lines in stock table Rewrite reindexObject so that we can insert lines in stock table
which will be equal to the difference between stock values for which will be equal to the difference between stock values for
...@@ -100,39 +101,47 @@ class Inventory(Delivery): ...@@ -100,39 +101,47 @@ class Inventory(Delivery):
temp_constructor = newTempDeliveryLine temp_constructor = newTempDeliveryLine
start_date = self.getStartDate() start_date = self.getStartDate()
node = self.getDestination() node = self.getDestination()
# build a dict containing all inventory for this node group by resource/variation # build a dict containing all inventory for this node
# and then subvariation # group by resource/variation and then subvariation
current_inventory_list = self.getPortalObject().portal_simulation.getInventoryList( \ current_inventory_list = \
to_date = start_date self.getPortalObject().portal_simulation.getInventoryList(
, node = node to_date=start_date,
, simulation_state = self.getPortalCurrentInventoryStateList() node=node,
, group_by_sub_variation = 1 simulation_state=self.getPortalCurrentInventoryStateList(),
, group_by_variation = 1 group_by_sub_variation=1,
, group_by_resource = 1 group_by_variation=1,
, connection_id = connection_id group_by_resource=1,
connection_id=connection_id,
) )
current_inventory_dict = {} current_inventory_dict = {}
current_inventory_key_id_list = ('resource_relative_url', 'variation_text') current_inventory_key_id_list = ('resource_relative_url', 'variation_text')
for line in current_inventory_list: for line in current_inventory_list:
current_inventory_key = tuple([line[x] for x in current_inventory_key_id_list]) current_inventory_key = tuple(
[line[x] for x in current_inventory_key_id_list])
if current_inventory_key[1] == None: if current_inventory_key[1] == None:
# To be consistent # To be consistent
current_inventory_key = (current_inventory_key[0], "") current_inventory_key = (current_inventory_key[0], "")
try: try:
current_inventory_by_sub_variation = current_inventory_dict[current_inventory_key] current_inventory_by_sub_variation = \
current_inventory_dict[current_inventory_key]
except KeyError: except KeyError:
current_inventory_by_sub_variation = current_inventory_dict[current_inventory_key] = {} current_inventory_by_sub_variation = \
current_inventory_by_sub_variation[line['sub_variation_text']] = line['total_quantity'] current_inventory_dict[current_inventory_key] = {}
current_inventory_by_sub_variation[line['sub_variation_text']] = \
line['total_quantity']
def getCurrentInventoryBySubVariation(**criterion_dict): def getCurrentInventoryBySubVariation(**criterion_dict):
current_inventory_key = tuple([criterion_dict[x] for x in current_inventory_key_id_list]) current_inventory_key = tuple(
[criterion_dict[x] for x in current_inventory_key_id_list])
return current_inventory_dict.get(current_inventory_key, {}) return current_inventory_dict.get(current_inventory_key, {})
# Browse all movements on inventory and create diff line when necessary # Browse all movements on inventory and create diff line when necessary
not_used_inventory_dict = {} not_used_inventory_dict = {}
inventory_uid = self.getUid() inventory_uid = self.getUid()
inventory_id = self.getId() inventory_id = self.getId()
for movement in self.getMovementList(): for movement in self.getMovementList():
if movement.getResourceValue() is not None and movement.getQuantity() not in (None,''): if movement.getResourceValue() is not None and \
movement.getQuantity() not in (None, ''):
resource_path = movement.getResource() resource_path = movement.getResource()
variation_text = movement.getVariationText() variation_text = movement.getVariationText()
movement_quantity = movement.getQuantity() movement_quantity = movement.getQuantity()
...@@ -143,21 +152,27 @@ class Inventory(Delivery): ...@@ -143,21 +152,27 @@ class Inventory(Delivery):
variation_text=variation_text) variation_text=variation_text)
movement_sub_variation_text = movement.getSubVariationText() movement_sub_variation_text = movement.getSubVariationText()
# Check wath is the quantity difference # Check wath is the quantity difference
if movement_sub_variation_text in inventory_by_subvariation_dict.keys(): if movement_sub_variation_text in \
total_quantity = inventory_by_subvariation_dict.pop(movement_sub_variation_text) inventory_by_subvariation_dict.keys():
# Put remaining subvariation in a dict to know which one to removed at end total_quantity = inventory_by_subvariation_dict.pop(
not_used_inventory_dict[resource_and_variation_key] = inventory_by_subvariation_dict movement_sub_variation_text)
# Put remaining subvariation in a dict to know which one
# to removed at end
not_used_inventory_dict[resource_and_variation_key] = \
inventory_by_subvariation_dict
diff_quantity = movement_quantity - total_quantity diff_quantity = movement_quantity - total_quantity
else: else:
# Inventory for new resource/variation/sub_variation # Inventory for new resource/variation/sub_variation
diff_quantity = movement_quantity diff_quantity = movement_quantity
# Put remaining subvariation in a dict to know which one to removed at end # Put remaining subvariation in a dict to know which one
not_used_inventory_dict[resource_and_variation_key] = inventory_by_subvariation_dict # to removed at end
not_used_inventory_dict[resource_and_variation_key] = \
inventory_by_subvariation_dict
# Create tmp movement with only diff between inventory # Create tmp movement with only diff between inventory
# and previous stock values # and previous stock values
if diff_quantity != 0: if diff_quantity != 0:
kwd = {'uid':inventory_uid, kwd = {'uid': inventory_uid,
'start_date': start_date} 'start_date': start_date}
if variation_text is not None: if variation_text is not None:
variation_list = variation_text.split('\n') variation_list = variation_text.split('\n')
...@@ -171,21 +186,24 @@ class Inventory(Delivery): ...@@ -171,21 +186,24 @@ class Inventory(Delivery):
inventory_id) inventory_id)
kwd['quantity'] = diff_quantity kwd['quantity'] = diff_quantity
category_list.append('resource/%s' % resource_path) category_list.append('resource/%s' % resource_path)
category_list.append('destination_payment/%s' % destination_payment_path) category_list.append(
'destination_payment/%s' % destination_payment_path)
category_list.extend(variation_list) category_list.extend(variation_list)
category_list.extend(sub_variation_list) category_list.extend(sub_variation_list)
kwd['category_list'] = category_list kwd['category_list'] = category_list
temp_delivery_line.edit(**kwd) temp_delivery_line.edit(**kwd)
stock_append(temp_delivery_line) stock_append(temp_delivery_line)
# Now create line to remove some subvariation text not present in new inventory # Now create line to remove some subvariation text not present
# in new inventory
for resource_and_variation_key in not_used_inventory_dict.keys(): for resource_and_variation_key in not_used_inventory_dict.keys():
inventory_by_subvariation_dict = not_used_inventory_dict[resource_and_variation_key] inventory_by_subvariation_dict = \
not_used_inventory_dict[resource_and_variation_key]
for sub_variation_text in inventory_by_subvariation_dict.keys(): for sub_variation_text in inventory_by_subvariation_dict.keys():
category_list = self.getCategoryList() category_list = self.getCategoryList()
quantity = inventory_by_subvariation_dict[sub_variation_text] quantity = inventory_by_subvariation_dict[sub_variation_text]
resource_path, variation_text = resource_and_variation_key resource_path, variation_text = resource_and_variation_key
kwd = {'uid':inventory_uid, kwd = {'uid': inventory_uid,
'start_date': start_date} 'start_date': start_date}
if variation_text is not None: if variation_text is not None:
variation_list = variation_text.split('\n') variation_list = variation_text.split('\n')
...@@ -193,8 +211,7 @@ class Inventory(Delivery): ...@@ -193,8 +211,7 @@ class Inventory(Delivery):
variation_list = [] variation_list = []
sub_variation_list = sub_variation_text.split('\n') sub_variation_list = sub_variation_text.split('\n')
diff_quantity = - quantity diff_quantity = - quantity
temp_delivery_line = temp_constructor(self, temp_delivery_line = temp_constructor(self, inventory_id)
inventory_id)
kwd['quantity'] = diff_quantity kwd['quantity'] = diff_quantity
category_list.append('resource/%s' % resource_path) category_list.append('resource/%s' % resource_path)
category_list.extend(variation_list) category_list.extend(variation_list)
...@@ -205,12 +222,13 @@ class Inventory(Delivery): ...@@ -205,12 +222,13 @@ class Inventory(Delivery):
# Reindex objects # Reindex objects
object_list = [self] object_list = [self]
self.portal_catalog.catalogObjectList(object_list, disable_archive=disable_archive) self.portal_catalog.catalogObjectList(object_list,
disable_archive=disable_archive)
if len(stock_object_list)==0: if len(stock_object_list)==0:
# Make sure to remove all lines # Make sure to remove all lines
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
stock_append(temp_constructor(self,inventory_id, stock_append(temp_constructor(self, inventory_id, uid=inventory_uid))
uid=inventory_uid)) self.portal_catalog.catalogObjectList(
self.portal_catalog.catalogObjectList(stock_object_list, stock_object_list, method_id_list=('z_catalog_stock_list', ),
method_id_list=('z_catalog_stock_list',), disable_cache=1, check_uid=0, disable_archive=disable_archive)
disable_cache=1,check_uid=0, disable_archive=disable_archive)
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