Skip to content

Stock Container Documentation

Overview

The Stock Container module (stock.container) manages physical containers, pallets, boxes, and packaging units used to organize and transport inventory. Containers group stock items together for efficient handling, shipping, and tracking throughout the supply chain.


Model Information

Model Name: stock.container
Display Name: Container
Key Fields: number

Features

  • ✅ Audit logging enabled
  • ❌ Multi-company support (not enforced)
  • ❌ Auto-sync disabled
  • ✅ Unique key constraint on number

Container Types

Type Code Description
Primary 1 Main container (pallet, box, etc.)
Secondary 2 Secondary/inner container

Container States

State Description
active Container in use
inactive Container retired/not in use

Key Fields Reference

Header Fields

Field Type Required Description
number Char Unique container number/ID
type Selection Primary (1) or Secondary (2)
state Selection active/inactive
description Text Container description

Content Tracking

Field Type Description
contents Json Current container contents (computed)
lot_numbers Text Range of lot numbers (computed)
new_lot_range Text Manually entered lot range

Relationship Fields

Field Type Description
comments One2Many Discussion thread
documents One2Many Attached documents
stock_moves One2Many Stock movements
validate_lines One2Many Validation records
stock_balances One2Many Current stock in container

API Methods

1. Create Container

Method: create(vals, context)

Creates a new container.

Example:

# Auto-generated container number
container_id = get_model("stock.container").create({
    "type": "1",  # Primary container
    "state": "active",
    "description": "Pallet for shipment to Customer ABC"
})

# Manual container number
manual_container = get_model("stock.container").create({
    "number": "PALLET-2025-001",
    "type": "1",
    "state": "active"
})


2. Get Contents

Method: get_contents(ids, context)

Returns detailed contents of container(s).

Returns: Json structure with product, lot, qty information

Example:

container = get_model("stock.container").browse(container_id)
contents = container.contents

for item in contents:
    print(f"Product {item['product_id']}: {item['qty']} units")


3. Get Lot Numbers

Method: get_lot_numbers(ids, context)

Returns formatted lot number ranges within container.

Example:

container = get_model("stock.container").browse(container_id)
lot_range = container.lot_numbers
print(f"Container contains lots: {lot_range}")


Common Use Cases

Use Case 1: Create Shipping Pallet

# 1. Create container/pallet
pallet_id = get_model("stock.container").create({
    "type": "1",
    "state": "active",
    "description": "Shipment to Customer XYZ"
})

# 2. Move products into container
picking_vals = {
    "type": "internal",
    "journal_id": transfer_journal_id,
    "container_id": pallet_id,
    "lines": [
        ("create", {
            "product_id": 100,
            "qty": 48,
            "container_id": pallet_id,
            "location_from_id": warehouse_loc,
            "location_to_id": shipping_loc
        })
    ]
}

pick_id = get_model("stock.picking").create(picking_vals)
get_model("stock.picking").set_done([pick_id])

Use Case 2: Nested Containers

# Primary container (pallet)
pallet_id = get_model("stock.container").create({
    "number": "PALLET-A-001",
    "type": "1"
})

# Secondary containers (boxes)
for i in range(1, 11):
    box_id = get_model("stock.container").create({
        "number": f"BOX-A-{i:03d}",
        "type": "2"
    })

Use Case 3: Container Transfer

# Transfer entire container
result = get_model("stock.picking").transfer_containers_fast(
    journal_id=transfer_journal_id,
    container_ids=[container_id],
    vals={"ref": "Container relocation"}
)

Best Practices

1. Use Container Types Appropriately

# Primary for pallets/large containers
pallet = {"type": "1", "number": "PALLET-001"}

# Secondary for boxes/inner packaging
box = {"type": "2", "number": "BOX-001"}

2. Deactivate Instead of Delete

# Good: Preserve history
get_model("stock.container").write([container_id], {
    "state": "inactive"
})

Model Relationship Description
stock.move One2Many Movements using this container
stock.balance One2Many Current stock in container
stock.picking Indirect Container transfers

Troubleshooting

"Container number must be unique"

Cause: Duplicate container number
Solution: Use unique numbers or auto-generate

"Container contents not showing"

Cause: No stock balances in container
Solution: Check stock_moves for movement history


This documentation is generated for developer onboarding and reference purposes.