Commit 89805a50 authored by Vincent Pelletier's avatar Vincent Pelletier

Modify getVaultPathFromCodification to use dict-based translation instead of...

Modify getVaultPathFromCodification to use dict-based translation instead of relying on site's categories codifications.
editDocument: Likewise, and move translation dict to class level.
Import translation dicts because they depend on category configuration and import codification conventions.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14243 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 80050e4f
...@@ -191,7 +191,24 @@ class BaobabConduit(ERP5Conduit): ...@@ -191,7 +191,24 @@ class BaobabConduit(ERP5Conduit):
}], }],
} }
try:
from Products.Baobab.Conduit import inventory_code_to_path
from Products.Baobab.Conduit import vault_code_to_path
from Products.Baobab.Conduit import variation_translate_dict
except ImportError:
inventory_code_to_path = {}
vault_code_to_path = {}
variation_translate_dict = {}
status_code_to_cash_status = {'TVA' : 'valid',
'NEE' : 'new_emitted',
'NEU' : 'new_not_emitted',
'RTC' : 'retired',
'ATR' : 'to_sort',
'MUT' : 'mutilated',
'EAV' : 'to_ventilate',
'ANN' : 'cancelled',
'MIX' : 'mixed'}
""" """
Methods below are tools to use the property_map. Methods below are tools to use the property_map.
...@@ -532,16 +549,9 @@ class BaobabConduit(ERP5Conduit): ...@@ -532,16 +549,9 @@ class BaobabConduit(ERP5Conduit):
for base_key in base_cat_map.keys(): for base_key in base_cat_map.keys():
if base_key in kw.keys() and kw[base_key] not in ('', None): if base_key in kw.keys() and kw[base_key] not in ('', None):
if base_key == 'status_code': if base_key == 'status_code':
status_table = { 'TVA' : 'valid' category = self.status_code_to_cash_status[kw[base_key]]
, 'NEE' : 'new_emitted' elif base_key == 'variation':
, 'NEU' : 'new_not_emitted' category = self.variation_translate_dict.get(kw[base_key], kw[base_key])
, 'RTC' : 'retired'
, 'ATR' : 'to_sort'
, 'MUT' : 'mutilated'
, 'EAV' : 'to_ventilate'
, 'ANN' : 'cancelled'
}
category = status_table[kw[base_key]]
else: else:
category = kw[base_key] category = kw[base_key]
else: else:
...@@ -883,89 +893,41 @@ class BaobabConduit(ERP5Conduit): ...@@ -883,89 +893,41 @@ class BaobabConduit(ERP5Conduit):
def getVaultPathFromCodification( self, object, agency_code=None, inventory_code=None, vault_code=None, currency_id=None): def getVaultPathFromCodification( self, object, agency_code=None, inventory_code=None, vault_code=None, currency_id=None):
""" """
This method get many parameters and try to find a category Recompose category path from agency_code, inventory_code and vault_code.
corresponding with parameters. agency_code : site's codification
inventory_code : relative path common to all vaults for a given
For example if agency_code=A00, this function will returns inventory
site/aaa/bbb/ccc vault_code : relative path specific to a given vault in a given
inventory
""" """
if agency_code in (None, ''): if agency_code is None:
return None return None
category_tool = object.portal_categories portal = object.getPortalObject()
# Get the site path to agency resolveCategory = portal.portal_categories.resolveCategory
agency_path = None site_list = portal.Delivery_getVaultItemList(vault_type=('site',),
site_base_object = category_tool.resolveCategory('site') strict_membership=1,
# XXX Warning, we should use the catalog in order to retrieve this leaf_node=0,
# first level. It will go faster. But we need the codification in user_site=0,
# the catalog table with_base=1)[1:]
agency_dict = dict([(resolveCategory(path).getCodification(), path) \
# Parse the category tree in order to find the category corresponding for (title, path) in site_list])
# to the agency agency_path = agency_dict.get(agency_code)
for site_item in site_base_object.Delivery_getVaultItemList( result_list = []
vault_type=('site',), if agency_path is not None:
strict_membership=1,leaf_node=0, result_list.append(agency_path)
user_site=0,with_base=1)[1:]: inventory_path = self.inventory_code_to_path.get(inventory_code)
site_path = site_item[1] if inventory_path is not None:
site_object = category_tool.resolveCategory(site_path) result_list.append(inventory_path)
if site_object.getPortalType() == 'Category': vault_path = self.vault_code_to_path.get(vault_code)
site_code = site_object.getCodification() if vault_path is not None:
if site_code not in (None, '') and site_code.upper() == agency_code.upper(): result_list.append(vault_path)
agency_path = site_path elif vault_code is not None:
break raise ValueError, '%s is not a known vault import codification' % (vault_code, )
#import pdb;pdb.set_trace() elif inventory_code is not None:
if inventory_code in (None, ''): raise ValueError, '%s is not a known inventory import codification' % (inventory_code, )
return agency_path if len(result_list) == 0:
# Get the site path corresponding to the inventory type return None
inventory_path = None return '/'.join(result_list)
agency_site_object = site_object
# Parse the category tree (from the level of the agency) in order to
# find the category corresponding to the inventory
for agency_sub_item in agency_site_object.getCategoryChildItemList(base=1)[1:]:
agency_sub_item_path = agency_sub_item[1]
agency_sub_item_object = category_tool.resolveCategory(agency_sub_item_path)
agency_sub_item_vault = agency_sub_item_object.getVaultType()
if agency_sub_item_vault not in (None, ''):
vault_type_path = 'vault_type/' + agency_sub_item_vault
vault_type_object = category_tool.resolveCategory(vault_type_path)
vault_type_code = vault_type_object.getCodification()
if vault_type_code not in (None, '') and vault_type_code.upper() == inventory_code.upper():
inventory_path = agency_sub_item_path
break
if vault_code in (None, ''):
return inventory_path
# Get the site path corresponding to the vault code
vault_path = None
vault_site_object = agency_sub_item_object
# Parse the category tree (from the level of the inventory) in order to
# find the category corresponding to the vault
for vault_sub_item in vault_site_object.getCategoryChildItemList(base=1)[1:]:
vault_sub_item_path = vault_sub_item[1]
vault_sub_item_object = category_tool.resolveCategory(vault_sub_item_path)
vault_sub_item_code = vault_sub_item_object.getCodification()
if vault_sub_item_code not in (None, '') and vault_sub_item_code.upper() == vault_code.upper():
vault_path = vault_sub_item_path
break
if currency_id in (None, ''):
return vault_path
# Get the site path corresponding to the currency-related-subvault
currency_object = category_tool.currency_module[currency_id]
currency_title = currency_object.getTitle()
currency_vault_path = None
vault_object = vault_sub_item_object
# Parse the category tree (from the level of the vault) in order to
# find the category corresponding to the currency
for currency_vault_item in vault_object.getCategoryChildItemList(base=1)[1:]:
currency_vault_item_path = currency_vault_item[1]
currency_vault_item_object = category_tool.resolveCategory(currency_vault_item_path)
currency_vault_item_title = currency_vault_item_object.getTitle()
if currency_vault_item_title not in (None, '') and currency_vault_item_title.upper() == currency_title.upper():
currency_vault_path = currency_vault_item_path
break
if currency_vault_path == None:
return vault_path
return currency_vault_path
### CashInventoryDetail-related-properties functions ### CashInventoryDetail-related-properties functions
......
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