summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Boulanger <christophe.boulanger@imio.be>2017-06-14 13:27:09 (GMT)
committerChristophe Boulanger <christophe.boulanger@imio.be>2017-06-14 13:27:09 (GMT)
commite87c1af3bacc141460a401ff03b5531663f935de (patch)
tree0b8b75a1830b51d1c98f06677552f886c37399d8
parent8510f9f26bc5a3b59cc0106e28131fe2774820a1 (diff)
downloadpasserelle-imio-extra-fees-e87c1af3bacc141460a401ff03b5531663f935de.zip
passerelle-imio-extra-fees-e87c1af3bacc141460a401ff03b5531663f935de.tar.gz
passerelle-imio-extra-fees-e87c1af3bacc141460a401ff03b5531663f935de.tar.bz2
Adapt compute method for specific Namur use-case...v0.1
-rw-r--r--passerelle_imio_extra_fees/models.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/passerelle_imio_extra_fees/models.py b/passerelle_imio_extra_fees/models.py
index 99b2e31..d8f235e 100644
--- a/passerelle_imio_extra_fees/models.py
+++ b/passerelle_imio_extra_fees/models.py
@@ -38,14 +38,19 @@ class ExtraFees(BaseResource):
data = json.loads(request.body)
nb_documents = 0
+ # Balaie chaque elem du panier.
for basket_item in data['data']:
+ nb_letter = 0
+ postage_fee = Decimal('0.74')
+ max_doc_in_letter = 5
try:
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:
# basket item not associated with any document, no fee
pass
-
+ nb_letter = int(nb_documents / max_doc_in_letter) + (((nb_documents % max_doc_in_letter) > 0) and 1 or 0)
# compute fee
- postage_fee = 3 + nb_documents * 1
-
+ postage_fee = nb_letter * postage_fee
return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]}