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

[ADD] [15.0] delivery_dhl_de_oca #141

Closed
wants to merge 3 commits into from
Closed
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
76 changes: 76 additions & 0 deletions ge_dhl_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
============
DHL API Base
============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a404da423eddfbafd05b4caeb9d50df507e4a79953bf09134df5358e8923d73b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github
:target: https://github.com/OCA/delivery-carrier/tree/15.0/ge_dhl_base
:alt: OCA/delivery-carrier
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/delivery-carrier-15-0/delivery-carrier-15-0-ge_dhl_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

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/OCA/delivery-carrier/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/OCA/delivery-carrier/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 <[email protected]> (https://www.grueneerde.com/)

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/15.0/ge_dhl_base>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 8 additions & 0 deletions ge_dhl_base/__init__.py
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
18 changes: 18 additions & 0 deletions ge_dhl_base/__manifest__.py
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/OCA/l10n-germany",
"license": "AGPL-3",
"depends": ["base", "stock"],
"data": ["views/stock_picking_views.xml", "views/delivery_carrier_views.xml"],
}
8 changes: 8 additions & 0 deletions ge_dhl_base/models/__init__.py
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
93 changes: 93 additions & 0 deletions ge_dhl_base/models/dhl_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 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(

Check warning on line 17 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L17

Added line #L17 was not covered by tests
"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(

Check warning on line 26 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L21-L26

Added lines #L21 - L26 were not covered by tests
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)

Check warning on line 32 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L29-L32

Added lines #L29 - L32 were not covered by tests

if api in ["dhl_return", "dhl_shipping"]:
user = self.username
password = self.password

Check warning on line 36 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L35-L36

Added lines #L35 - L36 were not covered by tests
else:
user = self.dhl_api_key
password = self.dhl_api_secret
auth_encoding = "%s:%s" % (

Check warning on line 40 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L38-L40

Added lines #L38 - L40 were not covered by tests
user,
password,
)
self.authorization = base64.b64encode(auth_encoding.encode("utf-8")).decode(

Check warning on line 44 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L44

Added line #L44 was not covered by tests
"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"}

Check warning on line 56 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L52-L56

Added lines #L52 - L56 were not covered by tests
if auth:
headers["Authorization"] = "Basic {}".format(self.authorization)
headers["dhl-api-key"] = "{}".format(self.dhl_api_key)
res = requests.request(

Check warning on line 60 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L58-L60

Added lines #L58 - L60 were not covered by tests
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

Check warning on line 65 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L63-L65

Added lines #L63 - L65 were not covered by tests
except requests.exceptions.Timeout as tout:
raise UserError(_("Timeout: the server did not reply within 60s")) from tout

Check warning on line 67 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L67

Added line #L67 was not covered by tests
except (ValueError, requests.exceptions.ConnectionError) as valerr:
raise UserError(

Check warning on line 69 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L69

Added line #L69 was not covered by tests
_("Server not reachable, please try again later")
) from valerr
except requests.exceptions.HTTPError as e:
_logger.warning(e)
resp = res.json()

Check warning on line 74 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L72-L74

Added lines #L72 - L74 were not covered by tests

errormessage = ""

Check warning on line 76 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L76

Added line #L76 was not covered by tests
for line in resp.get("items", []):
for valmes in line.get("validationMessages", []):
errormessage += valmes.get("validationMessage", "")

Check warning on line 79 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L79

Added line #L79 was not covered by tests

raise UserError(

Check warning on line 81 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L81

Added line #L81 was not covered by tests
_(
"%(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

Check warning on line 93 in ge_dhl_base/models/dhl_request.py

View check run for this annotation

Codecov / codecov/patch

ge_dhl_base/models/dhl_request.py#L93

Added line #L93 was not covered by tests
1 change: 1 addition & 0 deletions ge_dhl_base/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Nikolaus Weingartmair <[email protected]> (https://www.grueneerde.com/)
1 change: 1 addition & 0 deletions ge_dhl_base/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module has common functionality for dhl api services.
Loading
Loading