Commit 0339d7a7 authored by Yusei Tahara's avatar Yusei Tahara

Support three dimensional table. No need to hardcode dimension

number in cell_dict_list parameter.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34606 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e34d32fd
...@@ -358,7 +358,6 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list): ...@@ -358,7 +358,6 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
dicts in cell_dict_list can have following keys: dicts in cell_dict_list can have following keys:
- base_id - base_id
- cell_range_kw - cell_range_kw
- dimension
- mapped_value_argument_list - mapped_value_argument_list
- table - table
...@@ -368,13 +367,34 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list): ...@@ -368,13 +367,34 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
'DeliveryLine_asCellRange', 'DeliveryLine_asCellRange',
({'base_id':'movement', ({'base_id':'movement',
'mapped_value_argument_list':('quantity',), 'mapped_value_argument_list':('quantity',),
'dimension':1,
'table':(('product_packing/package', 1), 'table':(('product_packing/package', 1),
('product_packing/case' , 1), ('product_packing/case' , 1),
) )
}, },
) )
) )
# Table structure examples
one_dimension = (
(line, mapped_value),
(line, mapped_value),
)
two_dimension = (
( column, column,),
(line, mapped_value, mapped_value,),
(line, mapped_value, mapped_value,),
)
three_dimension = (
((tab,),
( column, column,),
(line, mapped_value, mapped_value,),
(line, mapped_value, mapped_value,),
),
((tab,),
( column, column,),
(line, mapped_value, mapped_value,),
(line, mapped_value, mapped_value,),
)
)
""" """
def get_range_id_list(range_list): def get_range_id_list(range_list):
if not range_list: if not range_list:
...@@ -398,7 +418,6 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list): ...@@ -398,7 +418,6 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
for cell_range in cell_range_list] for cell_range in cell_range_list]
) )
dimension = cell_dict['dimension']
mapped_value_argument_list = cell_dict['mapped_value_argument_list'] mapped_value_argument_list = cell_dict['mapped_value_argument_list']
def getMappedValueDict(item): def getMappedValueDict(item):
if len(mapped_value_argument_list)==1: if len(mapped_value_argument_list)==1:
...@@ -409,20 +428,36 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list): ...@@ -409,20 +428,36 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
result[argument_name] = item[index] result[argument_name] = item[index]
return result return result
# verify table structure to know dimension.
table = cell_dict['table'] table = cell_dict['table']
if dimension==1: if len([True for item in table if len(item)!=2])==0:
dimension = 1
elif len(table)>1 and (len(table[0])+1)==len(table[1]):
dimension = 2
elif isinstance(table[0][0], (tuple, list)):
dimension = 3
else:
raise RuntimeError, "Unsupported table structure!"
data_list = [] data_list = []
if dimension==1:
for table_line in table: for table_line in table:
data_list.append(([table_line[0]], getMappedValueDict(table_line[1]))) data_list.append(([table_line[0]], getMappedValueDict(table_line[1])))
elif dimension==2: elif dimension==2:
column = table[0] column = table[0]
data_list = []
for table_line in table[1:]: for table_line in table[1:]:
row = table_line[0] row = table_line[0]
for index, item in enumerate(table_line[1:]): for index, item in enumerate(table_line[1:]):
data_list.append(([row, column[index]], getMappedValueDict(item))) data_list.append(([row, column[index]], getMappedValueDict(item)))
elif dimension==3: elif dimension==3:
raise NotImplementedError table_list = table
for table in table_list:
tab = table[0][0]
column = table[1]
for table_line in table[2:]:
row = table_line[0]
for index, item in enumerate(table_line[1:]):
data_list.append(([row, column[index], tab], getMappedValueDict(item)))
for category_list, mapped_value_dict in data_list: for category_list, mapped_value_dict in data_list:
cell = line.newCell(portal_type=cell_type, cell = line.newCell(portal_type=cell_type,
......
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