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):
dicts in cell_dict_list can have following keys:
- base_id
- cell_range_kw
- dimension
- mapped_value_argument_list
- table
......@@ -368,13 +367,34 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
'DeliveryLine_asCellRange',
({'base_id':'movement',
'mapped_value_argument_list':('quantity',),
'dimension':1,
'table':(('product_packing/package', 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):
if not range_list:
......@@ -398,7 +418,6 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
for cell_range in cell_range_list]
)
dimension = cell_dict['dimension']
mapped_value_argument_list = cell_dict['mapped_value_argument_list']
def getMappedValueDict(item):
if len(mapped_value_argument_list)==1:
......@@ -409,20 +428,36 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
result[argument_name] = item[index]
return result
# verify table structure to know dimension.
table = cell_dict['table']
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 = []
if dimension==1:
data_list = []
for table_line in table:
data_list.append(([table_line[0]], getMappedValueDict(table_line[1])))
elif dimension==2:
column = table[0]
data_list = []
for table_line in table[1:]:
row = table_line[0]
for index, item in enumerate(table_line[1:]):
data_list.append(([row, column[index]], getMappedValueDict(item)))
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:
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