Skip to content
Merged
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
34 changes: 15 additions & 19 deletions delivery_dhl_parcel_de/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,30 @@ 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 an '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 Account number: ``3333333333`` (sandbox account)
* 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=``

5. Fill out the necessary information. The information below is only meant as an example:

* Company: Company Name
* DHL Weight UOM: ``KG``
* DHL Services Name: ``V53WPAK-DHL Paket``
* DHL Account number: ``3333333333`` (sandbox account)
* DHL Procedure number: ``01``
* DHL Participation number: ``02``
* DHL Package Info: Create package type
Expand All @@ -60,7 +56,7 @@ Create Delivery Methods

3. Save your changes

5. Save your changes
6. Save your changes


Testing
Expand Down
6 changes: 4 additions & 2 deletions delivery_dhl_parcel_de/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "DHL Parcel (Post & Parcel Germany) Integration",
"category": "Website",
"version": "18.0.1.0.0",
"version": "18.0.1.0.2",
"summary": """
Create DHL Parce DE shipments from Odoo,
update tracking information in Odoo from DHL,
Expand All @@ -10,12 +10,14 @@
"license": "AGPL-3",
"depends": [
"stock_delivery",
"delivery_carrier_account",
"base_iso3166",
"stock_picking_declared_value",
],
"data": [
"data/data.xml",
"data/ir_cron.xml",
"views/res_company.xml",
"views/carrier_account_views.xml",
"views/delivery_carrier.xml",
"views/stock_picking.xml",
],
Expand Down
45 changes: 45 additions & 0 deletions delivery_dhl_parcel_de/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<odoo noupdate="1">
<record id="dhl_stock_package_type" model="stock.package.type">
<field name="name">DHL Parcel DE</field>
<field name="package_carrier_type">dhl_parcel_de_provider</field>
<field name="packaging_length">5.00</field>
<field name="width">5.00</field>
<field name="height">5.00</field>
<field name="base_weight">0.50</field>
<field name="max_weight">10.00</field>
<field name="shipper_package_code">DHL-Paket</field>
</record>

<record id="dhl_carrier_account" model="carrier.account">
<field name="name">DHL Parcel DE Account</field>
<field name="delivery_type">dhl_parcel_de_provider</field>
<field name="account">3333333333</field>
<field name="password">dummy</field>
</record>

<record id="dhl_parcel_delivery_type" model="delivery.carrier">
<field name="name">DHL Parcel</field>
<field name="delivery_type">dhl_parcel_de_provider</field>
<field name="integration_level">rate_and_ship</field>
<field name="product_id" ref="delivery.product_product_delivery" />
<field name="sequence">15</field>
<field
name="dhl_parcel_de_provider_package_id"
ref="delivery_dhl_parcel_de.dhl_stock_package_type"
/>
<field
name="carrier_account_id"
ref="delivery_dhl_parcel_de.dhl_carrier_account"
/>
<field name="dhl_weight_uom">kg</field>
<field name="dhl_services_name">V01PAK</field>
<field name="dhl_premium" eval="False" />
<field name="dhl_export_type_description">DHL Parcel</field>
<field name="dhl_procedure_no">01</field>
<field name="dhl_participation_no">01</field>
<field name="dhl_bulky_goods" eval="False" />
<field name="dhl_endorsement">RETURN</field>
<field name="dhl_document_format">PDF</field>
<field name="dhl_export_type">OTHER</field>
</record>
</odoo>
7 changes: 5 additions & 2 deletions delivery_dhl_parcel_de/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" ?>
<odoo>
<data noupdate="1">
<record id="dhl_parcel_de_authentication_cron" model="ir.cron">
<record id="dhl_parcel_de_authentication_delivery_account_cron" model="ir.cron">
<field name="name">DHL Parcel DE Authentication Process</field>
<field name="interval_number">10</field>
<field name="interval_type">minutes</field>
<field name="model_id" ref="model_res_company" />
<field
name="model_id"
ref="delivery_carrier_account.model_carrier_account"
/>
<field name="code">model.dhl_parcel_de_get_access_token_cron()</field>
<field name="active" eval="True" />
<field name="state">code</field>
Expand Down
14 changes: 7 additions & 7 deletions delivery_dhl_parcel_de/data/neutralize.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-- remove DHL credentials and DHL account number on delivery carriers
UPDATE res_company
SET dhl_userid = NULL,
dhl_password = NULL,
UPDATE carrier_account
SET account = '3333333333',
dhl_userid = NULL,
password = 'SandboxPasswort2023!',
dhl_api_key = NULL,
dhl_api_secret = NULL,
dhl_access_token = NULL,
dhl_parcel_de_api_url = 'https://api-sandbox.dhl.com';
dhl_parcel_de_api_url = 'https://api-sandbox.dhl.com'
WHERE delivery_type = 'dhl_parcel_de_provider';
UPDATE delivery_carrier
SET dhl_account_no = NULL,
prod_environment = false
SET prod_environment = false
WHERE delivery_type = 'dhl_parcel_de_provider';
108 changes: 108 additions & 0 deletions delivery_dhl_parcel_de/migrations/18.0.1.0.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)


def migrate(cr, version):
"""Transfer DHL data from res.company to carrier.account"""
_logger.info("Starting post-migration: Transferring DHL data to carrier.account")

env = api.Environment(cr, SUPERUSER_ID, {})

# Validate prerequisites
if "carrier.account" not in env:
return _logger.warning("carrier.account model not found, skipping migration")

cr.execute(
"SELECT EXISTS ("
"SELECT FROM information_schema.tables "
"WHERE table_name = 'temp_dhl_company_data'"
")"
)
if not cr.fetchone()[0]:
return _logger.error("Temporary table 'temp_dhl_company_data' does not exist")

# Get the DHL delivery carrier(s)
dhl_carrier = env.ref("delivery_dhl_parcel_de.dhl_parcel_delivery_type", False)
if not dhl_carrier:
return _logger.warning("DHL delivery carrier not found, skipping migration")
_logger.info(f"Found {len(dhl_carrier)} DHL carrier")

# Get company data
cr.execute("SELECT * FROM temp_dhl_company_data")
companies_data = cr.dictfetchall()
if not companies_data:
return _logger.info("No company data found in temporary table")

# Get carrier.account fields
cr.execute(
"SELECT column_name "
"FROM information_schema.columns "
"WHERE table_name = 'carrier_account'"
)
carrier_fields = {row[0] for row in cr.fetchall()}

field_mapping = [
"dhl_parcel_de_api_url",
"dhl_userid",
"password",
"dhl_api_key",
"dhl_api_secret",
"dhl_tracking_url",
"dhl_access_token",
]

success = failed = 0

for data in companies_data:
try:
company_id = data.pop("company_id")

existing = env.ref("delivery_dhl_parcel_de.dhl_carrier_account")
if (
existing
and existing.dhl_userid
and existing.password
and existing.dhl_api_key
):
_logger.info("Already migrated")
continue

account_vals = {
"company_id": company_id,
"carrier_id": dhl_carrier.id,
**{
k: v
for k, v in data.items()
if v and k in carrier_fields and k in field_mapping
},
}

if existing:
update_vals = {
k: v
for k, v in account_vals.items()
if k not in ["company_id", "carrier_id"]
}
if update_vals:
existing.write(update_vals)
success += 1
else:
env["carrier.account"].create(account_vals)
success += 1

except Exception as e:
failed += 1
_logger.error(
f"Error processing company {data.get('company_id', 'unknown')}: {e}"
)

_logger.info(f"Migration completed: {success} successful, {failed} failed")

# Archive temp table
cr.execute(
"ALTER TABLE IF EXISTS temp_dhl_company_data "
"RENAME TO temp_dhl_company_data_archived"
)
92 changes: 92 additions & 0 deletions delivery_dhl_parcel_de/migrations/18.0.1.0.2/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import logging

_logger = logging.getLogger(__name__)


def migrate(cr, version):
"""Store res.company DHL data before carrier.account exists"""
_logger.info("Starting pre-migration: Storing DHL data from res.company")

# First, check if the fields exist in res.company
cr.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'res_company'
AND column_name IN (
'use_dhl_parcel_de_shipping_provider',
'dhl_parcel_de_api_url',
'dhl_userid',
'dhl_password',
'dhl_api_key',
'dhl_api_secret',
'dhl_tracking_url',
'dhl_access_token'
)
""")

