Commit 73bdeb5d authored by Romain Courteaud's avatar Romain Courteaud

Improve the price calculation.

Does not work yet with options.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4311 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 423074be
...@@ -523,13 +523,53 @@ class Resource(XMLMatrix, CoreResource, Variated): ...@@ -523,13 +523,53 @@ class Resource(XMLMatrix, CoreResource, Variated):
has_cell_content=0, **kw) has_cell_content=0, **kw)
# Calculate the unit price # Calculate the unit price
unit_base_price = None unit_base_price = None
base_price = None # (base_price + SUM(addtional_price)) *
# (1 + SUM(surcharge_ratio)) *
# (1 - MIN(1, MAX(SUM(discount_ratio) , exclusive_discount_ratio ))))
# Get price parameters
price_parameter_dict = {
'base_price': None,
'additional_price': None,
'surcharge_ratio': None,
'discount_ratio': None,
'exclusive_discount_ratio': None,
}
if mapped_value is not None: if mapped_value is not None:
base_price = mapped_value.getBasePrice() for price_parameter_name in price_parameter_dict.keys():
price_parameter_dict[price_parameter_name] = \
mapped_value.getProperty(price_parameter_name)
# Calculate
base_price = price_parameter_dict['base_price']
if base_price in [None, '']: if base_price in [None, '']:
# XXX Compatibility
# base_price must not be defined on resource
base_price = self.getBasePrice() base_price = self.getBasePrice()
if base_price not in [None, '']: if base_price not in [None, '']:
unit_base_price = base_price
# Sum additional price
additional_price = price_parameter_dict['additional_price']
if additional_price not in [None, '']:
unit_base_price += additional_price
# Surcharge ratio
surcharge_ratio = price_parameter_dict['surcharge_ratio']
if surcharge_ratio not in [None, '']:
unit_base_price = unit_base_price * \
(1 + surcharge_ratio)
# Discount
discount_ratio = price_parameter_dict['discount_ratio']
exclusive_discount_ratio = \
price_parameter_dict['exclusive_discount_ratio']
d_ratio = 0
if discount_ratio not in [None, '']:
d_ratio = max(d_ratio, discount_ratio)
if exclusive_discount_ratio not in [None, '']:
d_ratio = max(d_ratio, exclusive_discount_ratio)
if d_ratio != 0:
d_ratio = 1 - min(1, d_ratio)
unit_base_price = unit_base_price * d_ratio
# Divide by the priced quantity
if unit_base_price is not None:
priced_quantity = self.getPricedQuantity() priced_quantity = self.getPricedQuantity()
unit_base_price = base_price / priced_quantity unit_base_price = unit_base_price / priced_quantity
# Return result # Return result
return unit_base_price return unit_base_price
...@@ -472,93 +472,72 @@ class TestResource(ERP5TypeTestCase): ...@@ -472,93 +472,72 @@ class TestResource(ERP5TypeTestCase):
config = [ config = [
{ {
'base_price': None, 'base_price': None,
'additional_price': [], 'additional_price': None,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [], 'discount_ratio': None,
'exclusive_discount_ratio': None, 'exclusive_discount_ratio': None,
'price': None, 'price': None,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [], 'additional_price': None,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [], 'discount_ratio': None,
'exclusive_discount_ratio': None, 'exclusive_discount_ratio': None,
'price': 5, 'price': 5,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1], 'additional_price': 1,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [], 'discount_ratio': None,
'exclusive_discount_ratio': None, 'exclusive_discount_ratio': None,
'price': 6, 'price': 6,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [], 'surcharge_ratio': 0.5,
'discount_ratio': [], 'discount_ratio': None,
'exclusive_discount_ratio': None,
'price': 8,
},{
'base_price': 5,
'additional_price': [1, 2],
'surcharge_ratio': [0.5],
'discount_ratio': [],
'exclusive_discount_ratio': None, 'exclusive_discount_ratio': None,
'price': 12, 'price': 12,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [0.5, 0.5], 'surcharge_ratio': None,
'discount_ratio': [], 'discount_ratio': 0.25,
'exclusive_discount_ratio': None,
'price': 16,
},{
'base_price': 5,
'additional_price': [1, 2],
'surcharge_ratio': [],
'discount_ratio': [0.25],
'exclusive_discount_ratio': None, 'exclusive_discount_ratio': None,
'price': 6, 'price': 6,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [0.25, 0.25], 'discount_ratio': None,
'exclusive_discount_ratio': None,
'price': 5,
},{
'base_price': 5,
'additional_price': [1, 2],
'surcharge_ratio': [],
'discount_ratio': [],
'exclusive_discount_ratio': 0.5, 'exclusive_discount_ratio': 0.5,
'price': 4, 'price': 4,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [0.25, 0.25], 'discount_ratio': 0.5,
'exclusive_discount_ratio': 0.75, 'exclusive_discount_ratio': 0.75,
'price': 2, 'price': 2,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [], 'surcharge_ratio': None,
'discount_ratio': [0.25, 0.5], 'discount_ratio': 0.75,
'exclusive_discount_ratio': 0.25, 'exclusive_discount_ratio': 0.25,
'price': 2, 'price': 2,
},{ },{
'base_price': 5, 'base_price': 5,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [1], 'surcharge_ratio': 1,
'discount_ratio': [0.25, 0.5], 'discount_ratio': 0.75,
'exclusive_discount_ratio': 0.25, 'exclusive_discount_ratio': 0.25,
'price': 3, 'price': 4,
},{ },{
'base_price': None, 'base_price': None,
'additional_price': [1, 2], 'additional_price': 3,
'surcharge_ratio': [1], 'surcharge_ratio': 1,
'discount_ratio': [0.25, 0.5], 'discount_ratio': 0.75,
'exclusive_discount_ratio': 0.25, 'exclusive_discount_ratio': 0.25,
'price': None, 'price': None,
} }
...@@ -603,8 +582,8 @@ class TestResource(ERP5TypeTestCase): ...@@ -603,8 +582,8 @@ class TestResource(ERP5TypeTestCase):
supply_line = product.newContent( supply_line = product.newContent(
portal_type=self.supply_line_portal_type) portal_type=self.supply_line_portal_type)
# Set pricing parameter # Set pricing parameter
self.logMessage("Set %s on supply line with value %i..." % \ self.logMessage("Set %s on supply line with value %s..." % \
(key, pricing_param), tab=1) (key, str(pricing_param)), tab=1)
supply_line.setProperty(key, pricing_param) supply_line.setProperty(key, pricing_param)
# Commit transaction # Commit transaction
self.logMessage("Commit transaction...", tab=1) self.logMessage("Commit transaction...", tab=1)
...@@ -615,11 +594,6 @@ class TestResource(ERP5TypeTestCase): ...@@ -615,11 +594,6 @@ class TestResource(ERP5TypeTestCase):
# Check resource price # Check resource price
self.logMessage("Check product price...", tab=1) self.logMessage("Check product price...", tab=1)
self.assertEquals(config['price'], product.getPrice()) self.assertEquals(config['price'], product.getPrice())
# try:
# self.assertEquals(config['price'], product.getPrice())
# except:
# import pdb
# pdb.set_trace()
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
......
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