summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Boulanger <christophe.boulanger@imio.be>2017-11-06 17:02:20 (GMT)
committerChristophe Boulanger <christophe.boulanger@imio.be>2017-11-06 17:02:20 (GMT)
commita7fbd6b4415133ca84fa6fe3c2dd6890a342063c (patch)
tree47beb18b08874972e6be018c03d3ad6fef749f1d
parent6d37e7809e7f64c6712f14fcee06d8e8e5232c93 (diff)
downloadpasserelle-imio-extra-fees-a7fbd6b4415133ca84fa6fe3c2dd6890a342063c.zip
passerelle-imio-extra-fees-a7fbd6b4415133ca84fa6fe3c2dd6890a342063c.tar.gz
passerelle-imio-extra-fees-a7fbd6b4415133ca84fa6fe3c2dd6890a342063c.tar.bz2
Namur : Add some 'bad' exceptions because Ingenico doesn't support multi regie.
-rw-r--r--passerelle_imio_extra_fees/models.py37
1 files changed, 29 insertions, 8 deletions
diff --git a/passerelle_imio_extra_fees/models.py b/passerelle_imio_extra_fees/models.py
index 8402ac2..a6dbb66 100644
--- a/passerelle_imio_extra_fees/models.py
+++ b/passerelle_imio_extra_fees/models.py
@@ -36,20 +36,41 @@ class ExtraFees(BaseResource):
@endpoint(methods=['post'])
def compute(self, request, **kwargs):
data = json.loads(request.body)
+ # EXCEPTIONS :
+ # duplicata-de-livret-de-mariage (frais port 8 ou 13)
+ #
+ duplicata_exception = False
+ changement_adresse_exception = False
+ duplicata_country_price = Decimal('0.00')
+ duplicata_nb_doc = 0
max_doc_in_letter = 5
nb_documents = 0
nb_letter = 0
# Balaie chaque elem du panier.
for basket_item in data['data']:
- postage_fee = Decimal('0.74')
- 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
+ if 'duplicata-de-livret-de-mariage' in basket_item['request_data']['form_slug']:
+ duplicata_exception = True
+ duplicata_country_price = Decimal(basket_item['request_data']['country_price'])
+ duplicata_nb_doc = int(basket_item['request_data']['nb_documents'])
+
+ for basket_item in data['data']:
+ if 'duplicata-de-livret-de-mariage' not in basket_item['request_data']['form_slug']:
+ postage_fee = Decimal('0.74')
+ 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'])
+ if 'demande-de-changement-d-adresse-domicile' in basket_item['request_data']['form_slug'] and nb_documents > 1:
+ changement_adresse_exception = True
+ nb_documents = nb_documents - 1
+ 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 = nb_letter * postage_fee
+ if duplicata_exception is True:
+ postage_fee = duplicata_country_price if duplicata_country_price > postage_fee else postage_fee
+ if changement_adresse_exception == True and nb_documents <= 1:
+ postage_fee = Decimal('0.00')
return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]}