Commit 8ed6f61e authored by Yusei Tahara's avatar Yusei Tahara

Update updateCellList. Support simpler data structure to add cells.

parent 8cf0df19
......@@ -475,6 +475,7 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
- cell_range_kw
- mapped_value_argument_list
- table
- variation_category_list_and_mapped_value_list (optional)
Example:
updateCellList(sale_order_line_1_1,
......@@ -523,6 +524,12 @@ def updateCellList(portal, line, cell_type, cell_range_method, cell_dict_list):
)
)
Also you can pass variation_category_list_and_mapped_value_list. Then you do not
have touse above table structure. variation_category_list_and_mapped_value_list
structure should be like following:
((variation_category_list, mapped_value),
(variation_category_list, mapped_value),
(variation_category_list, mapped_value),)
"""
def get_range_id_list(range_list):
if not range_list:
......@@ -569,37 +576,41 @@ 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:
for table_line in table:
data_list.append(([table_line[0]], getMappedValueDict(table_line[1])))
elif dimension==2:
column = table[0]
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:
table_list = table
for table in table_list:
tab_list = list(table[0])
tab_list.reverse()
column = table[1]
for table_line in table[2:]:
if cell_dict.get('variation_category_list_and_mapped_value_list'):
for variation_category_list, mapped_value in cell_dict.get('variation_category_list_and_mapped_value_list'):
data_list.append((variation_category_list, getMappedValueDict(mapped_value)))
else:
# 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!"
if dimension==1:
for table_line in table:
data_list.append(([table_line[0]], getMappedValueDict(table_line[1])))
elif dimension==2:
column = table[0]
for table_line in table[1:]:
row = table_line[0]
for index, item in enumerate(table_line[1:]):
data_list.append(([row, column[index]] + tab_list, getMappedValueDict(item)))
data_list.append(([row, column[index]], getMappedValueDict(item)))
elif dimension==3:
table_list = table
for table in table_list:
tab_list = list(table[0])
tab_list.reverse()
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_list, getMappedValueDict(item)))
for category_list, mapped_value_dict in data_list:
category_list = getSortedCategoryList(line, base_id, category_list)
......
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