Skip to content

Port Loading Documentation

Overview

The Port Loading module (port.loading) tracks loading ports for export shipments. Identical in structure to port.destination but used for origin/departure ports where goods are loaded onto vessels.


Model Information

Model Name: port.loading
Display Name: Port Loading
Key Fields: None

Features

  • ❌ No audit logging
  • ❌ No multi-company support
  • ✅ Search enabled on name, code, country
  • ✅ Unique code constraint
  • ✅ Custom name_get formatting

Understanding Key Fields

Unique Code Constraint

_sql_constraints = [
    ("code_uniq", "unique (code)", "Code must be unique")
]

Each port loading code must be globally unique to prevent duplicates.


Key Fields Reference

Field Type Required Description
name Char Port name (searchable)
code Char Unique port code (searchable, unique)
description Text Additional details
country_id Many2One Country location (searchable)

Default Order: Ordered by code


API Methods

name_get

Returns formatted display names: "[CODE] Name"

Example:

names = get_model("port.loading").name_get([1, 2])
# Returns: [(1, "[CNSHA] Shanghai Port", None), 
#           (2, "[USNYC] New York", None)]


Common Use Cases

Use Case 1: Setup Export Loading Ports

# Major export ports
loading_ports = [
    {
        "code": "CNSHA",
        "name": "Shanghai Port",
        "description": "China's largest port for exports",
        "country_id": china_id
    },
    {
        "code": "CNYTN",
        "name": "Yantian Port",
        "description": "Major container port in Shenzhen",
        "country_id": china_id
    },
    {
        "code": "USNYC",
        "name": "Port of New York/New Jersey",
        "description": "Major US East Coast export port",
        "country_id": usa_id
    },
    {
        "code": "USLAX",
        "name": "Port of Los Angeles",
        "description": "Largest US West Coast port",
        "country_id": usa_id
    }
]

for port in loading_ports:
    get_model("port.loading").create(port)

Use Case 2: Match Loading to Destination

def create_shipping_route(loading_code, destination_code):
    """Create route between loading and destination ports"""

    loading = get_model("port.loading").search_browse([
        ["code", "=", loading_code]
    ])

    destination = get_model("port.destination").search_browse([
        ["code", "=", destination_code]
    ])

    if not loading:
        raise ValueError(f"Loading port {loading_code} not found")
    if not destination:
        raise ValueError(f"Destination port {destination_code} not found")

    route = {
        "from_port": f"[{loading[0].code}] {loading[0].name}",
        "to_port": f"[{destination[0].code}] {destination[0].name}",
        "from_country": loading[0].country_id.name,
        "to_country": destination[0].country_id.name
    }

    return route

# Usage
route = create_shipping_route("CNSHA", "USLAX")
print(f"Route: {route['from_port']}{route['to_port']}")

Model Relationship Description
country Many2One Port location country
port.destination Related Destination ports for shipments
sale.order Referenced by Export orders specify loading port
stock.picking Referenced by Export pickings track loading port

Best Practices

1. Use Standard Port Codes

# Good: UN/LOCODE format
get_model("port.loading").create({
    "code": "CNSHA",  # CN=China, SHA=Shanghai
    "name": "Shanghai Port",
    "country_id": china_id
})

2. Coordinate with Destination Ports

# Ensure loading and destination ports exist
def setup_trade_lane(export_port, import_port):
    # Check/create loading port
    loading = get_model("port.loading").search([
        ["code", "=", export_port["code"]]
    ])
    if not loading:
        loading_id = get_model("port.loading").create(export_port)

    # Check/create destination port
    destination = get_model("port.destination").search([
        ["code", "=", import_port["code"]]
    ])
    if not destination:
        dest_id = get_model("port.destination").create(import_port)

    print(f"Trade lane ready: {export_port['code']}{import_port['code']}")

Version History

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


Additional Resources

  • Port Destination Documentation: port.destination
  • Shipping Port Documentation: ship.port
  • Country Documentation: country

This documentation is generated for developer onboarding and reference purposes.