Adapt compute method for specific Namur use-case...

This commit is contained in:
Christophe Boulanger 2017-06-14 15:27:09 +02:00
parent 8510f9f26b
commit e87c1af3ba
1 changed files with 8 additions and 3 deletions

View File

@ -38,14 +38,19 @@ class ExtraFees(BaseResource):
data = json.loads(request.body) data = json.loads(request.body)
nb_documents = 0 nb_documents = 0
# Balaie chaque elem du panier.
for basket_item in data['data']: for basket_item in data['data']:
nb_letter = 0
postage_fee = Decimal('0.74')
max_doc_in_letter = 5
try: try:
nb_documents += int(basket_item['request_data']['nb_documents']) nb_documents += int(basket_item['request_data']['nb_documents'])
if Decimal(basket_item['request_data']['country_price']) > postage_fee:
postage_fee = Decimal(basket_item['request_data']['country_price'])
except KeyError: except KeyError:
# basket item not associated with any document, no fee # basket item not associated with any document, no fee
pass pass
nb_letter = int(nb_documents / max_doc_in_letter) + (((nb_documents % max_doc_in_letter) > 0) and 1 or 0)
# compute fee # compute fee
postage_fee = 3 + nb_documents * 1 postage_fee = nb_letter * postage_fee
return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]} return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]}