Namur : Add some 'bad' exceptions because Ingenico doesn't support multi regie.

This commit is contained in:
Christophe Boulanger 2017-11-06 18:02:20 +01:00
parent 6d37e7809e
commit a7fbd6b441
1 changed files with 29 additions and 8 deletions

View File

@ -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)}]}