Commit 87be239f authored by Romain Courteaud's avatar Romain Courteaud 🐙

slapos_accounting:

* configure Sale Supply predicate
* test Supply Line matching and getPrice
* allow Supply Line to define price even if resource has variations
  Force quantity unit to match (no convertion for now)
* order Supply Predicate matching
* Supply Cell before Line
parent 34bc30c7
......@@ -6,11 +6,13 @@ def sort_key_method(e):
having source_function only
others
"""
return 0
parent = e.getParentValue()
if parent.getPortalType().endswith('Line'):
parent = parent.getParentValue()
return 0 - 1 * int(parent.hasSourceFunction()) - 2 * int(parent.hasGroup())
minus = 0.5
else:
minus = 0
return 0 - 1 * int(parent.hasDestination()) - minus
def filter_method(currency, destination_project, group):
def filter_by_source_function_and_group(l):
......@@ -38,6 +40,7 @@ def filter_method(currency, destination_project, group):
#if parent.getGroup() not in (None, group):
# continue
ret.append(i)
return ret
return filter_by_source_function_and_group
source = context.getSourceValue()
......@@ -47,13 +50,6 @@ else:
group = source.getGroup()
kw['filter_method'] = filter_method(context.getPriceCurrency(), context.getDestinationProject(), group)
"""
def filter_couscous(predicate_list):
raise NotImplementedError(predicate_list)
return predicate_list
kw['filter_method'] = filter_couscous
"""
kw['sort_key_method'] = sort_key_method
resource = context.getResourceValue()
......@@ -63,7 +59,6 @@ if resource is not None:
if product_line:
kw['categories'] = kw.get('categories', []) + ['product_line/%s' % product_line]
#raise NotImplementedError(str(kw))
return resource.getPriceCalculationOperandDict(
default=default, context=context, **kw)
......
<?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>*args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleSupplyCell_asPredicate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
parent = context.getParentValue()
if (parent.getPortalType() != 'Sale Supply') or (parent.getValidationState() != 'validated'):
# If this supply line is not in a validated Sale Supply, it does not apply.
if (not context.hasBasePrice()) or (not context.getPriceCurrency()) or (not context.getResource()) or (not context.getQuantityUnit()):
# Meaningless path if no resource/price_currency/base_price/quantity_unit
return None
supply = context.getParentValue()
base_category_tuple = ['resource', 'price_currency', 'quantity_unit']
if context.getPortalType() == 'Sale Supply Cell':
base_category_tuple.extend(supply.getVariationRangeBaseCategoryList())
supply = supply.getParentValue()
base_category_tuple = ('resource', 'price_currency')
if (supply.getPortalType() != 'Sale Supply') or (supply.getValidationState() != 'validated'):
# If this supply line is not in a validated Sale Supply, it does not apply.
return None
if context.getSourceSection():
base_category_tuple += ('source_section',)
base_category_tuple.append('source_section')
if context.getDestinationSection():
base_category_tuple += ('destination_section',)
base_category_tuple.append('destination_section')
if context.getSource():
base_category_tuple += ('source',)
base_category_tuple.append('source')
if context.getDestination():
base_category_tuple += ('destination',)
base_category_tuple.append('destination')
if context.getSourceProject():
base_category_tuple += ('source_project',)
base_category_tuple.append('source_project')
if context.getDestinationProject():
base_category_tuple += ('destination_project',)
base_category_tuple.append('destination_project')
#backwards compatibility
mapped_value_property_list = context.getMappedValuePropertyList()
......
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupplyLine_asPredicate</string> </value>
<value> <string>SaleSupplyLine_asPredicate</string> </value>
</item>
</dictionary>
</pickle>
......
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