-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename transporter to carrier, improve helpers and merge back carrier…
…v2 to carrier
- Loading branch information
1 parent
46b0897
commit 95eab64
Showing
11 changed files
with
92 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
from . import dpd_fr_soap | ||
from . import geodis_fr | ||
from . import mondialrelay | ||
from . import mondialrelay_fr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import carrier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from ..helpers import prefix, clean_empty, REMOVED | ||
from ..schema import ( | ||
from ...helpers import prefix, filter_empty, unaccent, REMOVED | ||
from ...schema import ( | ||
Address, | ||
Auth, | ||
Label, | ||
|
@@ -30,13 +30,19 @@ def soap(self): | |
} | ||
|
||
def sign(self, parameters): | ||
parameters = unaccent(filter_empty(parameters)) | ||
m = md5() | ||
|
||
m.update( | ||
"".join( | ||
[ | ||
str(v) | ||
for k in SORTED_KEYS | ||
for v in [parameters.get(k)] | ||
for _, v in sorted( | ||
parameters.items(), | ||
key=lambda item: SORTED_KEYS.index( | ||
item[0], | ||
), | ||
) | ||
if v is not None | ||
] | ||
+ [self.password] | ||
|
@@ -110,7 +116,7 @@ def soap(self): | |
|
||
|
||
class MondialRelayAddress(Address): | ||
lang: str | ||
lang: str = "FR" | ||
country: str | ||
zip: str | ||
city: str | ||
|
@@ -146,15 +152,13 @@ class MondialRelayLabelInput(LabelInput): | |
|
||
def soap(self): | ||
return self.auth.sign( | ||
clean_empty( | ||
{ | ||
**self.auth.soap(), | ||
**self.service.soap(), | ||
**self.parcels[0].soap(), | ||
**prefix(self.from_address.soap(), "Expe_"), | ||
**prefix(self.to_address.soap(), "Dest_"), | ||
} | ||
) | ||
{ | ||
**self.auth.soap(), | ||
**self.service.soap(), | ||
**self.parcels[0].soap(), | ||
**prefix(self.from_address.soap(), "Expe_"), | ||
**prefix(self.to_address.soap(), "Dest_"), | ||
} | ||
) | ||
|
||
|
||
|
@@ -168,21 +172,19 @@ class MondialRelayPickupSiteSearch(PickupSiteSearch): | |
resultsCount: int | None = None | ||
|
||
def soap(self): | ||
return clean_empty( | ||
{ | ||
"Pays": self.country, | ||
"NumPointRelais": self.id, | ||
"CP": self.zip, | ||
"Latitude": self.lat, | ||
"Longitude": self.lng, | ||
"Poids": self.weight, | ||
"Action": self.action, | ||
"DelaiEnvoi": self.delay, | ||
"RayonRecherche": self.searchRadius, | ||
"TypeActivite": self.actionType, | ||
"NombreResultats": self.resultsCount, | ||
} | ||
) | ||
return { | ||
"Pays": self.country, | ||
"NumPointRelais": self.id, | ||
"CP": self.zip, | ||
"Latitude": self.lat, | ||
"Longitude": self.lng, | ||
"Poids": self.weight, | ||
"Action": self.action, | ||
"DelaiEnvoi": self.delay, | ||
"RayonRecherche": self.searchRadius, | ||
"TypeActivite": self.actionType, | ||
"NombreResultats": self.resultsCount, | ||
} | ||
|
||
|
||
class MondialRelayPickupSiteInput(PickupSiteInput): | ||
|
@@ -191,12 +193,10 @@ class MondialRelayPickupSiteInput(PickupSiteInput): | |
|
||
def soap(self): | ||
return self.auth.sign( | ||
clean_empty( | ||
{ | ||
**self.auth.soap(), | ||
**self.search.soap(), | ||
} | ||
) | ||
{ | ||
**self.auth.soap(), | ||
**self.search.soap(), | ||
} | ||
) | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from typing import ClassVar | ||
import unicodedata | ||
|
||
REMOVED = ClassVar[None] # Hack to remove a field from inherited class | ||
|
||
|
@@ -15,12 +15,33 @@ def suffix(data, suffix): | |
return {f"{k}{suffix}": v for k, v in data.items()} | ||
|
||
|
||
def clean_empty(data): | ||
return {k: v for k, v in data.items() if v is not None and v != ""} | ||
def walk_data(data, filter=lambda x: True, transform=lambda x: x): | ||
if isinstance(data, dict): | ||
return { | ||
k: walk_data(v, filter, transform) for k, v in data.items() if filter(v) | ||
} | ||
elif isinstance(data, list): | ||
return [walk_data(v, filter, transform) for v in data] | ||
else: | ||
return transform(data) | ||
|
||
|
||
def filter_empty(data): | ||
return walk_data(data, filter=lambda x: x is not None and x != "") | ||
|
||
|
||
def none_as_empty(data): | ||
return {k: v if v is not None else "" for k, v in data.items()} | ||
return walk_data(data, transform=lambda x: "" if x is None else x) | ||
|
||
|
||
def unaccent(s): | ||
if isinstance(s, dict): | ||
return walk_data(s, transform=unaccent) | ||
if not isinstance(s, str): | ||
return s | ||
return "".join( | ||
c for c in unicodedata.normalize("NFD", s) if unicodedata.category(c) != "Mn" | ||
) | ||
|
||
|
||
def merge(*dicts): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters