-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nikolausweingartmair
committed
Dec 29, 2023
1 parent
5df0d0e
commit 0792c83
Showing
60 changed files
with
3,375 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Odoo Proprietary License v1.0 | ||
|
||
This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) | ||
if you have purchased a valid license from the authors, typically via Odoo Apps, | ||
or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). | ||
|
||
You may develop Odoo modules that use the Software as a library | ||
(typically by depending on it, importing it and using its resources), | ||
but without copying any source code or material from the Software. | ||
You may distribute those modules under the license of your choice, | ||
provided that this license is compatible with the terms of the Odoo Proprietary License | ||
(For example: LGPL, MIT, or proprietary licenses similar to this one). | ||
|
||
It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. | ||
|
||
The above copyright notice and this permission notice must be included in all copies | ||
or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
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,57 @@ | ||
============ | ||
DHL API Base | ||
============ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:e9abffe3fbf9e68aa1007831223d306bbaba1461e03d0c6b9bc8115f279f7ffb | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/license-OPL--1-blue | ||
:target: https://www.odoo.com/documentation/user/13.0/legal/licenses/licenses.html#odoo-apps | ||
:alt: License: OPL-1 | ||
.. |badge2| image:: https://img.shields.io/badge/github-grueneerde%2Fgrueneerde-lightgray.png?logo=github | ||
:target: https://github.com/grueneerde/grueneerde/tree/15.0/ge_dhl_base | ||
:alt: grueneerde/grueneerde | ||
|
||
|badge1| |badge2| | ||
|
||
This module has common functionality for dhl api services. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/grueneerde/grueneerde/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/grueneerde/grueneerde/issues/new?body=module:%20ge_dhl_base%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Grüne Erde | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Nikolaus Weingartmair <nikolaus.weingartmair@grueneerde.com> (https://www.grueneerde.com/) | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `grueneerde/grueneerde <https://github.com/grueneerde/grueneerde/tree/15.0/ge_dhl_base>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
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,8 @@ | ||
##################################################################################### | ||
# Copyright (c) 2023 Grüne Erde GmbH (https://grueneerde.com) | ||
# All Right Reserved | ||
# | ||
# Licensed under the Odoo Proprietary License v1.0 (OPL). | ||
# See LICENSE file for full licensing details. | ||
##################################################################################### | ||
from . import models |
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,18 @@ | ||
##################################################################################### | ||
# Copyright (c) 2023 Grüne Erde GmbH (https://grueneerde.com) | ||
# All Right Reserved | ||
# | ||
# Licensed under the Odoo Proprietary License v1.0 (OPL). | ||
# See LICENSE file for full licensing details. | ||
##################################################################################### | ||
{ | ||
"name": "DHL API Base", | ||
"summary": """This module has common functionality for the dhl api.""", | ||
"version": "15.0.1.0.0", | ||
"category": "Inventory", | ||
"author": "Grüne Erde", # pylint: disable=all | ||
"website": "https://github.com/grueneerde/ge_complaint_types", | ||
"license": "OPL-1", | ||
"depends": ["base", "stock"], | ||
"data": ["views/stock_picking_views.xml", "views/delivery_carrier_views.xml"], | ||
} |
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,8 @@ | ||
##################################################################################### | ||
# Copyright (c) 2023 Grüne Erde GmbH (https://grueneerde.com) | ||
# All Right Reserved | ||
# | ||
# Licensed under the Odoo Proprietary License v1.0 (OPL). | ||
# See LICENSE file for full licensing details. | ||
##################################################################################### | ||
from . import dhl_request |
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,92 @@ | ||
# Copyright 2021-2022 Tecnativa - Víctor Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
import base64 | ||
import logging | ||
|
||
import requests | ||
|
||
from odoo import _ | ||
from odoo.exceptions import UserError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class DhlRequest(object): | ||
def __init__(self, carrier, record, api=None): | ||
if api is None: | ||
_logger.warning( | ||
"DhlRequest needs to be initialized with api='' dhl_tracking, dhl_shipping, dhl_return" | ||
) | ||
self.carrier = carrier | ||
self.record = record | ||
self.username = getattr(self.carrier.company_id, api + "_userid", False) | ||
self.password = getattr(self.carrier.company_id, api + "_password", False) | ||
self.dhl_api_key = getattr(self.carrier.company_id, api + "_dhl_api_key", False) | ||
self.dhl_api_secret = getattr( | ||
self.carrier.company_id, api + "_dhl_api_secret", False | ||
) | ||
self.domain = getattr(self.carrier.company_id, api + "_domain", False) | ||
self.endpoint = getattr(self.carrier.company_id, api + "_endpoint", False) | ||
self.url = getattr(self.carrier.company_id, api + "_url", False) | ||
self.receiverId = getattr(self.carrier.company_id, api + "_receiverId", False) | ||
|
||
if api in ["dhl_return", "dhl_shipping"]: | ||
user = self.username | ||
password = self.password | ||
else: | ||
user = self.dhl_api_key | ||
password = self.dhl_api_secret | ||
auth_encoding = "%s:%s" % ( | ||
user, | ||
password, | ||
) | ||
self.authorization = base64.b64encode(auth_encoding.encode("utf-8")).decode( | ||
"utf-8" | ||
) | ||
|
||
def _send_api_request( | ||
self, url, data=None, auth=True, content_type="application/xml", method="GET" | ||
): | ||
if data is None: | ||
data = {} | ||
dhl_last_request = ("URL: {}\nData: {}").format(self.url, data) | ||
self.carrier.log_xml(dhl_last_request, "dhl_last_request") | ||
try: | ||
headers = {"Content-Type": content_type, "charset": "UTF-8"} | ||
if auth: | ||
headers["Authorization"] = "Basic {}".format(self.authorization) | ||
headers["dhl-api-key"] = "{}".format(self.dhl_api_key) | ||
res = requests.request( | ||
method, url=url, data=data.encode("utf-8"), headers=headers, timeout=60 | ||
) | ||
res.raise_for_status() | ||
self.carrier.log_xml(res.text or "", "dhl_last_request") | ||
res = res.text | ||
except requests.exceptions.Timeout as tout: | ||
raise UserError(_("Timeout: the server did not reply within 60s")) from tout | ||
except (ValueError, requests.exceptions.ConnectionError) as valerr: | ||
raise UserError( | ||
_("Server not reachable, please try again later") | ||
) from valerr | ||
except requests.exceptions.HTTPError as e: | ||
_logger.warning(e) | ||
resp = res.json() | ||
|
||
errormessage = "" | ||
for line in resp.get("items", []): | ||
for valmes in line.get("validationMessages", []): | ||
errormessage += valmes.get("validationMessage", "") | ||
|
||
raise UserError( | ||
_( | ||
"%(error)s\n%(message)s\n%(detail)s%(errormessage)s\n%(fullresponse)s" | ||
) | ||
% { | ||
"error": e, | ||
"message": resp.get("Message", "") if res.text else "", | ||
"detail": resp.get("detail", "") if res.text else "", | ||
"errormessage": errormessage, | ||
"fullresponse": res.text, | ||
} | ||
) from e | ||
return res |
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 @@ | ||
* Nikolaus Weingartmair <nikolaus.weingartmair@grueneerde.com> (https://www.grueneerde.com/) |
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 @@ | ||
This module has common functionality for dhl api services. |
Oops, something went wrong.