Skip to content

Commit 2be64c2

Browse files
authored
Merge pull request #88 from PurplShip/purplship-2020.12-patch
[patch] Purplship 2020.12 patch
2 parents 3b036e8 + e0d15a1 commit 2be64c2

File tree

51 files changed

+332
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+332
-169
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a href="https://github.com/Purplship/Purplship/actions"><img src="https://github.com/Purplship/Purplship/workflows/PuprlShip/badge.svg" alt="CI" style="max-width:100%;"></a>
1212
<a href="https://www.gnu.org/licenses/lgpl-3.0" rel="nofollow"><img src="https://img.shields.io/badge/License-LGPL%20v3-blue.svg" alt="License: AGPL v3" data-canonical-src="https://img.shields.io/badge/License-AGPL%20v3-blue.svg" style="max-width:100%;"></a>
1313
<a href="https://github.com/python/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black" style="max-width:100%;"></a>
14-
<a href="https://codecov.io/gh/Purplship/Purplship"><img src="https://codecov.io/gh/Purplship/Purplship/branch/master/graph/badge.svg" alt="codecov" style="max-width:100%;"></a>
14+
<a href="https://codecov.io/gh/Purplship/Purplship"><img src="https://codecov.io/gh/Purplship/Purplship/branch/main/graph/badge.svg" alt="codecov" style="max-width:100%;"></a>
1515
<a href="https://app.codacy.com/manual/DanH91/Purplship?utm_source=github.com&utm_medium=referral&utm_content=Purplship/Purplship&utm_campaign=Badge_Grade_Dashboard"><img src="https://api.codacy.com/project/badge/Grade/a57baa23a1ca4403a37a8b7134609709" alt="Codacy Badge" style="max-width:100%;"></a>
1616
<a href="https://gitter.im/Purplship/Purplship?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge"><img src="https://badges.gitter.im/Purplship/purplship.svg" alt="Join the chat at https://gitter.im/Purplship/Purplship" style="max-width:100%;"></a>
1717
</p>
@@ -36,7 +36,7 @@ With Purplship you can:
3636
Purplship has two layers
3737

