Commit 4b65e8d7 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: allow Supply Line to define price even if resource has variations

Force quantity unit to match (no convertion for now)
parent fc18ba29
supply = context.getParentValue() 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
if context.getPortalType() == 'Sale Supply Line': supply = context.getParentValue()
# If resource has variation, do not use the Line as a predicate
if context.getVariationRangeBaseCategoryList():
return None
base_category_tuple = ['resource', 'price_currency'] base_category_tuple = ['resource', 'price_currency', 'quantity_unit']
if context.getPortalType() == 'Sale Supply Cell': if context.getPortalType() == 'Sale Supply Cell':
base_category_tuple.extend(supply.getVariationRangeBaseCategoryList()) base_category_tuple.extend(supply.getVariationRangeBaseCategoryList())
supply = supply.getParentValue() supply = supply.getParentValue()
...@@ -14,7 +13,6 @@ if (supply.getPortalType() != 'Sale Supply') or (supply.getValidationState() != ...@@ -14,7 +13,6 @@ if (supply.getPortalType() != 'Sale Supply') or (supply.getValidationState() !=
# If this supply line is not in a validated Sale Supply, it does not apply. # If this supply line is not in a validated Sale Supply, it does not apply.
return None return None
if context.getSourceSection(): if context.getSourceSection():
base_category_tuple.append('source_section') base_category_tuple.append('source_section')
if context.getDestinationSection(): if context.getDestinationSection():
......
...@@ -21,7 +21,8 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin): ...@@ -21,7 +21,8 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin):
# - one with 2 releases and 2 types # - one with 2 releases and 2 types
simple_product = self.portal.software_product_module.newContent( simple_product = self.portal.software_product_module.newContent(
portal_type="Software Product", portal_type="Software Product",
title="Simple Product" title="Simple Product",
quantity_unit='time/month',
) )
simple_product.newContent( simple_product.newContent(
portal_type="Software Product Type Variation", portal_type="Software Product Type Variation",
...@@ -34,7 +35,8 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin): ...@@ -34,7 +35,8 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin):
complex_product = self.portal.software_product_module.newContent( complex_product = self.portal.software_product_module.newContent(
portal_type="Software Product", portal_type="Software Product",
title="Complex Product" title="Complex Product",
quantity_unit='time/month',
) )
complex_product.newContent( complex_product.newContent(
portal_type="Software Product Type Variation", portal_type="Software Product Type Variation",
...@@ -101,6 +103,7 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin): ...@@ -101,6 +103,7 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin):
title="%s without price" % software_product.getTitle(), title="%s without price" % software_product.getTitle(),
portal_type="Sale Supply Line", portal_type="Sale Supply Line",
resource_value=software_product, resource_value=software_product,
quantity_unit=software_product.getQuantityUnit(),
) )
sale_supply_line_list.append(sale_supply_line) sale_supply_line_list.append(sale_supply_line)
...@@ -110,13 +113,15 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin): ...@@ -110,13 +113,15 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin):
portal_type="Sale Supply Line", portal_type="Sale Supply Line",
resource_value=software_product, resource_value=software_product,
base_price=base_price, base_price=base_price,
quantity_unit=software_product.getQuantityUnit(),
) )
sale_supply_line_list.append(sale_supply_line) sale_supply_line_list.append(sale_supply_line)
sale_supply_line = sale_supply.newContent( sale_supply_line = sale_supply.newContent(
title="%s with variation" % software_product.getTitle(), title="%s with variation" % software_product.getTitle(),
portal_type="Sale Supply Line", portal_type="Sale Supply Line",
resource_value=software_product resource_value=software_product,
quantity_unit=software_product.getQuantityUnit(),
) )
sale_supply_line_list.append(sale_supply_line) sale_supply_line_list.append(sale_supply_line)
base_price += 1 base_price += 1
...@@ -162,6 +167,7 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin): ...@@ -162,6 +167,7 @@ class TestSlapOSSaleSupply(SlapOSTestCaseMixin):
portal_type='Movement', portal_type='Movement',
temp_object=1, temp_object=1,
resource_value=software_product, resource_value=software_product,
quantity_unit=software_product.getQuantityUnit(),
software_type_value=software_type, software_type_value=software_type,
software_release_value=software_release, software_release_value=software_release,
start_date=start_date, start_date=start_date,
......
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