Commit 05f913a0 by Nicolas Wavrant

### Price per quantity per slice

This MR introduces a second way of calculating the base price of a resource using "Base Price Quantity Step".

Currently, for a resource, we could define on a Supply Line "Quantity Steps",  and set a price for each of these steps. Then, depending on the quantity of the resource, the price of the unique matching step would apply.

For exemple :

| Quantity Step Range | Price for the step|
|------------|---------|
| 0 -> 10 | 10€ |
| 11 -> 20 | 9€ |
| 21 -> inf | 8€ |

With the current method, for an Order of 15 products, the 2 range "11 -> 20" would apply, the unit price for the products would be 9€, and the total price would be 15*9 = 135€.

The new method of calculating would apply the _Price for the step_ __to, and only to, all items of this step__. Which means, for an order of 15 products, the 10 first products would have a unit price of 10€, and the 5 next products would have a unit price of 9€, which makes in the end a total price of 145€, and a base price of 9.66€.

/reviewed-on !896
parents db0ee9b5 334b21a7
 ... ... @@ -8,6 +8,10 @@ edit_workflow, validation_workflow Internal Supply Cell supply_cell_interaction_workflow Internal Supply Line edit_workflow, reindex_object_interaction_workflow, supply_line_interaction_workflow ... ... @@ -24,6 +28,10 @@ edit_workflow, validation_workflow Purchase Supply Cell supply_cell_interaction_workflow Purchase Supply Line edit_workflow, reindex_object_interaction_workflow, supply_line_interaction_workflow ... ... @@ -44,6 +52,10 @@ edit_workflow, validation_workflow Sale Supply Cell supply_cell_interaction_workflow Sale Supply Line edit_workflow, reindex_object_interaction_workflow, supply_line_interaction_workflow ... ... @@ -52,6 +64,10 @@ edit_workflow, validation_workflow Supply Cell supply_cell_interaction_workflow Supply Line edit_workflow, reindex_object_interaction_workflow, supply_line_interaction_workflow ... ...
 ... ... @@ -226,6 +226,7 @@ my_max_order_quantity_variation_base_category_list matrixbox_for_max_order_quantity my_view_mode_target_delivery my_base_price_per_slice ... ...
 delegated_list title id my_base_price_per_slice message_values external_validator_failed The input failed the external validator. overrides field_id form_id tales field_id form_id values field_id my_checkbox form_id Base_viewFieldLibrary title Base Price Applies to Items in Slice
 ... ... @@ -11,7 +11,6 @@ css_class default external_validator title width ... ... @@ -57,10 +56,12 @@ default AAAAAAAAAAI= css_class external_validator field_id ... ... @@ -74,6 +75,14 @@ target title width ... ... @@ -86,15 +95,9 @@ figure default external_validator AAAAAAAAAAM= AAAAAAAAAAI= ... ... @@ -125,19 +128,6 @@ _text python:[str(x) for x in here.getQuantityStepList()] ... ...
 ... ... @@ -106,6 +106,7 @@ my_price_currency my_start_date_range_min my_start_date_range_max my_base_price_per_slice ... ...
 ... ... @@ -9,7 +9,9 @@ delegated_list default ... ... @@ -51,6 +53,12 @@ default AAAAAAAAAAI= field_id ... ... @@ -70,6 +78,14 @@ default base_price field_id my_mapped_value_property_list ... ... @@ -87,4 +103,17 @@ _text python: [\'base_price\', \'base_unit_price\', \'slice_base_price\', \'slice_quantity_range\']
 delegated_list id my_base_price_per_slice message_values external_validator_failed The input failed the external validator. overrides field_id form_id tales field_id form_id values field_id my_base_price_per_slice form_id Base_viewPDMFieldLibrary
 ... ... @@ -106,6 +106,7 @@ my_price_currency my_start_date_range_min my_start_date_range_max my_base_price_per_slice ... ...
 delegated_list id my_base_price_per_slice message_values external_validator_failed The input failed the external validator. overrides field_id form_id tales field_id form_id values field_id my_base_price_per_slice form_id Base_viewPDMFieldLibrary
 from math import log result = context.getPriceParameterDict(context=movement, **kw) # Calculate # If slice_base_price: # base_price = SUM(number_of_items_in_slice * slice_base_price) for each slice # Then # ((base_price + SUM(additional_price) + # variable_value * SUM(variable_additional_price)) * # (1 - MIN(1, MAX(SUM(discount_ratio) , exclusive_discount_ratio ))) + ... ... @@ -17,6 +22,23 @@ result = context.getPriceParameterDict(context=movement, **kw) # depends on discrete variations, but also on a continuous property # of the object if result["slice_base_price"]: total_price = 0. quantity = movement.getQuantity() sliced_base_price_list = zip(result["slice_base_price"], result["slice_quantity_range"]) for slice_price, slice_range in sliced_base_price_list: slice_min, slice_max = slice_range if slice_max is None: slice_max = quantity + 1 if slice_min is None: slice_min = 1 priced_quantity = min(slice_max - 1, quantity) - (slice_min - 1) total_price += priced_quantity * slice_price if result.get('base_unit_price', None) is None: result["base_price"] = total_price / quantity else: result["base_price"] = round(total_price / quantity, int(round(- log(result['base_unit_price'], 10),0))) base_price = result["base_price"] if base_price in (None, ""): # XXX Compatibility ... ...
 ... ... @@ -116,6 +116,7 @@ my_internal_supply_line_max_flow my_internal_supply_line_min_stock my_internal_supply_line_max_stock my_internal_supply_line_base_price_per_slice ... ...
 ... ... @@ -9,7 +9,9 @@ delegated_list default ... ... @@ -70,6 +72,17 @@ default base_price base_unit_price slice_base_price slice_quantity_range field_id my_mapped_value_property_list ... ...
 delegated_list id my_internal_supply_line_base_price_per_slice message_values external_validator_failed The input failed the external validator. overrides field_id form_id tales field_id form_id values field_id my_base_price_per_slice form_id Base_viewPDMFieldLibrary
 ... ... @@ -116,6 +116,7 @@ my_purchase_supply_line_max_flow my_purchase_supply_line_min_stock my_purchase_supply_line_max_stock my_purchase_supply_line_base_price_per_slice ... ...
 ... ... @@ -9,7 +9,9 @@ delegated_list default ... ... @@ -70,6 +72,17 @@ default base_price base_unit_price slice_base_price slice_quantity_range field_id my_mapped_value_property_list ... ...
 delegated_list id my_purchase_supply_line_base_price_per_slice message_values external_validator_failed The input failed the external validator.