Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate DPD to new roulier and python 3 #139

Merged
merged 4 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions roulier/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _normalize_coerce_zpl(self, value):
Remove ZPL ctrl caraters
Remove accents
"""
if not isinstance(value, basestring):
if not isinstance(value, str):
return value

ctrl_cars = [
Expand All @@ -28,41 +28,43 @@ def _normalize_coerce_zpl(self, value):

def _normalize_coerce_accents(self, value):
"""Sanitize accents for some WS."""
if not isinstance(value, basestring):
if not isinstance(value, str):
return value
sanitized = (
value
# quick and dirty replacement
# of common accentued chars in french
# because some ws don't handle well utf8
.replace(u"é", "e")
.replace(u"è", "e")
.replace(u"ë", "e")
.replace(u"ê", "e")
.replace(u"ô", "o")
.replace(u"ï", "i")
.replace(u"ö", "o")
.replace(u"à", "a")
.replace(u"â", "a")
.replace(u"ç", "c")
.replace(u"û", "u")
.replace(u"ù", "u")
.replace(u"É", "E")
.replace(u"È", "E")
.replace(u"Ë", "E")
.replace(u"Ê", "E")
.replace(u"Ô", "O")
.replace(u"Ï", "I")
.replace(u"Ö", "O")
.replace(u"À", "A")
.replace(u"Â", "A")
.replace(u"Ç", "C")
.replace(u"Û", "U")
.replace(u"Ù", "U")
.replace(u"œ", "oe")
.replace(u"Œ", "OE")
).encode(
"ascii", "ignore"
(
value
# quick and dirty replacement
# of common accentued chars in french
# because some ws don't handle well utf8
.replace("é", "e")
.replace("è", "e")
.replace("ë", "e")
.replace("ê", "e")
.replace("ô", "o")
.replace("ï", "i")
.replace("ö", "o")
.replace("à", "a")
.replace("â", "a")
.replace("ç", "c")
.replace("û", "u")
.replace("ù", "u")
.replace("É", "E")
.replace("È", "E")
.replace("Ë", "E")
.replace("Ê", "E")
.replace("Ô", "O")
.replace("Ï", "I")
.replace("Ö", "O")
.replace("À", "A")
.replace("Â", "A")
.replace("Ç", "C")
.replace("Û", "U")
.replace("Ù", "U")
.replace("œ", "oe")
.replace("Œ", "OE")
)
.encode("ascii", "ignore")
.decode("ascii")
) # cut remaining chars
return sanitized

Expand Down
2 changes: 1 addition & 1 deletion roulier/carriers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import laposte_fr
from . import gls_fr
from . import chronopost_fr
from . import dpd_fr_soap

# from . import geodis
# from . import dpd
6 changes: 0 additions & 6 deletions roulier/carriers/dpd/__init__.py

This file was deleted.

30 changes: 0 additions & 30 deletions roulier/carriers/dpd/dpd.py

This file was deleted.

65 changes: 0 additions & 65 deletions roulier/carriers/dpd/dpd_decoder.py

This file was deleted.

99 changes: 0 additions & 99 deletions roulier/carriers/dpd/dpd_encoder.py

This file was deleted.

5 changes: 5 additions & 0 deletions roulier/carriers/dpd_fr_soap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import carrier_action
from . import decoder
from . import encoder
from . import transport
from . import api
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Implementation of Dpd Api."""
from roulier.api import Api

from roulier.api import ApiParcel
from roulier.api import MyValidator

DPD_LABEL_FORMAT = (
"PDF",
Expand All @@ -22,7 +24,45 @@
)


class DpdApi(Api):
class DpdValidator(MyValidator):
def _validate_product(self, _, field, value):
"""
Tests some complex constraints relate to the product type and other fields values

The rule's arguments are validated against this schema:
{'type': 'boolean'}
"""
product = self.document.get("product")
pickup_id = self.document.get("pickupLocationId", "").strip()
notifications = self.document.get("notifications")
if pickup_id and product in ("DPD_Predict", "DPD_Classic"):
self._error(
"pickupLocationId", "pickupLocationId can't be used with %s" % product
)
if product == "DPD_Predict":
if notifications and "notifications" != "Predict":
self._error(
"notifications", "must be set to Predict when using Predict"
)
else:
if notifications == "Predict":
self._error(
"notifications",
"Predict notifications can't be used with %s" % product,
)
if product == "DPD_Relais" and not pickup_id:
self._error(
"pickupLocationId", "pickupLocationId is mandatory for Relais"
)


class DpdApi(ApiParcel):
def _validator(self):
v = DpdValidator()
v.allow_unknown = True
# v.purge_unknown = True
return v

def _service(self):
schema = super(DpdApi, self)._service()
schema["labelFormat"]["allowed"] = DPD_LABEL_FORMAT
Expand Down Expand Up @@ -61,10 +101,11 @@ def _service(self):
"default": DPD_PRODUCTS[0],
# 'description': 'Type de produit',
"allowed": DPD_PRODUCTS,
"product": True,
}
)

schema["dropOffLocation"] = {
schema["pickupLocationId"] = {
"default": "",
"empty": True,
"required": False,
Expand Down
Loading