Commit 842d5f60 authored by Jérome Perrin's avatar Jérome Perrin

pdm: supply line quantity unit WIP

parent 4f452ca4
......@@ -76,7 +76,22 @@ unit_base_price *= 1 + result["surcharge_ratio"]
# Divide by the priced quantity
priced_quantity = result['priced_quantity']
if priced_quantity:
# If this priced quantity is in a different quantity unit from the
# resource's default quantity unit, we have to convert this quantity
# to the resource quantity unit.
# For example, if we have a resource managed in Kilogram and we have
# a supply line saying that the price for 250 Grams is 100€, we adjust this
# priced quantity to be 0.25 (Kilogram)
supply_line_quantity_unit = next(iter(result.get('quantity_unit', ())), None)
resource_default_quantity_unit = context.getDefaultQuantityUnit()
if resource_default_quantity_unit != supply_line_quantity_unit:
priced_quantity = context.convertQuantity(
priced_quantity or 1,
supply_line_quantity_unit,
resource_default_quantity_unit,
movement.getVariationCategoryList()
)
if priced_quantity and priced_quantity != 1:
unit_base_price /= priced_quantity
result["price"] = unit_base_price
......
......@@ -35,9 +35,10 @@ if context.getParentValue().getParentValue().getPortalType() in (
#backwards compatibility
mapped_value_property_list = context.getMappedValuePropertyList()
if not 'priced_quantity' in mapped_value_property_list:
mapped_value_property_list.append('priced_quantity')
context.setMappedValuePropertyList(mapped_value_property_list)
for mapped_property in ('priced_quantity', 'quantity_unit'):
if not mapped_property in mapped_value_property_list:
mapped_value_property_list.append(mapped_property)
context.setMappedValuePropertyList(mapped_value_property_list)
# XXX: An hack that the context cell may not have the start_date_range_min/max properties.
# But they don't acquire it parent the properties.
......
......@@ -36,9 +36,10 @@ if context.getParentValue().getPortalType() in (
#backwards compatibility
mapped_value_property_list = context.getMappedValuePropertyList()
if not 'priced_quantity' in mapped_value_property_list:
mapped_value_property_list.append('priced_quantity')
context.setMappedValuePropertyList(mapped_value_property_list)
for mapped_property in ('priced_quantity', 'quantity_unit'):
if not mapped_property in mapped_value_property_list:
mapped_value_property_list.append(mapped_property)
context.setMappedValuePropertyList(mapped_value_property_list)
return context.generatePredicate(membership_criterion_base_category_list = base_category_tuple,
criterion_property_list = ('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