Skip to content

Courier Documentation

Overview

The Courier module (courier) provides a simple registry for courier service providers used in delivery operations. This is a basic master data model for tracking which courier companies are used in the system.


Model Information

Model Name: courier
Display Name: Courier
Key Fields: None

Features

  • ❌ No audit logging
  • ❌ No multi-company support
  • ❌ No full-text search
  • ❌ No unique constraints

Key Fields Reference

Header Fields

Field Type Required Description
name Char Courier company name

API Methods

1. Create Courier

Method: create(vals, context)

Creates a new courier record.

Parameters:

vals = {
    "name": str,           # Courier company name
}

Returns: int - New record ID

Example:

# Create a courier service provider
courier_id = get_model("courier").create({
    "name": "DHL Express"
})


2. Search Couriers

Method: search_browse(condition, context)

Search and retrieve courier records.

Example:

# Get all couriers
couriers = get_model("courier").search_browse([])

# Search by name
dhl = get_model("courier").search_browse([
    ["name", "ilike", "DHL"]
])


Common Use Cases

Use Case 1: Register Courier Services

# Register multiple courier services
couriers = [
    "DHL Express",
    "FedEx International",
    "UPS Worldwide",
    "TNT Express",
    "Local Courier Service"
]

courier_ids = []
for courier_name in couriers:
    courier_id = get_model("courier").create({
        "name": courier_name
    })
    courier_ids.append(courier_id)

print(f"Registered {len(courier_ids)} courier services")

Use Case 2: List Available Couriers

# Get all registered couriers
couriers = get_model("courier").search_browse([])

print("Available Couriers:")
for courier in couriers:
    print(f"- {courier.name}")

Use Case 3: Update Courier Name

# Update courier name
courier_id = 1

get_model("courier").write([courier_id], {
    "name": "DHL Express Worldwide"
})

Model Relationship Description
stock.picking Referenced by Stock pickings may reference courier
sale.order Referenced by Sales orders may specify courier

Best Practices

1. Naming Convention

# Good: Use full official company names
get_model("courier").create({
    "name": "DHL Express"
})

# Avoid: Abbreviations or unclear names
get_model("courier").create({
    "name": "DHL"  # Which DHL service?
})

2. Avoid Duplicates

# Good: Check before creating
existing = get_model("courier").search([
    ["name", "=", "DHL Express"]
])

if not existing:
    get_model("courier").create({
        "name": "DHL Express"
    })
else:
    print("Courier already exists")

Performance Tips

1. Cache Courier Lists

# Good: Cache frequently used courier lists
_courier_cache = {}

def get_courier_by_name(name):
    if name not in _courier_cache:
        courier = get_model("courier").search_browse([
            ["name", "=", name]
        ])
        if courier:
            _courier_cache[name] = courier[0].id
    return _courier_cache.get(name)

Troubleshooting

No couriers showing in dropdown

Cause: No courier records created
Solution: Create courier records first

# Create default couriers
get_model("courier").create({"name": "Standard Courier"})

Duplicate courier names

Cause: No unique constraint on name field
Solution: Manually check for duplicates before creating

# Check for duplicates
name = "DHL Express"
existing = get_model("courier").search([["name", "=", name]])
if existing:
    print(f"Courier '{name}' already exists with ID {existing[0]}")

Testing Examples

Unit Test: Create Courier

def test_create_courier():
    # Create courier
    courier_id = get_model("courier").create({
        "name": "Test Courier Service"
    })

    # Verify creation
    assert courier_id is not None

    # Read back
    courier = get_model("courier").browse(courier_id)
    assert courier.name == "Test Courier Service"

    # Cleanup
    get_model("courier").delete([courier_id])

Security Considerations

Permission Model

  • Standard model permissions apply
  • No special security restrictions
  • Access controlled by user role

Data Access

  • All users with stock management access can view couriers
  • Admin rights required to create/modify couriers
  • No sensitive data stored

Version History

Last Updated: October 2025
Model File: courier.py
Framework: Netforce


Additional Resources

  • Stock Picking Documentation: stock.picking
  • Messenger Documentation: messenger
  • Shipping Method Documentation: ship.method

This documentation is generated for developer onboarding and reference purposes.