Commit 10b2144b authored by Romain Courteaud's avatar Romain Courteaud 🐙

slapos_accounting: get price from sale supply

parent 23271cbf
...@@ -158,41 +158,10 @@ if instance_tree.getCausalityState() == 'diverged': ...@@ -158,41 +158,10 @@ if instance_tree.getCausalityState() == 'diverged':
if specialise is not None: if specialise is not None:
assert open_order.getSpecialise() == specialise assert open_order.getSpecialise() == specialise
predicate_list = []
log_predicate_list = []
inherited_trade_condition = open_sale_order.getSpecialiseValue()
if specialise is None:
# XXX Comment on instance tree that no open can be created
# XXX ensure no open order has been created
assert inherited_trade_condition is not None
while inherited_trade_condition is not None:
predicate_list.extend([
x for x in inherited_trade_condition.contentValues(portal_type='Sale Supply Line')
if x.getResource() == service.getRelativeUrl()
])
log_predicate_list.extend([
x for x in inherited_trade_condition.contentValues(portal_type='Sale Supply Line')
])
inherited_trade_condition = inherited_trade_condition.getSpecialiseValue(portal_type=inherited_trade_condition.getPortalType())
price = service.getPrice(
context=open_order_line,
predicate_list=predicate_list,
default=None,
)
if price is None:
raise NotImplementedError('Price not found on %s (%s) for %s %s - %s' % (
open_sale_order.getSpecialiseTitle(),
open_sale_order.getSpecialise(),
service.getRelativeUrl(),
str([x.getRelativeUrl() for x in predicate_list]),
str([(x.getRelativeUrl(), x.getResource()) for x in log_predicate_list]),
))
open_order_cell.edit( open_order_cell.edit(
price=price price=open_order_cell.getPrice()
) )
# XXX XXX XXX assert open_order_cell.getPrice() is not None
storeWorkflowComment(open_order_line, "Created for %s" % instance_tree.getRelativeUrl()) storeWorkflowComment(open_order_line, "Created for %s" % instance_tree.getRelativeUrl())
# instance_tree.converge(comment="Last open order: %s" % open_sale_order_line.getRelativeUrl()) # instance_tree.converge(comment="Last open order: %s" % open_sale_order_line.getRelativeUrl())
......
...@@ -12,7 +12,7 @@ def sort_key_method(e): ...@@ -12,7 +12,7 @@ def sort_key_method(e):
parent = parent.getParentValue() parent = parent.getParentValue()
return 0 - 1 * int(parent.hasSourceFunction()) - 2 * int(parent.hasGroup()) return 0 - 1 * int(parent.hasSourceFunction()) - 2 * int(parent.hasGroup())
def filter_method(source_function, group): def filter_method(currency, destination_project, group):
def filter_by_source_function_and_group(l): def filter_by_source_function_and_group(l):
ret = [] ret = []
for i in l: for i in l:
...@@ -20,8 +20,8 @@ def filter_method(source_function, group): ...@@ -20,8 +20,8 @@ def filter_method(source_function, group):
if parent.getPortalType().endswith('Line'): if parent.getPortalType().endswith('Line'):
parent = parent.getParentValue() parent = parent.getParentValue()
# Price should be set in Sale Supply only. # Price should be set in Sale Supply only.
#if parent.getPortalType() != 'Sale Supply' and parent.getParentValue().getPortalType() != 'Sale Supply': if parent.getPortalType() != 'Sale Supply' and parent.getParentValue().getPortalType() != 'Sale Supply':
# continue continue
date = context.getStartDate() date = context.getStartDate()
# Check if effective # Check if effective
if parent.hasStartDateRangeMin() and date < parent.getStartDateRangeMin(): if parent.hasStartDateRangeMin() and date < parent.getStartDateRangeMin():
...@@ -29,8 +29,10 @@ def filter_method(source_function, group): ...@@ -29,8 +29,10 @@ def filter_method(source_function, group):
# Check if not expired # Check if not expired
if parent.hasStartDateRangeMax() and date > parent.getStartDateRangeMax(): if parent.hasStartDateRangeMax() and date > parent.getStartDateRangeMax():
continue continue
# Sale Supply having a different source_function should not be applied. # Sale Supply having a different destination_project should not be applied.
if parent.getSourceFunction() not in (None, source_function): if parent.getDestinationProject() != destination_project:
continue
if parent.getPriceCurrency() != currency:
continue continue
# XXX Sale Supply having a different group should not be applied. # XXX Sale Supply having a different group should not be applied.
#if parent.getGroup() not in (None, group): #if parent.getGroup() not in (None, group):
...@@ -43,7 +45,7 @@ if source is None: ...@@ -43,7 +45,7 @@ if source is None:
group = None group = None
else: else:
group = source.getGroup() group = source.getGroup()
kw['filter_method'] = filter_method(context.getSourceFunction(), group) kw['filter_method'] = filter_method(context.getPriceCurrency(), context.getDestinationProject(), group)
""" """
def filter_couscous(predicate_list): def filter_couscous(predicate_list):
......
parent = context.getParentValue() parent = context.getParentValue()
if (parent.getPortalType() != 'Sale Trade Condition') or (parent.getValidationState() != 'validated'): if (parent.getPortalType() != 'Sale Supply') or (parent.getValidationState() != 'validated'):
# If this supply line is not in a validated trade condition, it does not apply. # If this supply line is not in a validated Sale Supply, it does not apply.
return None return None
...@@ -21,14 +21,6 @@ if context.getSourceProject(): ...@@ -21,14 +21,6 @@ if context.getSourceProject():
if context.getDestinationProject(): if context.getDestinationProject():
base_category_tuple += ('destination_project',) base_category_tuple += ('destination_project',)
# Supply Lines from trade conditions are set as specialise to this trade condition,
# so that we can apply a predicate on movements later. Supply Lines from trade condition
# only apply on movements using these trade conditions.
category_list = context.getCategoryList() + ['specialise/%s' % context.getParentValue().getRelativeUrl()]
context = context.asContext(categories=category_list)
base_category_tuple += ('specialise', )
#backwards compatibility #backwards compatibility
mapped_value_property_list = context.getMappedValuePropertyList() mapped_value_property_list = context.getMappedValuePropertyList()
for mapped_property in ('priced_quantity', 'quantity_unit'): for mapped_property in ('priced_quantity', 'quantity_unit'):
......
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