diff --git a/delivery_postlogistics/__manifest__.py b/delivery_postlogistics/__manifest__.py index c0a72e8028..d4c4d7cd48 100644 --- a/delivery_postlogistics/__manifest__.py +++ b/delivery_postlogistics/__manifest__.py @@ -9,7 +9,7 @@ "license": "AGPL-3", "category": "Delivery", "complexity": "normal", - "depends": ["delivery", "mail", "base", "stock"], + "depends": ["mail", "base", "stock_delivery"], "website": "https://github.com/OCA/delivery-carrier", "data": [ "security/ir.model.access.csv", diff --git a/delivery_postlogistics/models/delivery_carrier.py b/delivery_postlogistics/models/delivery_carrier.py index 29c83b5dbd..0d996e0a05 100644 --- a/delivery_postlogistics/models/delivery_carrier.py +++ b/delivery_postlogistics/models/delivery_carrier.py @@ -22,7 +22,7 @@ class DeliveryCarrier(models.Model): postlogistics_endpoint_url = fields.Char( string="Endpoint URL", - default="https://wedecint.post.ch/", + default="https://api-int.post.ch", required=True, ) postlogistics_client_id = fields.Char( @@ -31,6 +31,11 @@ class DeliveryCarrier(models.Model): postlogistics_client_secret = fields.Char( string="Client Secret", groups="base.group_system" ) + postlogistics_scope = fields.Char( + string="Scope", + default="DCAPI_BARCODE_READ", + groups="base.group_system" + ) postlogistics_logo = fields.Binary( string="Company Logo on Post labels", help="Optional company logo to show on label.\n" @@ -102,14 +107,14 @@ class DeliveryCarrier(models.Model): def onchange_prod_environment(self): """ Auto change the end point url following the environment - - Test: https://wedecint.post.ch/ - - Prod: https://wedec.post.ch/ + - Test: https://api-int.post.ch/ + - Prod: https://api.post.ch/ """ for carrier in self: if carrier.prod_environment: - carrier.postlogistics_endpoint_url = "https://wedec.post.ch/" + carrier.postlogistics_endpoint_url = "https://api.post.ch/" else: - carrier.postlogistics_endpoint_url = "https://wedecint.post.ch/" + carrier.postlogistics_endpoint_url = "https://api-int.post.ch/" def postlogistics_get_tracking_link(self, picking): return ( diff --git a/delivery_postlogistics/postlogistics/web_service.py b/delivery_postlogistics/postlogistics/web_service.py index 73500d6ef8..f137a2003b 100644 --- a/delivery_postlogistics/postlogistics/web_service.py +++ b/delivery_postlogistics/postlogistics/web_service.py @@ -19,7 +19,7 @@ _compile_itemid = re.compile(r"[^0-9A-Za-z+\-_]") _compile_itemnum = re.compile(r"[^0-9]") -AUTH_PATH = "/WEDECOAuth/token" +AUTH_PATH = "/OAuth/token" GENERATE_LABEL_PATH = "/api/barcode/v1/generateAddressLabel" DISALLOWED_CHARS_MAPPING = { @@ -38,9 +38,8 @@ class PostlogisticsWebService: Handbook available here: https://developer.post.ch/en/digital-commerce-api - https://wedec.post.ch/doc/swagger/index.html? - url=https://wedec.post.ch/doc/api/barcode/v1/swagger.yaml - #/Barcode/generateAddressLabel + https://developer.apis.post.ch/ui/apis/5cff6ab7-8325-4a05-bf6a-b783256a0552 + /pages/50fa2b65-2f67-4867-ba2b-652f6738676d Allows to generate labels @@ -426,15 +425,16 @@ def _request_access_token(cls, delivery_carrier): client_id = delivery_carrier.postlogistics_client_id client_secret = delivery_carrier.postlogistics_client_secret + scope = delivery_carrier.postlogistics_scope authentication_url = urllib.parse.urljoin( delivery_carrier.postlogistics_endpoint_url or "", AUTH_PATH ) - if not (client_id and client_secret): + if not (client_id and client_secret and scope): raise exceptions.UserError( _( "Authorization Required\n\n" - "Please verify postlogistics client id and secret in:\n" + "Please verify postlogistics client id, secret and scope in:\n" "Delivery Carrier (PostLogistics)." ) ) @@ -446,7 +446,7 @@ def _request_access_token(cls, delivery_carrier): "grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret, - "scope": "WEDEC_BARCODE_READ", + "scope": scope, }, timeout=60, ) diff --git a/delivery_postlogistics/tests/common.py b/delivery_postlogistics/tests/common.py index b37806c5bf..e846d391d2 100644 --- a/delivery_postlogistics/tests/common.py +++ b/delivery_postlogistics/tests/common.py @@ -1,11 +1,13 @@ # Copyright 2021 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +import requests + from odoo.tests.common import TransactionCase from ..postlogistics.web_service import PostlogisticsWebService -ENDPOINT_URL = "https://wedecint.post.ch/" +ENDPOINT_URL = "https://api-int.post.ch/" CLIENT_ID = "XXX" CLIENT_SECRET = "XXX" LICENSE = "XXX" @@ -114,8 +116,14 @@ def create_picking(cls, partner=None, product_matrix=None): def setUpClassWebservice(cls): cls.service_class = PostlogisticsWebService(cls.env.user.company_id) + @classmethod + def _request_handler(cls, s, r, /, **kw): + """Don't block external requests.""" + return cls._super_send(s, r, **kw) + @classmethod def setUpClass(cls): + cls._super_send = requests.Session.send super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls.setUpClassLicense() diff --git a/delivery_postlogistics/tests/fixtures/cassettes/test_missing_language.yaml b/delivery_postlogistics/tests/fixtures/cassettes/test_missing_language.yaml index 3f4ac4fd64..5f845b7cc0 100644 --- a/delivery_postlogistics/tests/fixtures/cassettes/test_missing_language.yaml +++ b/delivery_postlogistics/tests/fixtures/cassettes/test_missing_language.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: scope=WEDEC_BARCODE_READ&client_secret=c70e3696ae5146e7fe317434e50a90cd&grant_type=client_credentials&client_id=865783331e39e91e633c3916fe892d92 + body: scope=DCAPI_BARCODE_READ&client_secret=c70e3696ae5146e7fe317434e50a90cd&grant_type=client_credentials&client_id=865783331e39e91e633c3916fe892d92 headers: Accept: - "*/*" @@ -15,7 +15,7 @@ interactions: content-type: - application/x-www-form-urlencoded method: POST - uri: https://wedecint.post.ch/WEDECOAuth/token + uri: https://api-int.post.ch/OAuth/token response: body: string: '{"access_token":"XXX","token_type":"Bearer","expires_in":60}' @@ -67,7 +67,7 @@ interactions: content-type: - application/json method: POST - uri: https://wedecint.post.ch/api/barcode/v1/generateAddressLabel + uri: https://api-int.post.ch/api/barcode/v1/generateAddressLabel response: body: string: "{\n \"labelDefinition\" : {\n \"labelLayout\" : \"A6\",\n \"\ diff --git a/delivery_postlogistics/tests/fixtures/cassettes/test_store_label.yaml b/delivery_postlogistics/tests/fixtures/cassettes/test_store_label.yaml index 28e207216e..75e825b1af 100644 --- a/delivery_postlogistics/tests/fixtures/cassettes/test_store_label.yaml +++ b/delivery_postlogistics/tests/fixtures/cassettes/test_store_label.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: scope=WEDEC_BARCODE_READ&client_secret=c70e3696ae5146e7fe317434e50a90cd&grant_type=client_credentials&client_id=865783331e39e91e633c3916fe892d92 + body: scope=DCAPI_BARCODE_READ&client_secret=c70e3696ae5146e7fe317434e50a90cd&grant_type=client_credentials&client_id=865783331e39e91e633c3916fe892d92 headers: Accept: - "*/*" @@ -15,7 +15,7 @@ interactions: content-type: - application/x-www-form-urlencoded method: POST - uri: https://wedecint.post.ch/WEDECOAuth/token + uri: https://api-int.post.ch/OAuth/token response: body: string: '{"access_token":"XXX","token_type":"Bearer","expires_in":60}' @@ -67,7 +67,7 @@ interactions: content-type: - application/json method: POST - uri: https://wedecint.post.ch/api/barcode/v1/generateAddressLabel + uri: https://api-int.post.ch/api/barcode/v1/generateAddressLabel response: body: string: "{\n \"labelDefinition\" : {\n \"labelLayout\" : \"A6\",\n \"\ diff --git a/delivery_postlogistics/views/delivery.xml b/delivery_postlogistics/views/delivery.xml index afc296a87d..3cc403a643 100644 --- a/delivery_postlogistics/views/delivery.xml +++ b/delivery_postlogistics/views/delivery.xml @@ -11,21 +11,25 @@ +