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
...@@ -33,184 +33,202 @@ from Acquisition import aq_base ...@@ -33,184 +33,202 @@ from Acquisition import aq_base
from zLOG import LOG from zLOG import LOG
class Inventory(Delivery): class Inventory(Delivery):
"""
Inventory
"""
# CMF Type Definition
meta_type = 'ERP5 Inventory'
portal_type = 'Inventory'
isPortalContent = 1
isRADContent = 1
isDelivery = 1
isInventory = 1
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Task
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.Delivery
, PropertySheet.Path
, PropertySheet.FlowCapacity
, PropertySheet.Inventory
)
security.declarePublic('alternateReindexObject')
def alternateReindexObject(self, **kw):
""" """
Inventory This method is called when an inventory object is included in a
group of catalogged objects.
""" """
# CMF Type Definition return self.immediateReindexObject(**kw)
meta_type = 'ERP5 Inventory'
portal_type = 'Inventory'
isPortalContent = 1
isRADContent = 1
isDelivery = 1
isInventory = 1
# Declarative security def immediateReindexObject(self, temp_constructor=None, **kw):
security = ClassSecurityInfo() """
security.declareObjectProtected(Permissions.AccessContentsInformation) Rewrite reindexObject so that we can insert lines in stock table
which will be equal to the difference between stock values for
# Default Properties resource in the inventory and the one before the date of this inventory
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.Task
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.Delivery
, PropertySheet.Path
, PropertySheet.FlowCapacity
, PropertySheet.Inventory
)
security.declarePublic('alternateReindexObject') temp_constructor is used in some particular cases where we want
def alternateReindexObject(self, **kw): to have our own temp object constructor, this is usefull if we
"""This method is called when an inventory object is included in a want to use some classes with some particular methods
group of catalogged objects. """
""" sql_catalog_id = kw.pop("sql_catalog_id", None)
return self.immediateReindexObject(**kw) disable_archive = kw.pop("disable_archive", 0)
connection_id = None
if sql_catalog_id is not None:
# try to get connection used in the catalog
catalog = self.portal_catalog[sql_catalog_id]
for method in catalog.objectValues():
if method.meta_type == "Z SQL Method":
if 'deferred' not in method.connection_id \
and 'transactionless' not in method.connection_id:
connection_id = method.connection_id
break
resource_and_variation_dict = {}
stock_object_list = []
stock_append = stock_object_list.append
if temp_constructor is None:
from Products.ERP5Type.Document import newTempDeliveryLine
temp_constructor = newTempDeliveryLine
start_date = self.getStartDate()
node = self.getDestination()
# build a dict containing all inventory for this node
# group by resource/variation and then subvariation
current_inventory_list = \
self.getPortalObject().portal_simulation.getInventoryList(
to_date=start_date,
node=node,
simulation_state=self.getPortalCurrentInventoryStateList(),
group_by_sub_variation=1,
group_by_variation=1,
group_by_resource=1,
connection_id=connection_id,
)
current_inventory_dict = {}
current_inventory_key_id_list = ('resource_relative_url', 'variation_text')
for line in current_inventory_list:
current_inventory_key = tuple(
[line[x] for x in current_inventory_key_id_list])
if current_inventory_key[1] == None:
# To be consistent
current_inventory_key = (current_inventory_key[0], "")
try:
current_inventory_by_sub_variation = \
current_inventory_dict[current_inventory_key]
except KeyError:
current_inventory_by_sub_variation = \
current_inventory_dict[current_inventory_key] = {}
current_inventory_by_sub_variation[line['sub_variation_text']] = \
line['total_quantity']
def immediateReindexObject(self,temp_constructor=None,**kw): def getCurrentInventoryBySubVariation(**criterion_dict):
""" current_inventory_key = tuple(
Rewrite reindexObject so that we can insert lines in stock table [criterion_dict[x] for x in current_inventory_key_id_list])
which will be equal to the difference between stock values for return current_inventory_dict.get(current_inventory_key, {})
resource in the inventory and the one before the date of this inventory
temp_constructor is used in some particular cases where we want # Browse all movements on inventory and create diff line when necessary
to have our own temp object constructor, this is usefull if we not_used_inventory_dict = {}
want to use some classes with some particular methods inventory_uid = self.getUid()
""" inventory_id = self.getId()
sql_catalog_id = kw.pop("sql_catalog_id", None) for movement in self.getMovementList():
disable_archive = kw.pop("disable_archive", 0) if movement.getResourceValue() is not None and \
connection_id = None movement.getQuantity() not in (None, ''):
if sql_catalog_id is not None: resource_path = movement.getResource()
# try to get connection used in the catalog variation_text = movement.getVariationText()
catalog = self.portal_catalog[sql_catalog_id] movement_quantity = movement.getQuantity()
for method in catalog.objectValues(): destination_payment_path = movement.getDestinationPayment()
if method.meta_type == "Z SQL Method": resource_and_variation_key = (resource_path, variation_text)
if 'deferred' not in method.connection_id \ inventory_by_subvariation_dict = getCurrentInventoryBySubVariation(
and 'transactionless' not in method.connection_id: resource_relative_url=resource_path,
connection_id = method.connection_id variation_text=variation_text)
break movement_sub_variation_text = movement.getSubVariationText()
# Check wath is the quantity difference
resource_and_variation_dict = {} if movement_sub_variation_text in \
stock_object_list = [] inventory_by_subvariation_dict.keys():
stock_append = stock_object_list.append total_quantity = inventory_by_subvariation_dict.pop(
if temp_constructor is None: movement_sub_variation_text)
from Products.ERP5Type.Document import newTempDeliveryLine # Put remaining subvariation in a dict to know which one
temp_constructor = newTempDeliveryLine # to removed at end
start_date = self.getStartDate() not_used_inventory_dict[resource_and_variation_key] = \
node = self.getDestination() inventory_by_subvariation_dict
# build a dict containing all inventory for this node group by resource/variation diff_quantity = movement_quantity - total_quantity
# and then subvariation else:
current_inventory_list = self.getPortalObject().portal_simulation.getInventoryList( \ # Inventory for new resource/variation/sub_variation
to_date = start_date diff_quantity = movement_quantity
, node = node # Put remaining subvariation in a dict to know which one
, simulation_state = self.getPortalCurrentInventoryStateList() # to removed at end
, group_by_sub_variation = 1 not_used_inventory_dict[resource_and_variation_key] = \
, group_by_variation = 1 inventory_by_subvariation_dict
, group_by_resource = 1
, connection_id = connection_id
)
current_inventory_dict = {}
current_inventory_key_id_list = ('resource_relative_url', 'variation_text')
for line in current_inventory_list:
current_inventory_key = tuple([line[x] for x in current_inventory_key_id_list])
if current_inventory_key[1] == None:
# To be consistent
current_inventory_key = (current_inventory_key[0], "")
try:
current_inventory_by_sub_variation = current_inventory_dict[current_inventory_key]
except KeyError:
current_inventory_by_sub_variation = current_inventory_dict[current_inventory_key] = {}
current_inventory_by_sub_variation[line['sub_variation_text']] = line['total_quantity']
def getCurrentInventoryBySubVariation(**criterion_dict): # Create tmp movement with only diff between inventory
current_inventory_key = tuple([criterion_dict[x] for x in current_inventory_key_id_list]) # and previous stock values
return current_inventory_dict.get(current_inventory_key, {}) if diff_quantity != 0:
# Browse all movements on inventory and create diff line when necessary kwd = {'uid': inventory_uid,
not_used_inventory_dict = {} 'start_date': start_date}
inventory_uid = self.getUid() if variation_text is not None:
inventory_id = self.getId() variation_list = variation_text.split('\n')
for movement in self.getMovementList():
if movement.getResourceValue() is not None and movement.getQuantity() not in (None,''):
resource_path = movement.getResource()
variation_text = movement.getVariationText()
movement_quantity = movement.getQuantity()
destination_payment_path = movement.getDestinationPayment()
resource_and_variation_key = (resource_path, variation_text)
inventory_by_subvariation_dict = getCurrentInventoryBySubVariation(
resource_relative_url=resource_path,
variation_text=variation_text)
movement_sub_variation_text = movement.getSubVariationText()
# Check wath is the quantity difference
if movement_sub_variation_text in inventory_by_subvariation_dict.keys():
total_quantity = inventory_by_subvariation_dict.pop(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
else: else:
# Inventory for new resource/variation/sub_variation variation_list = []
diff_quantity = movement_quantity category_list = self.getCategoryList()
# Put remaining subvariation in a dict to know which one to removed at end sub_variation_list = []
not_used_inventory_dict[resource_and_variation_key] = inventory_by_subvariation_dict if movement_sub_variation_text is not None:
sub_variation_list = movement_sub_variation_text.split('\n')
temp_delivery_line = temp_constructor(self,
inventory_id)
kwd['quantity'] = diff_quantity
category_list.append('resource/%s' % resource_path)
category_list.append(
'destination_payment/%s' % destination_payment_path)
category_list.extend(variation_list)
category_list.extend(sub_variation_list)
kwd['category_list'] = category_list
temp_delivery_line.edit(**kwd)
stock_append(temp_delivery_line)
# Create tmp movement with only diff between inventory # Now create line to remove some subvariation text not present
# and previous stock values # in new inventory
if diff_quantity != 0: for resource_and_variation_key in not_used_inventory_dict.keys():
kwd = {'uid':inventory_uid, inventory_by_subvariation_dict = \
'start_date': start_date} not_used_inventory_dict[resource_and_variation_key]
if variation_text is not None: for sub_variation_text in inventory_by_subvariation_dict.keys():
variation_list = variation_text.split('\n') category_list = self.getCategoryList()
else: quantity = inventory_by_subvariation_dict[sub_variation_text]
variation_list = [] resource_path, variation_text = resource_and_variation_key
category_list = self.getCategoryList() kwd = {'uid': inventory_uid,
sub_variation_list = [] 'start_date': start_date}
if movement_sub_variation_text is not None: if variation_text is not None:
sub_variation_list = movement_sub_variation_text.split('\n') variation_list = variation_text.split('\n')
temp_delivery_line = temp_constructor(self, else:
inventory_id) variation_list = []
kwd['quantity'] = diff_quantity sub_variation_list = sub_variation_text.split('\n')
category_list.append('resource/%s' % resource_path) diff_quantity = - quantity
category_list.append('destination_payment/%s' % destination_payment_path) temp_delivery_line = temp_constructor(self, inventory_id)
category_list.extend(variation_list) kwd['quantity'] = diff_quantity
category_list.extend(sub_variation_list) category_list.append('resource/%s' % resource_path)
kwd['category_list'] = category_list category_list.extend(variation_list)
temp_delivery_line.edit(**kwd) category_list.extend(sub_variation_list)
stock_append(temp_delivery_line) kwd['category_list'] = category_list
temp_delivery_line.edit(**kwd)
stock_append(temp_delivery_line)
# Now create line to remove some subvariation text not present in new inventory # Reindex objects
for resource_and_variation_key in not_used_inventory_dict.keys(): object_list = [self]
inventory_by_subvariation_dict = not_used_inventory_dict[resource_and_variation_key] self.portal_catalog.catalogObjectList(object_list,
for sub_variation_text in inventory_by_subvariation_dict.keys(): disable_archive=disable_archive)
category_list = self.getCategoryList() if len(stock_object_list)==0:
quantity = inventory_by_subvariation_dict[sub_variation_text] # Make sure to remove all lines
resource_path, variation_text = resource_and_variation_key from Products.ERP5Type.Document import newTempBase
kwd = {'uid':inventory_uid, stock_append(temp_constructor(self, inventory_id, uid=inventory_uid))
'start_date': start_date} self.portal_catalog.catalogObjectList(
if variation_text is not None: stock_object_list, method_id_list=('z_catalog_stock_list', ),
variation_list = variation_text.split('\n') disable_cache=1, check_uid=0, disable_archive=disable_archive)
else:
variation_list = []
sub_variation_list = sub_variation_text.split('\n')
diff_quantity = - quantity
temp_delivery_line = temp_constructor(self,
inventory_id)
kwd['quantity'] = diff_quantity
category_list.append('resource/%s' % resource_path)
category_list.extend(variation_list)
category_list.extend(sub_variation_list)
kwd['category_list'] = category_list
temp_delivery_line.edit(**kwd)
stock_append(temp_delivery_line)
# Reindex objects
object_list = [self]
self.portal_catalog.catalogObjectList(object_list, disable_archive=disable_archive)
if len(stock_object_list)==0:
# Make sure to remove all lines
from Products.ERP5Type.Document import newTempBase
stock_append(temp_constructor(self,inventory_id,
uid=inventory_uid))
self.portal_catalog.catalogObjectList(stock_object_list,
method_id_list=('z_catalog_stock_list',),
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