summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Muyshond <daniel.muyshond@gmail.com>2020-10-06 14:08:28 (GMT)
committerDaniel Muyshond <daniel.muyshond@gmail.com>2020-10-06 14:08:28 (GMT)
commit1bf9c6b0e9dccea546e9d3127ebf30690b229520 (patch)
treea8a5a75898a15242341cba167ce0522f9b53cb91
parent7d970bf325dffd4a335570bb2941c1b479057ba7 (diff)
downloadpasserelle-imio-extra-fees-1bf9c6b0e9dccea546e9d3127ebf30690b229520.zip
passerelle-imio-extra-fees-1bf9c6b0e9dccea546e9d3127ebf30690b229520.tar.gz
passerelle-imio-extra-fees-1bf9c6b0e9dccea546e9d3127ebf30690b229520.tar.bz2
[TELE-694] fix bad indent error + pep8 reformat
-rw-r--r--passerelle_imio_extra_fees/models.py55
1 files changed, 31 insertions, 24 deletions
diff --git a/passerelle_imio_extra_fees/models.py b/passerelle_imio_extra_fees/models.py
index 668df2f..434d8a4 100644
--- a/passerelle_imio_extra_fees/models.py
+++ b/passerelle_imio_extra_fees/models.py
@@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.encoding import force_text
@@ -28,20 +27,25 @@ from passerelle.compat import json_loads
from passerelle.utils.api import endpoint
from decimal import Decimal
+
class ExtraFees(BaseResource):
category = _('Misc')
PROFILE_CHOICES = (
- ('DEFAULT','Default'),
- ('NAMUR','Namur'),
+ ('DEFAULT', 'Default'),
+ ('NAMUR', 'Namur'),
)
profile = models.CharField(max_length=30, choices=PROFILE_CHOICES, default='Default')
- max_doc_in_letter = models.PositiveSmallIntegerField(verbose_name=_('Maximum documents in one letter'),
- default=5,
- validators=[MaxValueValidator(100), MinValueValidator(1)])
- belgium_postage_fee = models.DecimalField(decimal_places=2, max_digits=6, verbose_name=_('Postage fees for belgium'), default=0.00)
- europe_postage_fee = models.DecimalField(decimal_places=2, max_digits=6, verbose_name=_('Postage fees for europe'), default=0.00)
- world_postage_fee = models.DecimalField(decimal_places=2, max_digits=6, verbose_name=_('Postage fees for rest of the world'), default=0.00)
+ max_doc_in_letter = models.PositiveSmallIntegerField(verbose_name=_('Maximum documents in one letter'),
+ default=5,
+ validators=[MaxValueValidator(100), MinValueValidator(1)])
+ belgium_postage_fee = models.DecimalField(decimal_places=2, max_digits=6,
+ verbose_name=_('Postage fees for belgium'), default=0.00)
+ europe_postage_fee = models.DecimalField(decimal_places=2, max_digits=6, verbose_name=_('Postage fees for europe'),
+ default=0.00)
+ world_postage_fee = models.DecimalField(decimal_places=2, max_digits=6,
+ verbose_name=_('Postage fees for rest of the world'), default=0.00)
+
# free_postage_exeptions_list_doc ?
class Meta:
@@ -51,7 +55,6 @@ class ExtraFees(BaseResource):
def get_connector_slug(cls):
return 'extra-fees'
-
# Minimum requirement in request to compute basket with postage fee
# nb_documents : Number of desired documents for one citizen posted form.
# postage_fee : THanks to citizen choice (Be/Eu/Wrld), Postage Fee value for this form.
@@ -63,16 +66,17 @@ class ExtraFees(BaseResource):
for basket_item in data['data']:
try:
nb_documents += int(basket_item['request_data']['nb_documents'])
- destination = basket_item['request_data']['destination'] # Passed in the workflow webservice
+ destination = basket_item['request_data']['destination'] # Passed in the workflow webservice
# No postage fees if send by mail
- if destination and 'mail' in destination:
+ if destination and 'mail' in destination:
postage_fee = Decimal(0)
if Decimal(basket_item['request_data']['postage_fee']) > postage_fee:
postage_fee = Decimal(basket_item['request_data']['postage_fee'])
except KeyError:
# basket item not associated with any document, no fee
pass
- nb_letter = int(nb_documents / int(self.max_doc_in_letter)) + (((nb_documents % int(self.max_doc_in_letter)) > 0) and 1 or 0)
+ nb_letter = int(nb_documents / int(self.max_doc_in_letter)) + (
+ ((nb_documents % int(self.max_doc_in_letter)) > 0) and 1 or 0)
postage_fee = nb_letter * postage_fee
return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]}
@@ -100,7 +104,9 @@ class ExtraFees(BaseResource):
for basket_item in data['data']:
try:
nb_documents += int(basket_item['request_data']['nb_documents'])
- if Decimal(basket_item['request_data']['country_price']) > postage_fee and 'duplicata-de-livret-de-mariage' not in basket_item['request_data']['form_slug']:
+ if Decimal(basket_item['request_data'][
+ 'country_price']) > postage_fee and 'duplicata-de-livret-de-mariage' not in \
+ basket_item['request_data']['form_slug']:
postage_fee = Decimal(basket_item['request_data']['country_price'])
except KeyError:
# basket item not associated with any document, no fee
@@ -110,7 +116,7 @@ class ExtraFees(BaseResource):
postage_fee = Decimal('0.00')
else:
if changement_adresse_exception == True and nb_documents > 1:
- nb_documents = nb_documents -1
+ nb_documents = nb_documents - 1
nb_letter = int(nb_documents / max_doc_in_letter) + (((nb_documents % max_doc_in_letter) > 0) and 1 or 0)
postage_fee = nb_letter * postage_fee
if duplicata_exception == True:
@@ -129,21 +135,22 @@ class ExtraFees(BaseResource):
# So, we need to keep 0.74 and 1.13 like id and use fee key to get real fee value.
@endpoint()
def namur_fees(self, request):
- return {'data':[{'id':'0.74','fee':self.belgium_postage_fee,'text':'En Belgique'},
- {'id':'1.13','fee':self.europe_postage_fee,'text':'À l\'étranger'}]}
+ return {'data': [{'id': '0.74', 'fee': self.belgium_postage_fee, 'text': 'En Belgique'},
+ {'id': '1.13', 'fee': self.europe_postage_fee, 'text': 'À l\'étranger'}]}
# wcs : new webservice call : https://[COMMUNE]-passerelle.guichet-citoyen.be/extra-fees/[CONNECTOR-SLUG]/fees
# datasources : webservice.fees.get('belgium')
@endpoint()
def fees(self, request):
- return {'belgium':self.belgium_postage_fee,
- 'europe':self.europe_postage_fee,
- 'world' :self.world_postage_fee}
+ return {'belgium': self.belgium_postage_fee,
+ 'europe': self.europe_postage_fee,
+ 'world': self.world_postage_fee}
@endpoint()
def destination_choices(self, request, q=None, **kwargs):
- destination_choices = {'data':[{'id':'belgium', 'text':'En belgique', 'fee':self.belgium_postage_fee},
- {'id':'europe', 'text':'En europe', 'fee':self.europe_postage_fee},
- {'id':'world', 'text':'Dans le reste du monde', 'value':self.world_postage_fee}
- ]}
+ destination_choices = {'data': [{'id': 'belgium', 'text': 'En belgique', 'fee': self.belgium_postage_fee},
+ {'id': 'europe', 'text': 'En europe', 'fee': self.europe_postage_fee},
+ {'id': 'world', 'text': 'Dans le reste du monde',
+ 'value': self.world_postage_fee}
+ ]}
return destination_choices