3838
- **Purplship SDK** for an integration as a Python library. *[documentation](#Documentation) bellow*
39-
- **Purplship Server** for an On-prem or private cloud REST API. *documentation and usage can be found at [docs.purplship.com](https://docs.purplship.com)*
39+
- **Purplship Server** for an On-prem or cloud REST API. *documentation and usage can be found at [docs.purplship.com](https://docs.purplship.com)*
4040

4141
## License
4242

@@ -446,7 +446,7 @@ rates = request.from_(carrier).parse()
446446

447447
| Name | Type | Description
448448
| --- | --- | --- |
449-
| `carrier_name` | `str` | default: carrier name (eg: CanadaPost, Purolator...)
449+
| `carrier_name` | `str` | default: carrier name (eg: canadapost, purolator...)
450450
| `id` | `str` |
451451
| `test` | `boolean` |
452452

@@ -566,7 +566,7 @@ rates = request.from_(carrier).parse()
566566
| --- | --- | --- |
567567
| `carrier_name` | `str` |
568568
| `carrier_id` | `str` |
569-
| `message` | `str` |
569+
| `message` | Union[str, Any] |
570570
| `code` | `str` |
571571
| `details` | `dict` |
572572

@@ -710,6 +710,7 @@ rates = request.from_(carrier).parse()
710710
| `doc_images` | List[[Doc](#Doc)] |
711711
| `options` | `dict` |
712712
| `reference` | `str` |
713+
| `label_type` | `str` |
713714

714715

715716
- <a name="TrackingDetails"></a> TrackingDetails
@@ -738,7 +739,7 @@ rates = request.from_(carrier).parse()
738739
| --- | --- | --- |
739740
| `tracking_numbers` | List[str] |
740741
| `language_code` | `str` |
741-
| `level_of_details` | `str` |
742+
| `level_of_details` | `str` |
742743

743744
</details>
744745

cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22
import inspect
33
from jinja2 import Template
4-
from purplship.core.utils import to_dict
4+
from purplship.core.utils import DP
55

66
MODELS_TEMPLATE = Template('''
77
{% for name, cls in classes.items() %}
@@ -135,7 +135,7 @@ def generate_shipment_options():
135135
@cli.command()
136136
def generate_package_presets():
137137
preset_mappers = {
138-
key: {c.name: to_dict(c.value) for c in list(getattr(mapper['package'], mapper['packagePresets']))}
138+
key: {c.name: DP.to_dict(c.value) for c in list(getattr(mapper['package'], mapper['packagePresets']))}
139139
for key, mapper in PACKAGE_MAPPERS.items()
140140
if mapper.get('packagePresets') is not None
141141
}

extensions/boxknight/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_namespace_packages
22

33
setup(name='purplship.boxknight',
4-
version='2020.12-alpha',
4+
version='2020.12.1-alpha',
55
description='Multi-carrier shipping API integration with python',
66
url='https://github.com/PurplShip/purplship',
77
author='Purplship Team',

extensions/canadapost/purplship/mappers/canadapost/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def _non_contract_shipment(job: Job):
8080
def _get_label(job: Job):
8181
label_string = http(
8282
decoder=lambda b: base64.encodebytes(b).decode("utf-8"),
83-
url=job.data,
83+
url=job.data["href"],
8484
headers={
85-
"Accept": "application/pdf",
85+
"Accept": job.data["media"],
8686
"Authorization": f"Basic {self.settings.authorization}",
8787
},
8888
method="GET",

extensions/canadapost/purplship/providers/canadapost/rate.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
service_standardType,
1414
)
1515
from functools import reduce
16-
from datetime import datetime
1716
from typing import List, Tuple, cast
1817
from purplship.core.utils import Serializable, Element, NF, XP
1918
from purplship.providers.canadapost.utils import Settings
2019
from purplship.core.units import Country, Currency, Packages, Services, Options
2120
from purplship.core.errors import OriginNotServicedError
2221
from purplship.core.models import RateDetails, ChargeDetails, Message, RateRequest
2322
from purplship.providers.canadapost.error import parse_error_response
24-
from purplship.providers.canadapost.units import OptionCode, ServiceType, PackagePresets
23+
from purplship.providers.canadapost.units import OptionCode, ServiceType, PackagePresets, MeasurementOptions
2524

2625

2726
def parse_rate_response(
@@ -97,7 +96,7 @@ def rate_request(
9796
contract_id=None,
9897
promo_code=None,
9998
quote_type=None,
100-
expected_mailing_date=datetime.today().strftime("%Y-%m-%d"),
99+
expected_mailing_date=requested_options.shipment_date,
101100
options=(
102101
optionsType(
103102
option=[
@@ -108,11 +107,11 @@ def rate_request(
108107
if any(requested_options) else None
109108
),
110109
parcel_characteristics=parcel_characteristicsType(
111-
weight=package.weight.KG,
110+
weight=package.weight.map(MeasurementOptions).KG,
112111
dimensions=dimensionsType(
113-
length=package.length.CM,
114-
width=package.width.CM,
115-
height=package.height.CM,
112+
length=package.length.map(MeasurementOptions).CM,
113+
width=package.width.map(MeasurementOptions).CM,
114+
height=package.height.map(MeasurementOptions).CM,
116115
),
117116
unpackaged=None,
118117
mailing_tube=None,

extensions/canadapost/purplship/providers/canadapost/shipment/contract.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
groupIdOrTransmitShipment,
2323
)
2424
from purplship.core.units import Currency, WeightUnit, Options, Packages
25-
from purplship.core.utils import Serializable, Element, XP, SF
25+
from purplship.core.utils import Serializable, Element, XP, SF, NF
2626
from purplship.core.models import (
2727
Message,
2828
ShipmentDetails,
@@ -33,9 +33,10 @@
3333
OptionCode,
3434
ServiceType,
3535
PackagePresets,
36-
PrinterType,
3736
PaymentType,
38-
INTERNATIONAL_NON_DELIVERY_OPTION
37+
LabelType,
38+
INTERNATIONAL_NON_DELIVERY_OPTION,
39+
MeasurementOptions,
3940
)
4041
from purplship.providers.canadapost.utils import Settings
4142

@@ -101,6 +102,8 @@ def compute_amount(code: str, _: Any):
101102
if is_intl and not any(key in special_services for key in INTERNATIONAL_NON_DELIVERY_OPTION):
102103
special_services['canadapost_return_to_sender'] = OptionCode.canadapost_return_to_sender.value
103104

105+
label_encoding, label_format = LabelType[payload.label_type or 'PDF_4x6'].value
106+
104107
request = ShipmentType(
105108
customer_request_id=None,
106109
groupIdOrTransmitShipment=groupIdOrTransmitShipment(),
@@ -145,11 +148,11 @@ def compute_amount(code: str, _: Any):
145148
),
146149
),
147150
parcel_characteristics=ParcelCharacteristicsType(
148-
weight=package.weight.KG,
151+
weight=package.weight.map(MeasurementOptions).KG,
149152
dimensions=dimensionsType(
150-
length=package.length.CM,
151-
width=package.width.CM,
152-
height=package.height.CM,
153+
length=package.length.map(MeasurementOptions).CM,
154+
width=package.width.map(MeasurementOptions).CM,
155+
height=package.height.map(MeasurementOptions).CM,
153156
),
154157
unpackaged=None,
155158
mailing_tube=None,
@@ -178,8 +181,8 @@ def compute_amount(code: str, _: Any):
178181
if options.notification_email else None
179182
),
180183
print_preferences=PrintPreferencesType(
181-
output_format=PrinterType[options.label_printing or "regular"].value,
182-
encoding=None,
184+
output_format=label_format,
185+
encoding=label_encoding,
183186
),
184187
preferences=PreferencesType(
185188
service_code=None,

extensions/canadapost/purplship/providers/canadapost/shipment/create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def _create_shipment(payload: ShipmentRequest, settings: Settings) -> Job:
3737

3838
def _get_shipment_label(shipement_response: str) -> Job:
3939
links = XP.to_xml(shipement_response).xpath(".//*[local-name() = $name]", name="link")
40-
label_url = next(
41-
(link.get("href") for link in links if link.get("rel") == "label"),
42-
None,
40+
href, media = next(
41+
((link.get("href"), link.get("media-type")) for link in links if link.get("rel") == "label"),
42+
(None, None),
4343
)
44-
return Job(id="shipment_label", data=label_url, fallback="")
44+
return Job(id="shipment_label", data=dict(href=href, media=media), fallback="")

extensions/canadapost/purplship/providers/canadapost/shipment/non_contract.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
PreferencesType,
2020
)
2121
from purplship.core.units import Currency, WeightUnit, Options, Packages
22-
from purplship.core.utils import Serializable, Element, SF, XP
22+
from purplship.core.utils import Serializable, Element, SF, XP, NF
2323
from purplship.core.models import (
2424
Message,
2525
ShipmentDetails,
@@ -138,11 +138,11 @@ def compute_amount(code: str, _: Any):
138138
if len(special_services) > 0 else None
139139
),
140140
parcel_characteristics=ParcelCharacteristicsType(
141-
weight=package.weight.KG,
141+
weight=NF.decimal(package.weight.KG, .1),
142142
dimensions=dimensionsType(
143-
length=package.length.CM,
144-
width=package.width.CM,
145-
height=package.height.CM,
143+
length=NF.decimal(package.length.CM, .1),
144+
width=NF.decimal(package.width.CM, .1),
145+
height=NF.decimal(package.height.CM, .1),
146146
),
147147
unpackaged=None,
148148
mailing_tube=None,
@@ -157,7 +157,7 @@ def compute_amount(code: str, _: Any):
157157
if options.notification_email is not None else None
158158
),
159159
preferences=PreferencesType(
160-
show_packing_instructions=True,
160+
show_packing_instructions=False,
161161
show_postage_rate=True,
162162
show_insured_value=("insurance" in payload.options),
163163
),

extensions/canadapost/purplship/providers/canadapost/units.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,18 @@ class PackagePresets(Flag):
4646
)
4747

4848

49-
class PrinterType(Enum):
50-
regular = "8.5x11"
51-
thermal = "4x6"
49+
class MeasurementOptions(Enum):
50+
quant = 0.1
5251

5352

54-
class LablelEncoding(Enum):
55-
pdf = "PDF"
56-
zpl = "ZPL"
53+
class LabelType(Enum):
54+
PDF_4x6 = ("PDF", "4x6")
55+
PDF_8_5x11 = ("PDF", "8.5x11")
56+
ZPL_4x6 = ("ZPL", "4x6")
57+
58+
""" Unified Label type mapping """
59+
PDF = PDF_4x6
60+
ZPL = ZPL_4x6
5761

5862

5963
class PaymentType(Flag):

extensions/canadapost/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="purplship.canadapost",
5-
version="2020.12",
5+
version="2020.12.1",
66
description="Multi-carrier shipping API integration with python",
77
url="https://github.com/PurplShip/purplship",
88
author="Purplship Team",

0 commit comments

Comments
 (0)