Commit da0990b9 authored by Vincent Pelletier's avatar Vincent Pelletier

erp5_pdm: Fix Supply Cell update when {en,dis}abling sliced pricing.

Deleting matrix cells with manage_delObjects is not a good solution, as
this breaks matrix index consistency.
Also, call isBasePricePerSlice rather than introspecting wrapped method
arguments - the only wrapped method is _setBasePricePerSlice anyway !
Also, explicitly trigger SupplyCell_updateSliceBasePrice as it depends on
isBasePricePerSlice value at line level, and it just changed, and cell-level
interaction workflow does not trigger on line changes.
Also, get rid of a trivial local variable.
Also, fix the exception expected from list.index .
Also, raise if multiple quantity criterion are somehow found.
parent 7a4db2aa
Pipeline #7471 passed with stage
in 0 seconds
quantity_criterion_list = [
criterion for criterion in context.getCriterionList()
if criterion.property == 'quantity'
]
if not quantity_criterion_list:
return
quantity_criterion, = quantity_criterion_list
supply_line_value = context.getParentValue()
if supply_line_value.isBasePricePerSlice():
quantity_step_list = [None] + supply_line_value.getQuantityStepList(base_id='path') + [None]
try:
index = quantity_step_list.index(quantity_criterion.min)
except ValueError:
# _range_criterion is set to {} if criterion is None
index = 0
min_quantity = quantity_step_list[index]
max_quantity = quantity_step_list[index+1]
context.setSliceQuantityRange((min_quantity, max_quantity))
context.setSliceBasePrice(context.getBasePrice())
else:
context.setSliceQuantityRange(None)
context.setSliceBasePrice(None)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupplyCell_updateSliceBasePrice</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
supply_cell = state_change['object'] state_change['object'].SupplyCell_updateSliceBasePrice()
supply_line = supply_cell.getParentValue()
quantity_criterion_list = [
criterion for criterion in supply_cell.getCriterionList()
if criterion.property == 'quantity'
]
if len(quantity_criterion_list) == 1:
quantity_criterion = quantity_criterion_list[0]
else:
return
if supply_cell.getParentValue().isBasePricePerSlice():
quantity_step_list = [None] + supply_line.getQuantityStepList(base_id='path') + [None]
try:
index = quantity_step_list.index(quantity_criterion.min)
except KeyError:
# _range_criterion is set to {} if criterion is None
index = 0
min_quantity = quantity_step_list[index]
max_quantity = quantity_step_list[index+1]
supply_cell.setSliceQuantityRange((min_quantity, max_quantity))
supply_cell.setSliceBasePrice(supply_cell.getBasePrice())
else:
supply_cell.setSliceQuantityRange(None)
supply_cell.setSliceBasePrice(None)
supply_line = state_change['object'] supply_line = state_change['object']
to_delete_cell_list = [ supply_line.updateQuantityPredicate(
cell for cell in supply_line.getCellIdList(base_id='path') 'slice_base_price'
if hasattr(supply_line, cell) if supply_line.isBasePricePerSlice() else
] 'base_price'
supply_line.manage_delObjects(ids=to_delete_cell_list) )
if state_change.kwargs['workflow_method_args'][0]:
price_parameter = 'slice_base_price'
else:
price_parameter = 'base_price'
supply_line.updateQuantityPredicate(price_parameter)
supply_line.updateCellRange(base_id='path') supply_line.updateCellRange(base_id='path')
for cell_value in supply_line.getCellValueList(base_id='path'):
cell_value.SupplyCell_updateSliceBasePrice()
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