existing_columns = [row[0] for row in cr.fetchall()]
if existing_columns:
_logger.info(f"Found columns in res.company: {existing_columns}")
# Create a temporary table to store the data
# Using IF NOT EXISTS to avoid errors if script runs multiple times
cr.execute("""
CREATE TEMP TABLE IF NOT EXISTS temp_dhl_company_data (
company_id INTEGER,
use_dhl_parcel_de_shipping_provider BOOLEAN,
dhl_parcel_de_api_url VARCHAR,
dhl_userid VARCHAR,
password VARCHAR,
dhl_api_key VARCHAR,
dhl_api_secret VARCHAR,
dhl_tracking_url VARCHAR,
dhl_access_token VARCHAR
)
""")

# Clear existing data in temp table (in case of re-run)
cr.execute("DELETE FROM temp_dhl_company_data")

# Insert data from res.company
cr.execute("""
INSERT INTO temp_dhl_company_data (
company_id,
use_dhl_parcel_de_shipping_provider,
dhl_parcel_de_api_url,
dhl_userid,
password,
dhl_api_key,
dhl_api_secret,
dhl_tracking_url,
dhl_access_token
)
SELECT
id as company_id,
use_dhl_parcel_de_shipping_provider,
dhl_parcel_de_api_url,
dhl_userid,
dhl_password,
dhl_api_key,
dhl_api_secret,
dhl_tracking_url,
dhl_access_token
FROM res_company
WHERE use_dhl_parcel_de_shipping_provider = true
""")

# Get count of records migrated
cr.execute("SELECT COUNT(*) FROM temp_dhl_company_data")
count = cr.fetchone()[0]

_logger.info(
f"Successfully stored {count} companies with DHL enabled in temporary table"
)

# Optional: Verify the data was stored correctly
if count > 0:
cr.execute(
"SELECT company_id, dhl_userid FROM temp_dhl_company_data LIMIT 5"
)
sample_data = cr.fetchall()
_logger.info(f"Sample data from temp table: {sample_data}")
else:
_logger.warning("Not found columns in res.company")
2 changes: 1 addition & 1 deletion delivery_dhl_parcel_de/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import delivery_carrier
from . import package_details
from . import res_company
from . import carrier_account
from . import stock_picking
Loading
Loading