From 0d20221ab25ea2a92bb254e9f147beb35c1109ea Mon Sep 17 00:00:00 2001 From: Hitesh Jadav Date: Fri, 27 Feb 2026 18:43:16 +0530 Subject: [PATCH 01/12] [18.0][IMP] delivery_dhl_parcel_de: Added DHL configuration in delivery method account --- delivery_dhl_parcel_de/README.rst | 32 +++++------ delivery_dhl_parcel_de/__manifest__.py | 3 +- delivery_dhl_parcel_de/data/ir_cron.xml | 4 +- delivery_dhl_parcel_de/models/__init__.py | 2 +- .../{res_company.py => carrier_account.py} | 10 ++-- .../models/delivery_carrier.py | 14 ++--- .../models/stock_picking.py | 6 +- .../views/carrier_account_views.xml | 56 +++++++++++++++++++ delivery_dhl_parcel_de/views/res_company.xml | 56 ------------------- 9 files changed, 90 insertions(+), 93 deletions(-) rename delivery_dhl_parcel_de/models/{res_company.py => carrier_account.py} (93%) create mode 100644 delivery_dhl_parcel_de/views/carrier_account_views.xml delete mode 100644 delivery_dhl_parcel_de/views/res_company.xml diff --git a/delivery_dhl_parcel_de/README.rst b/delivery_dhl_parcel_de/README.rst index abd263d8..e6924563 100644 --- a/delivery_dhl_parcel_de/README.rst +++ b/delivery_dhl_parcel_de/README.rst @@ -15,29 +15,25 @@ Note that shipping rates are not retrieved from DHL but need to be configured. Configuration ------------- -Company -^^^^^^^ - -1. "Settings" -> "Users & Companies" -> "Companies" -2. Select or create a company -3. "DHL Parcel DE Configuration" tab -> set the "Use DHL Parcel DE Shipping Provider" as active -4. Fill out the necessary information. The information below is only meant for testing purposes: - - * DHL API URL: ``https://api-sandbox.dhl.com`` - * DHL UserId: ``user-valid`` - * DHL Password: ``SandboxPasswort2023!`` - * DHL API Key: Add your own API key here - * DHL Tracking URL: (optional) Leave empty or use: ``https://www.dhl.de/en/privatkunden/pakete-empfangen/verfolgen.html?piececode=`` - -5. Save your changes - Create Delivery Methods ^^^^^^^^^^^^^^^^^^^^^^^ 1. "Inventory" -> "Configuration" -> "Delivery" -> "Delivery Methods" 2. Select or create a method 3. Set the "Provider" to "DHL Parcel DE" -4. Fill out the necessary information. The information below is only meant as an example: +4. Select or create a 'Account'. + 1. Choose the Delivery Type 'DHL Parcel DE' in the Account form view to display the DHL fields + + 2. Fill in the necessary information in the 'Account' form. The values below are for testing purposes only: + + * DHL API URL: ``https://api-sandbox.dhl.com`` + * DHL UserId: ``user-valid`` + * DHL Password: ``SandboxPasswort2023!`` + * DHL API Key: Add your own API key here + * DHL API Secret: Add your own API secret here + * DHL Tracking URL: (optional) Leave empty or use: ``https://www.dhl.de/en/privatkunden/pakete-empfangen/verfolgen.html?piececode=`` + +7. Fill out the necessary information. The information below is only meant as an example: * Company: Company Name * DHL Weight UOM: ``KG`` @@ -60,7 +56,7 @@ Create Delivery Methods 3. Save your changes -5. Save your changes +8. Save your changes Testing diff --git a/delivery_dhl_parcel_de/__manifest__.py b/delivery_dhl_parcel_de/__manifest__.py index 8e7ce40a..38b0f27e 100644 --- a/delivery_dhl_parcel_de/__manifest__.py +++ b/delivery_dhl_parcel_de/__manifest__.py @@ -10,12 +10,13 @@ "license": "AGPL-3", "depends": [ "stock_delivery", + "delivery_carrier_account", "base_iso3166", "stock_picking_declared_value", ], "data": [ "data/ir_cron.xml", - "views/res_company.xml", + "views/carrier_account_views.xml", "views/delivery_carrier.xml", "views/stock_picking.xml", ], diff --git a/delivery_dhl_parcel_de/data/ir_cron.xml b/delivery_dhl_parcel_de/data/ir_cron.xml index 73d5db84..a9e44e5e 100644 --- a/delivery_dhl_parcel_de/data/ir_cron.xml +++ b/delivery_dhl_parcel_de/data/ir_cron.xml @@ -1,11 +1,11 @@ - + DHL Parcel DE Authentication Process 10 minutes - + model.dhl_parcel_de_get_access_token_cron() code diff --git a/delivery_dhl_parcel_de/models/__init__.py b/delivery_dhl_parcel_de/models/__init__.py index 482467fd..c19b3fce 100644 --- a/delivery_dhl_parcel_de/models/__init__.py +++ b/delivery_dhl_parcel_de/models/__init__.py @@ -1,4 +1,4 @@ from . import delivery_carrier from . import package_details -from . import res_company +from . import carrier_account from . import stock_picking diff --git a/delivery_dhl_parcel_de/models/res_company.py b/delivery_dhl_parcel_de/models/carrier_account.py similarity index 93% rename from delivery_dhl_parcel_de/models/res_company.py rename to delivery_dhl_parcel_de/models/carrier_account.py index ccaa3e5d..aebc434d 100644 --- a/delivery_dhl_parcel_de/models/res_company.py +++ b/delivery_dhl_parcel_de/models/carrier_account.py @@ -1,11 +1,11 @@ import requests -from odoo import fields, models +from odoo import api, fields, models from odoo.exceptions import ValidationError -class ResCompany(models.Model): - _inherit = "res.company" +class CarrierAccount(models.Model): + _inherit = "carrier.account" use_dhl_parcel_de_shipping_provider = fields.Boolean( copy=False, @@ -94,7 +94,7 @@ def dhl_parcel_de_get_access_token(self): raise ValidationError(e) # noqa: B904 def dhl_parcel_de_get_access_token_cron(self): - for company_id in self.search( + for carrier_account_id in self.search( [("use_dhl_parcel_de_shipping_provider", "=", True)] ): - company_id.dhl_parcel_de_get_access_token() + carrier_account_id.dhl_parcel_de_get_access_token() diff --git a/delivery_dhl_parcel_de/models/delivery_carrier.py b/delivery_dhl_parcel_de/models/delivery_carrier.py index 2f6e7c28..5524fdc8 100644 --- a/delivery_dhl_parcel_de/models/delivery_carrier.py +++ b/delivery_dhl_parcel_de/models/delivery_carrier.py @@ -507,9 +507,9 @@ def dhl_parcel_de_provider_send_shipping(self, picking): header = { "accept": "application/json", "Content-Type": "application/json", - "Authorization": f"Bearer {self.company_id.dhl_access_token}", + "Authorization": f"Bearer {self.carrier_account_id.dhl_access_token}", } - api_url = f"{self.company_id.dhl_parcel_de_api_url}/parcel/de/shipping/v2/orders?docFormat={self.dhl_document_format}" # noqa: E501 + api_url = f"{self.carrier_account_id.dhl_parcel_de_api_url}/parcel/de/shipping/v2/orders?docFormat={self.dhl_document_format}" # noqa: E501 request_type = "POST" ( response_status, @@ -580,9 +580,9 @@ def dhl_parcel_de_provider_send_shipping(self, picking): raise ValidationError(e) from e def dhl_parcel_de_provider_cancel_shipment(self, picking): - company_id = self.company_id + carrier_account_id = self.carrier_account_id try: - api_url = f"{self.company_id.dhl_parcel_de_api_url}/parcel/de/shipping/v2/orders?profile=STANDARD_GRUPPENPROFIL" # noqa: E501 + api_url = f"{carrier_account_id.dhl_parcel_de_api_url}/parcel/de/shipping/v2/orders?profile=STANDARD_GRUPPENPROFIL" # noqa: E501 awb_numbers = picking.carrier_tracking_ref.split(",") for shipment in awb_numbers: api_url += f"&shipment={shipment}" @@ -590,7 +590,7 @@ def dhl_parcel_de_provider_cancel_shipment(self, picking): header = { "accept": "application/json", "Content-Type": "application/json", - "Authorization": f"Bearer {company_id.dhl_access_token}", + "Authorization": f"Bearer {carrier_account_id.dhl_access_token}", } request_type = "DELETE" ( @@ -609,9 +609,9 @@ def dhl_parcel_de_provider_cancel_shipment(self, picking): raise ValidationError(e) from e def dhl_parcel_de_provider_get_tracking_link(self, picking): - if self.company_id and self.company_id.dhl_tracking_url: + if self.carrier_account_id and self.carrier_account_id.dhl_tracking_url: tracking_no = (picking.carrier_tracking_ref).split(",") for number in tracking_no: - return f"{self.company_id.dhl_tracking_url}{number}" + return f"{self.carrier_account_id.dhl_tracking_url}{number}" else: raise ValidationError(_("Please Set Tracking URL In Company")) diff --git a/delivery_dhl_parcel_de/models/stock_picking.py b/delivery_dhl_parcel_de/models/stock_picking.py index 6e00659d..c5e5bf69 100644 --- a/delivery_dhl_parcel_de/models/stock_picking.py +++ b/delivery_dhl_parcel_de/models/stock_picking.py @@ -22,7 +22,7 @@ def dhl_parcel_de_provider_return_shipment(self): """ try: carrier_id = self.carrier_id - company_id = carrier_id.company_id + carrier_account_id = carrier_id.carrier_account_id shipper_address_error = carrier_id.check_address_details( self.partner_id, ["zip", "city", "street"] ) @@ -70,9 +70,9 @@ def dhl_parcel_de_provider_return_shipment(self): ) headers = { "content-type": "application/json", - "Authorization": f"Bearer {company_id.dhl_access_token}", + "Authorization": f"Bearer {carrier_account_id.dhl_access_token}", } - api_url = f"{company_id.dhl_parcel_de_api_url}/parcel/de/shipping/returns/v1/orders?labelType=SHIPMENT_LABEL" # noqa: E501 + api_url = f"{carrier_account_id.dhl_parcel_de_api_url}/parcel/de/shipping/returns/v1/orders?labelType=SHIPMENT_LABEL" # noqa: E501 request_type = "POST" response_status, response_data = ( carrier_id.dhl_parcel_de_provider_create_shipment( diff --git a/delivery_dhl_parcel_de/views/carrier_account_views.xml b/delivery_dhl_parcel_de/views/carrier_account_views.xml new file mode 100644 index 00000000..a4544dda --- /dev/null +++ b/delivery_dhl_parcel_de/views/carrier_account_views.xml @@ -0,0 +1,56 @@ + + + + carrier.account.form.inherit.dhl + carrier.account + + + + + + + + + + +