> For the complete documentation index, see [llms.txt](https://docs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akinon.com/technical-guides/oms/omnitron-shipment-client.md).

# Omnitron Shipment Client

`OmnitronShipmentClient` can produce a shipping label (cargo label) in two ways:

1. **Local generation (default):** The label is generated inside OMS via `get_label_data`.
2. **Fetch from Omnitron:** The label is retrieved from the shipping-info record on Omnitron (`cargo_label`).

Which path is used is controlled by two independent flags under `shipper_info.strategies`.

## <mark style="color:red;">Strategies</mark>

| Strategy                  | Default | Description                                                                                                                                                                                                                                                                                                                |
| ------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetch_label`             | `false` | If `true`, the label is fetched from Omnitron; if `false`, it is generated locally.                                                                                                                                                                                                                                        |
| `fetch_label_only_for_4p` | `false` | Only meaningful when `fetch_label = true`. If `true`, the label is fetched from Omnitron **only** for orders where `extra_field.is4P` evaluates to true; for all other orders the label is generated locally. If `false` (default), the `is4P` check is skipped and the label for **all** orders is fetched from Omnitron. |

### <mark style="color:red;">Behavior Table</mark>

| `fetch_label` | `fetch_label_only_for_4p` | `extra_field.is4P`            | Result                             |
| ------------- | ------------------------- | ----------------------------- | ---------------------------------- |
| `false`       | —                         | —                             | Label is generated **locally**     |
| `true`        | `false` *(default)*       | any                           | Label is **fetched from Omnitron** |
| `true`        | `true`                    | `true` / `"true"`             | Label is **fetched from Omnitron** |
| `true`        | `true`                    | `false` / missing / `"false"` | Label is generated **locally**     |

{% hint style="info" %}
The `is4P` value is supported both as a boolean (`true`) and as a string (`"true"`). For string values, case and leading/trailing whitespace are ignored (e.g. `" True "` is accepted as true). Any other value (`false`, `0`, `null`, or the field being absent entirely) is treated as "not 4P".
{% endhint %}

## <mark style="color:red;">How to Configure</mark> <mark style="color:red;"></mark><mark style="color:red;">`shipper_info`</mark> <mark style="color:red;"></mark><mark style="color:red;">in a Cargo Condition</mark>

In the example condition from the original question, `shipper_info` was empty:

```json
"conf": {
    "klass": "oms.shipments.clients.omnitron_shipment_client.OmnitronShipmentClient",
    "shipper_info": {}
}
```

If you want labels for 4P orders to be fetched from Omnitron, `shipper_info` should be filled in as follows:

```json
"conf": {
    "klass": "oms.shipments.clients.omnitron_shipment_client.OmnitronShipmentClient",
    "shipper_info": {
        "strategies": {
            "fetch_label": true,
            "fetch_label_only_for_4p": true
        }
    }
}
```

Full example of a cargo company condition:

```json
{
    "rules_configuration": {
        "rules": [
            {
                "klass": "oms.shipments.shipment_conditions.ChannelBasedOrdersCondition",
                "params": {
                    "conf": {
                        "klass": "oms.shipments.clients.omnitron_shipment_client.OmnitronShipmentClient",
                        "shipper_info": {
                            "strategies": {
                                "fetch_label": true,
                                "fetch_label_only_for_4p": true
                            }
                        }
                    },
                    "channels": [67],
                    "condition_type": "sales_channel"
                }
            }
        ]
    },
    "cargo_company": 34
}
```

{% hint style="info" %}
If you want labels to be fetched from Omnitron for **all** orders (without distinguishing 4P), either omit `fetch_label_only_for_4p` entirely or leave it as `false`; just `"fetch_label": true` is enough.
{% endhint %}

### <mark style="color:red;">Marking an Order as 4P</mark>

For the label to be fetchable from Omnitron (when `fetch_label_only_for_4p = true`), the order's `extra_field` must contain the `is4P` information:

```json
{
    "extra_field": {
        "is4P": true
    }
}
```

### <mark style="color:red;">API Service Used</mark>

When the `fetch_label` condition (and `is4P`, if required) is satisfied, the label is fetched from Omnitron via `OmnitronApiClient.get_shipping_info`.

* **Endpoint:** `GET /order_shipping_infos/?order={omnitron_id}&sort=-created_date`
* **Full URL:** `{OMNITRON_BASE_URL}/order_shipping_infos/?order={omnitron_id}&sort=-created_date`
* **Auth:** Omnitron client token header (added automatically by the client)
* The client takes the **first** record from the returned `results` list (the most recent one, due to `sort=-created_date`) and uses its `cargo_label` value as the label URL.

#### <mark style="color:red;">Example Request</mark>

```http
GET /order_shipping_infos/?order=12345&sort=-created_date HTTP/1.1
Host: <omnitron-host>
Authorization: Token <omnitron_token>
Content-Type: application/json
```

#### <mark style="color:red;">Example Response</mark>

```json
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "pk": 1,
            "order": 12345,
            "order_number": "6288872",
            "shipping_company": "other",
            "send_request": null,
            "send_response": {},
            "is_send": true,
            "cargo_label": "https://omnitron.example.com/cargo-label/123/",
            "modified_date": "2022-11-03T06:45:05.634999Z",
            "created_date": "2022-11-03T06:45:05.634976Z",
            "shipping_option_group": null
        }
    ]
}
```

### <mark style="color:red;">Return Value of OMS's</mark> <mark style="color:red;"></mark><mark style="color:red;">`get_shipping_label`</mark>

`get_shipping_label` returns a `(label_data, label_url)` tuple:

| Scenario                                                  | `label_data`         | `label_url`                                                              |
| --------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------ |
| Fetched from Omnitron (response present)                  | `None`               | `cargo_label` URL (e.g. `https://omnitron.example.com/cargo-label/123/`) |
| Fetched from Omnitron but `shipping_info` is empty/`None` | `None`               | `None`                                                                   |
| Generated locally                                         | `ContentFile` (HTML) | OMS label URL                                                            |

{% hint style="info" %}
On the Omnitron-fetch path, `label_data` is always `None`; the label arrives as an external URL (`label_url`). On the local-generation path, the label content is returned as a `ContentFile` inside `label_data`.
{% endhint %}

### <mark style="color:red;">Summary Flow</mark>

```
get_shipping_label(package)
        │
        ▼
fetch_label == true ?
        │ no  → generate locally (get_label_data)
        │ yes
        ▼
fetch_label_only_for_4p == true ?
        │ no  → fetch from Omnitron (get_shipping_info → cargo_label)
        │ yes
        ▼
order.extra_field.is4P true ?
        │ yes → fetch from Omnitron (get_shipping_info → cargo_label)
        │ no  → generate locally (get_label_data)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.akinon.com/technical-guides/oms/omnitron-shipment-client.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
