Fulfilment and returns
The physical axis of a delivery note — picking, packages, carrier and tracking — and the return that brings goods and money back.
Once a delivery note exists, two questions remain that the document itself does not answer: is it ready, does the carrier have it, did it arrive — and, when it comes back, what do we owe. The first is the fulfilment axis, the second is the return.
The fulfilment axis is gated by the fulfilment module and returns by the
returns module, both from the Avanzado plan upwards.
A third axis, not a new state
A delivery note already has a commercial status. The physical cycle is a separate axis on the same document: moving it does not touch the commercial status, does not touch the public projection, and anyone subscribed to the delivery note's status change receives exactly what they received before.
pending → picking → prepared → handed_over → in_transit → delivered
│ │
└────────────┴──> failed ──> in_transitThere is one operation for the whole machine, not one route per step:
transition the fulfilment status
names the target in the body. The state machine stays the only authority: a
target that is not reachable from the current status is refused with 422
(business_rule_violation, subcode invalid_fulfilment_transition) and the
message names the current status and the ones it does admit by their labels. Read the catalog at
runtime with
fulfilment statuses.
failed is a real outcome with a way back: a delivery that did not happen
returns to in_transit on the next attempt instead of dead-ending.
Instants, attempts and the reason
The shipment publishes the instant of each stage of the physical axis, all in
ISO 8601 and all null while that stage has not happened: prepared_at,
handed_over_at, in_transit_at, delivered_at and failed_at. A new delivery
attempt after a failure moves in_transit_at. attempt numbers the delivery
attempts, and only once a delivery has failed: it is the number of failures while
the shipment is failed, and that number plus one while it is back in_transit
or delivered; it is null while no delivery has failed. The same keys travel in
reading the shipment,
in the fulfilment.* events and in the storefront tracking.
failure_reason is optional when the target of the transition is failed: a
failure is often recorded before anyone knows why, so it may be left out, sent as
null or sent blank, and all three record the failure without a reason (up to 500
characters when given). With any other target it is still refused, because it
would be a note nobody reads back. The shipment publishes it while it stays
failed, as null when it was recorded without one, and putting it back in
transit clears it.
Picking
Opening the picking list builds it from the lines the note has at that moment, one picking line per line, and returns it complete with the id of each line so you can start marking without a second read. Re-opening it replaces the previous list entirely.
Each picking line also tells the picker what to look for and where. sku and
catalog_name come from the current catalog article, read live (the copied
description remains the documentary truth); location gives the code and
name of the location of the last stock movement of that article in the warehouse
of the delivery note, as a hint of where to pick it from; and unassigned_quantity
is what has been picked and not yet distributed into any package. They are null
when they do not resolve: a line without an article, an article without SKU, a
note without a warehouse or an article that never moved with a location.
Three more things about the line are copied when the list is opened, so the
picker sees what the note said then and not what it says today: unit_code (the
UN/ECE code of the unit of the quantity, such as C62 or KGM),
presentation_label (for example «Box of 12») and note, the note of the line
for whoever picks it. All three are null
when the line has none, and editing the note of the delivery note afterwards does
not make the list stale.
A stale list
If the lines of the delivery note change after the list was opened, the list is
stale: is_stale is true and stale says what changed, line by line.
stale is null while the list is up to date. It carries changed_at and
changed_by (id and name of the author of that last edit, either null when
it is not on record), changes[] — one entry per line of the snapshot that no
longer matches, with its position, its kind (quantity, description or
removed; when both the quantity and the text changed, quantity wins) and what
the note has now in now_quantity and now_description (null on a removed
line) — and added[], the lines the note gained, each with description,
quantity, sku and location.
A stale list is never rewritten or deleted by itself. While it is stale, marking a
line and moving the axis to prepared are refused with 422 business_rule_violation
and subcode picking_list_is_stale, and the message says the remedy: reopen the
picking.
Reopening the preparation
Reopening is the remedy, and it empties the contents of the packages of the
shipment in the same transaction: what had been distributed into them pointed to
the lines of the snapshot that has just been replaced. The packages themselves are
kept, without contents. The response of
opening the list
says how many entries were emptied in cleared_package_contents (0 when there
were none); in any other response of the list the field is null. After reopening,
distribute the contents again from the new lines.
Marking a line records the picked quantity as a decimal string with four decimals, so articles picked by weight travel whole. Marking again overwrites, and marking zero undoes it — which is why the operation is not published as irreversible. You cannot pick more than the line asks for.
The picking queue
is the warehouse's work list, filterable by fulfilment status, carrier, origin
warehouse and the sales order the note came from; an id of another company gives an
empty page. list_state chooses what is queued: open (the default) lists the
notes with a picking list open, not_started the ones still to start — physical
status pending, no picking list and not cancelled — and all both groups. Each
item is a thin projection: the id and number of the note, its fulfilment status
with its label, and the ids of its warehouse and sales order.
The delivery note itself says where it comes from and where it leaves from:
sales_order ({id, number}, null for a note entered by hand) and warehouse
({id, name}, null when the note does not pin one).
The picking sheet
is the printable version of the list. When revisioned presentation is active for your
company (render_activation), it takes the
logo, the commercial identity, the typography and the colors of the company's own
template for warehouse sheets (document_kind logistic-sheet) when it has one and,
otherwise, of its main template in the
template library, and keeps its own
layout: its boxes to fill in by hand and its grouping by
location are the same with any template. Its heading also carries the number of the
delivery note as a Code 128 barcode. The code holds the number, never a URL: when a
barcode reader types it into the search of the shipments queue of the app and it
matches exactly one delivery note, the app opens that shipment. The
transfer note, the
goods receipt sheet
of a single entry and the numbered return sheet carry their number in the same
way.
Packages
Declaring a package takes a reference, a weight in kilograms, three dimensions in centimetres, notes and whether it is fragile — all optional, because a warehouse that only needs to count parcels declares them with nothing at all. Position is not part of the body: it is assigned deterministically.
fragile is a boolean that is false when omitted, and it is written when the package
is declared and on its partial update,
where omitting it keeps the current value. null, or anything that is not true or
false, is refused with 422 and param fragile, and nothing is saved. Every read of a
package carries the key, false unless the package was marked. The MCP tools
create_delivery_note_package, update_delivery_note_package,
list_delivery_note_packages and get_delivery_note_shipment take and return it with
the same rules.
Two printables come out of this: the
packing list
and the shipping label,
which by default is 100 × 150 mm and not A4. It carries one label per package,
numbered 1/2, 2/2 and so on, and accepts two query parameters. package_ids
prints only those packages, as a list of public identifiers, and keeps their
n/total numbering; omitted or empty it prints all of them, and a package that does
not belong to the delivery note answers 404. paper chooses the paper: thermal
(the default, one 100 × 150 mm label per page) or a4 (four labels per A4 sheet).
The paper is a choice of the call, not a setting stored for your company, and the
rest of the label is the same on every surface.
When revisioned presentation is active for your company, the packing list takes the
logo, the commercial identity, the typography and the colors of the company's own
template for warehouse sheets (document_kind logistic-sheet) when it has one and,
otherwise, of its main template in the
template library, and keeps its own
layout. The shipping label takes only the typography and always prints in
black, with the same size, the same grid on A4 and the same cut marks whatever the
template. A package marked fragile prints a FRAGILE notice on its label and a mark on
the packing list, and the delivery_instructions of the shipment print in a box on every
label of the shipment.
A package can also declare its contents: a list of up to 500 entries, each one a
picking line (picking_line_id) and the quantity of it packed there, with four
decimals. The contents distribute what was picked, so they need an open
picking list — otherwise the call is refused with 422 business_rule_violation,
param contents and subcode package_content_requires_picking_list — and the
units of one line, summed over all the packages of the delivery note, cannot
exceed what is prepared of it (422 business_rule_violation, subcode
package_content_exceeds_prepared). On update, omitting contents keeps them, []
empties them and a list replaces them as a whole; null is rejected. Reading a
package returns its contents (an empty list when nothing was distributed into
it), each entry with picking_line_id, position, description and quantity.
The packages block of the shipment carries total, total_weight_kg and
packages_without_weight. total_weight_kg is the sum of the weights, and it is
null when there are no packages or when any of them has no weight: a package
that was not weighed does not weigh zero, and a partial sum is never published as
the total. packages_without_weight says how many are missing.
Carriers and tracking
A carrier is a record in
your company with a name, a code that is the integration key (unique per
company, so a duplicate is refused with 422 naming code, never with 409), a
tracking kind and, when the kind says so, a tracking URL template.
A carrier can also carry its tax_id — a Spanish NIF, CIF or NIE with a valid
control character, optional, stored without spaces, hyphens or dots, and absent when
there is none — and a postal address (line, postal_code, city, province
and country as an ISO 3166-1 alpha-2 code; the street line and the city go
together). A transport control document (DeCA) proposed from a
delivery note of that carrier takes both: with tax_id the pre-fill copies it and
the address; without it the draft is saved incomplete and cannot be issued. For a
foreign carrier, leave tax_id empty and complete its identification on the
control document.
There is no integration with any carrier's API. Factuarea does not call
the carrier, does not poll it and does not receive its events. The tracking
link is composed: the template carries the placeholder
{tracking_number} and the URL is derived on every read by substituting
the escaped number. Nothing is stored, so fixing a carrier's template fixes
the link of every shipment it ever had, without rewriting a single row. Only
http and https templates are accepted.
The tracking kinds are url_template (the carrier publishes tracking at a URL
of its own), manual and store_provided.
Reading the shipment
returns the note, its fulfilment status, the carrier as an opaque id plus its
name, the free-text carrier the note already carried, the tracking number, the
derived tracking URL, the expected delivery date, the delivery_instructions and the
packages with their count and total weight (null while any package has no weight).
Updating the shipment
is partial and accepts exactly five fields: carrier, expected delivery date,
packages reference, tracking number and delivery_instructions. The tracking number has up to 100
characters, and null or an empty value removes it. It is a fact of the physical
cycle, so it is accepted whatever the commercial status of the delivery note is —
draft, delivered or invoiced — and refused with 422 only when the note is
cancelled or when the shipment has no carrier, either assigned or written as free
text on the note: a number nobody can track is not a tracking number. The update of
the delivery note itself writes the same field with the same rule. Assigning a
carrier does not overwrite the free-text carrier: the two travel together.
delivery_instructions is for whoever delivers the shipment — where to leave it, access
hours, who to ask for — as plain text of up to 300 characters. Omitting it keeps the
current text, and null or a blank text removes it. A text over 300 characters, a value
that is not text or a text with HTML markup is refused with 422 and param
delivery_instructions, and nothing is saved. Every read of the shipment carries the key,
null while there are none. It is not the free notes of the delivery note nor its
transport details, which keep their own use. When revisioned presentation is active for
your company, it prints in a box on the shipping label. The MCP tools
update_delivery_note_shipment and get_delivery_note_shipment take and return it with
the same rules.
Once it is handed over
From handed_over onwards — in_transit, delivered and failed included — the
carrier holds the parcels and the label, so the shipment stops accepting changes to
them. Adding, changing or removing a package (param packages) and assigning,
changing or detaching the carrier (param carrier_id) answer 422
fulfilment_already_handed_over with the
subcode shipment_handed_over. The tracking number stays editable. If the goods
have to come back, the route is a return.
Returns
A return is requested against a document you already issued: a delivery note, an invoice or a sales order. Before requesting anything, ask what is still returnable: line by line, how much was delivered, how much is already returned and how much is still returnable, plus the unit price and tax rate a request would inherit. A rejected return does not count as returned, so its share comes back to the returnable pool.
requested ──approve──> approved ──receive──> received ──refund──> refunded
│ │
└──reject──> rejected <┘Choosing the origin
The returnable origins
(returns/origins) lists the delivery notes, invoices and sales orders a return
can be requested against, newest first and with cursor pagination, filterable by
origin_type and searchable by number or customer. Each origin carries its number,
customer, date, return deadline and days left, how many lines it has, how many units
are already in live returns, its warehouse and, for an invoice, the delivery note
it covers. state tells you whether it is worth offering: ok, expired,
all_returned or not_delivered.
An origin that was never delivered cannot be returned: asking for its returnable
lines or requesting the return answers 422
return_origin_not_delivered. A client
should hide the not_delivered ones and show the expired and all_returned
ones as unavailable. Documents of another company never appear.
The ceiling is per shipment
What is returnable of an article is the lower of two figures: what is left of that line (delivered minus what live returns already take) and what is left of the same article in the whole shipment — the sales order, its delivery notes and its invoices — once the other returns of that shipment are subtracted. So the same goods cannot come back twice by going through the delivery note and then through the invoice. The ceiling applies when the return is requested, when it is edited and when it is approved.
Each returnable line publishes returned_elsewhere_quantity: what the same article
already has in live returns of other documents of the shipment, which is what
can make returnable_quantity lower than what the line alone would leave. When you
edit a return that is still requested, pass exclude_return_id so the return you
are editing does not count against itself. Service lines are listed with
non_returnable_reason set to service and a returnable quantity of zero.
Reading a return
A return has no number until it is approved. While it is requested, number is
null: it is not a provisional and not an empty string, and a document list that
shows it should print «no number» instead of inventing one. The same goes for the
returns that appear in the related_documents of a delivery note, a sales order or
an invoice.
Besides its lines and amounts, the return answers what a screen needs without a second read:
warehouse: the warehouse the goods will be booked back into, resolved exactly as the reception will resolve it, with itssource(declaredwhen the return pins it,inheritedwhen it is the one the goods left from,defaultwhen it is the default warehouse of your company). The list filters bywarehouse_idagainst that resolved warehouse, not only the declared one, and bysales_order_id.window(days,deadline,expired,unlimited) andorigin_date, while it is requested: the last day it can still be approved.buyer: who returns the goods, taken from the sales order and otherwise from the business contact — name, kind, tax id, email, phone, city and address.orderanddocuments[]: the chain of the sales order, its delivery notes, its invoices and the corrective invoice the refund issued, withis_originmarking the one the return was requested against.totals(base,vat,surcharge,retention,total), equal torefundable_amount.refund_blocker, for a received return:no_invoicewhen no invoice of the origin can be corrected,choose_invoicewhen several can and none is chosen, andnullwhen nothing blocks the refund.corrective_candidates_countsays how many there are.
Each line also publishes origin_line_id, sku, unit_code, variant_name,
presentation_name, delivered_quantity, returned_in_other_returns and
returnable_quantity.
Approving and rejecting
approve stamps the
definitive number of the return series. The number is consumed at that moment
and no operation gives it back, which is why an approved return can no longer
be deleted: deleting it would leave a permanent gap in the numbering.
approve accepts an optional send_sheet, true by default: the customer is told
about the authorization, for any kind of origin, with the return sheet
attached. Send false to approve without notifying.
reject takes a closed
rejection_reason: window_expired and exceeds_delivered are the two automatic
ones and manual_decision is the one a person takes, the only one that admits a
rejection_note. A system reason is accepted only when it applies to that return
now; otherwise the call answers 422
return_rejection_reason_not_applicable.
You do not have to guess: the detail of a requested or approved return publishes
rejection_reasons[] with code, label, applicable and
not_applicable_reason, computed with the same rule. notify_buyer (default
false) emails the customer the reason of the rejection — never the internal note.
The return sheet
The return sheet is a PDF of its
own, without amounts: what goes back, why and where to deliver it. It is marked
REQUEST or REJECTED while the return is in those states and carries the stamp of
received or refunded afterwards. Pass ?download=1 to get it as an attachment;
otherwise it is served inline. The file name is Devolucion_{id}.pdf, with the public identifier, while the return is requested or was rejected without ever being authorized, and Devolucion_{number}.pdf, with the slashes turned into hyphens, once it has a definitive number. When the plan of the company does not include returns the download answers 403 feature_not_available_in_plan, before the return is looked up.
When revisioned presentation is active for your company, the sheet takes the logo, the
commercial identity, the typography and the colors of the company's own template for
warehouse sheets (document_kind logistic-sheet) when it has one and, otherwise, of its
main template in the template library, and
keeps its own layout and its REQUEST or REJECTED watermark, which the watermark of the
template does not replace. Once the return has a number, the sheet also carries it as a
Code 128 barcode.
Sending the sheet emails it as
an attachment. Every field of the body is optional (to, cc, bcc, subject,
message); without to, the recipient is the buyer of the sales order or, failing
that, the email of the customer, and if none is found the call is refused as a
missing to. It is an email, so it asks for an Idempotency-Key, and the answer
only says that it was queued. A return that is still requested or that was rejected
is refused with 422 return_not_sendable; sending
does not change its status.
Receiving by line
receive records the
physical arrival. It takes the destination warehouse, the date it arrived and, now,
lines[]: for each line, the received_quantity and its condition — sellable,
defective, damaged or expired.
- Without
lines, every line arrived in full and sellable. Withlines, a line you do not list arrived as zero, and a line at zero is accepted. - If nothing arrives at all, the call answers 422
return_reception_empty; if a line arrives above what was authorised, 422return_received_exceeds_authorized. - A return that does not exist or belongs to another company is 404
return_not_found, with the same body with or withoutlines; a line of another return on a return of your own is 422 onlines.N.id. - Only the sellable quantity goes back into stock, and the value and the corrective
invoice come out of what was received, not out of what was asked for. Each line
then publishes
received_quantity,condition,condition_labelandrestocked_quantity(in the base unit of the article), which arenulluntil the return is received.
This call moves stock: it writes the incoming movement. When the return belongs to an order, receiving it also discounts the returned quantity from the sales order: its returned and pending quantities and its status follow, and a closed order records what came back without reopening. See Sales orders.
If an open delivery note already covers the stock of the destination, the sellable
goods are not booked twice. The response lists them in covered_targets (product,
warehouse and quantity), and sending register_covered_adjustment as true books
that entry as an adjustment.
Refunding
refund issues the
corrective invoice that returns the money. Its body carries only the invoice to
correct: when the origin resolves to exactly one invoice you can omit it, when
it resolves to none the call is rejected because there is nothing to correct,
and when it resolves to several you must name one — which is what
the corrective candidates read
is for. A return with no candidates answers with an empty list, not an error.
Each candidate says how much of what is being returned it contains in
covers_returned_lines (all, some or none) and whether it is the one to pick
in recommended: the only one that covers everything or, when none does, the only
one that covers part of it. At most one is recommended, and none when the choice is
not clear.
Before issuing anything, preview the refund.
It returns the invoice that would be corrected, the scope (total or partial),
the totals and the received lines, computed with the same selection and amounts as
the refund, so refunding against that invoice issues exactly that. It reserves no
number and changes nothing; pass target_invoice_id to preview a specific
candidate. It is refused with the same 422 as the refund.
What the buyer sees
The storefront tracking of an order (see Storefront) now follows the shipments. It keeps the flat keys, which describe the most recent shipment, and adds:
shipments[]: one entry per shipment with itsstage(preparing,handed_over,in_transit,delivered,failed),status,expected_delivery_date,carrier,tracking_number,tracking_url,package_count, thelinesit carries (description, quantity and unit) and the instant of each stage.pending[]: what has not left yet, one entry per order line with quantity still to ship.prepared_at,handed_over_at,in_transit_at,delivered_atandfailed_at, stamped on every transition of the fulfilment status, andattempt, the delivery attempt the shipment is on (nullwhile none has failed).order_expected_delivery_date: the delivery expected for the whole order, for when there is no shipment yet.
An order with no shipment is still a success: has_shipment is false and the lists
are empty.
Events
The physical axis publishes fulfilment.prepared, fulfilment.handed_over,
fulfilment.in_transit, fulfilment.delivered and fulfilment.failed, all
carrying the shipment. Returns publish return.requested, return.approved,
return.rejected, return.received and return.refunded. See
Events for the delivery body and how to subscribe.
Errors worth branching on
| Code | When |
|---|---|
carrier_not_found | The carrier is not yours, or does not exist. |
fulfilment_already_handed_over | The carrier has it: from that moment its parcels (param packages) and its carrier (param carrier_id) are fixed. Subcode shipment_handed_over. |
business_rule_violation with subcode package_content_requires_picking_list or package_content_exceeds_prepared | The contents of a package need an open picking list and cannot exceed what is prepared of each line (param contents). |
business_rule_violation with subcode picking_list_is_stale | The delivery note changed after the picking list was opened: marking a line or moving to prepared is refused until the picking is reopened. |
return_not_found | The return is not yours, or does not exist. |
return_window_expired | The window counted from the delivery has elapsed. Retrying does not reopen it. |
return_exceeds_delivered_quantity | The request asks for more than was delivered. The message names the line by its position in the request; param, details.scope (document or shipment) and details.returnable carry the rest. |
business_rule_violation with subcode return_order_cannot_be_edited | Deleting a return that is authorized, received or refunded: only a requested or a rejected return is deleted, and those two answer 204. |
return_origin_not_delivered | The origin was never delivered, so nothing of it can be returned (returns/origins marks it not_delivered). |
return_reception_empty | The reception declares every line at zero. |
return_received_exceeds_authorized | A line arrives above the quantity that was authorised. |
return_rejection_reason_not_applicable | The system reason chosen to reject does not apply to that return now; read rejection_reasons[] first. |
return_not_sendable | The sheet of a return that is still requested or was rejected cannot be sent. |
The full lists are the fulfilment error index and the return error index.
Where to go next
- Sales orders — where the delivery note came from.
- Inventory and warehouses — where a received return lands.
- Corrective invoices — the document a refund issues.
- Fulfilment tools in MCP and return tools — the same cycle for an agent.