Commit c5bb555e authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Resource, DomainTool: support per slice price configuration in several supplies.

also update tests to check if a duplicated supply will not cause doubled price.
parent 1c5710e4
Pipeline #16380 failed with stage
in 0 seconds
...@@ -1184,6 +1184,10 @@ class TestResource(ERP5TypeTestCase): ...@@ -1184,6 +1184,10 @@ class TestResource(ERP5TypeTestCase):
supply_line = supply.newContent(portal_type=self.sale_supply_line_portal_type) supply_line = supply.newContent(portal_type=self.sale_supply_line_portal_type)
supply_line.setProductLineValue(self.portal.portal_categories.product_line.a) supply_line.setProductLineValue(self.portal.portal_categories.product_line.a)
supply_line.setBasePrice(1000) supply_line.setBasePrice(1000)
copy_data = supply.getParentValue().manage_copyObjects([supply.getId()])
new_id = supply.getParentValue().manage_pasteObjects(copy_data)[0]['new_id']
new_supply = supply.getParentValue()[new_id]
new_supply.validate()
supply.validate() supply.validate()
resource_a = self.portal.getDefaultModule(self.product_portal_type)\ resource_a = self.portal.getDefaultModule(self.product_portal_type)\
...@@ -1295,6 +1299,10 @@ class TestResource(ERP5TypeTestCase): ...@@ -1295,6 +1299,10 @@ class TestResource(ERP5TypeTestCase):
) )
sale_supply.validate() sale_supply.validate()
copy_data = sale_supply.getParentValue().manage_copyObjects([sale_supply.getId()])
new_id = sale_supply.getParentValue().manage_pasteObjects(copy_data)[0]['new_id']
new_sale_supply = sale_supply.getParentValue()[new_id]
new_sale_supply.validate()
self.tic() self.tic()
currency_module = self.portal.getDefaultModule("Currency") currency_module = self.portal.getDefaultModule("Currency")
......
...@@ -712,8 +712,8 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin): ...@@ -712,8 +712,8 @@ class Resource(XMLObject, XMLMatrix, VariatedMixin):
'non_discountable_additional_price': [], 'non_discountable_additional_price': [],
'priced_quantity': None, 'priced_quantity': None,
'base_unit_price': None, 'base_unit_price': None,
'slice_base_price': [], 'slice_base_price': None,
'slice_quantity_range': [], 'slice_quantity_range': None,
} }
if mapped_value is None: if mapped_value is None:
return price_parameter_dict return price_parameter_dict
......
...@@ -313,13 +313,26 @@ class DomainTool(BaseTool): ...@@ -313,13 +313,26 @@ class DomainTool(BaseTool):
predicate_list = self.searchPredicateList(context, test=test, **kw) predicate_list = self.searchPredicateList(context, test=test, **kw)
if predicate_list: if predicate_list:
mapped_value_property_dict = defaultdict(list) mapped_value_property_dict = defaultdict(list)
per_parent_mapped_value_property_dict = defaultdict(dict)
parent_sort_index = {}
# Look for each property the first predicate with unique criterion # Look for each property the first predicate with unique criterion
# categories which defines the property # categories which defines the property
for predicate in predicate_list: for predicate in predicate_list:
for mapped_value_property in predicate.getMappedValuePropertyList(): for mapped_value_property in predicate.getMappedValuePropertyList():
value = predicate.getProperty(mapped_value_property) value = predicate.getProperty(mapped_value_property)
if value is not None: if value is not None:
# For base price defined per slice, we need a list of values from matched cells
# grouped by parent supply line.
if mapped_value_property in ('slice_base_price', 'slice_quantity_range'):
parent_uid = predicate.getParentUid()
if parent_uid not in parent_sort_index:
parent_sort_index[parent_uid] = len(parent_sort_index)
per_parent_mapped_value_property_dict[mapped_value_property].setdefault(parent_uid, []).append(value)
else:
mapped_value_property_dict[mapped_value_property].append(value) mapped_value_property_dict[mapped_value_property].append(value)
for mapped_value_property, v in per_parent_mapped_value_property_dict.iteritems():
for _, mapped_value_list in sorted(v.iteritems(), key=lambda x: parent_sort_index[x[0]]):
mapped_value_property_dict[mapped_value_property].append(mapped_value_list)
mapped_value = self.getPortalObject().newContent(temp_object=True, mapped_value = self.getPortalObject().newContent(temp_object=True,
portal_type='Supply Cell', id='multivalued_mapped_value') portal_type='Supply Cell', id='multivalued_mapped_value')
mapped_value._setMappedValuePropertyList( mapped_value._setMappedValuePropertyList(
......
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