Sales orders: the order header and its operations
Addon sale (depends on sales_team, product, mail and account), crate erp-addon-sale.
It ships sale.order and its lines with prices, taxes and totals. The order is a thread model with
activities. ADR 0199 governs the addon.
Fields
Section titled “Fields”| Field | Rule |
|---|---|
name | The order number, drawn at creation (below). A name given at create is kept; after create no client write changes it. |
company_id, partner_id | Required. The company defaults to the current one. |
state | draft, sent, sale, cancel; changed only by the operations. |
locked | Changed only by action_lock and action_unlock. |
date_order | Creation time; set to the confirmation time by action_confirm. |
partner_invoice_id, partner_shipping_id | Stored, editable; computed from the customer’s invoice and delivery contacts (res.partner.address_get). |
user_id | Salesperson, stored, editable: the customer’s salesperson (res.partner.user_id), else the commercial partner’s, else the current user when they are a salesperson. A saved order keeps its salesperson. |
team_id | Stored, editable: crm.team._get_default_team_id for the salesperson in the order’s company, the order’s present team preferred. |
client_order_ref, origin, commitment_date, validity_date, tag_ids, note | Plain editable fields. |
Numbering
Section titled “Numbering”An order created without a name, or with the placeholder New, takes the next number of the
sequence record with code sale.order for its company: a record of that company wins over the
shared one. The addon ships the shared record sale.seq_sale_order (prefix S, padding 5, as fields
of the record, noupdate). The draw goes through erp_sdk::sequence::draw_by_code. Without a record
for the company, the create is refused with a user error naming the code and the company; an order
is never saved without a number.
Operations
Section titled “Operations”Each operation is an RPC method with effect = write that acts on the whole record set. It locks
the rows in id order, reads the states, refuses the whole call when one order is not in a legal
source state (the error names the orders and their states), and writes through the base write.
| Operation | From | To |
|---|---|---|
action_quotation_sent | draft | sent |
action_confirm | draft, sent | sale, then locked when the setting is on |
action_cancel | draft, sent, sale, not locked | cancel |
action_draft | sent, cancel | draft |
action_lock | sale | locked; Sales administrators only |
action_unlock | locked | unlocked; Sales administrators only |
| delete | draft, cancel | removed |
Cancel, lock and unlock succeed without writing when the order is already in their end state.
action_confirm keeps the batched state and date writes, the confirmation hook and the
auto-lock step in one savepoint. A refusal rolls back their database changes and preserves
earlier work in the caller’s transaction. Confirmation extensions should perform their
transactional work through the supplied transaction.
Client writes
Section titled “Client writes”write refuses state, locked, invoicing_closed, invoice_status, delivery_status and
name in every state, also with sudo (create refuses the same fields except name, and refuses
them as default_<field> context keys too), any field of a cancelled order, the customer of a
confirmed order, the company of a confirmed order and of a quotation that has lines (a quotation
without lines may change company), and the protected fields of a locked order (order_line among
them). All are validation errors that name the field or the order. A create without invoice or delivery address
takes the customer’s (address_get) before the INSERT, since both fields are required.
Seams for satellite addons
Section titled “Seams for satellite addons”Override these with #[method(override)] and call sup once (ADR 0199 D4):
| Method | Result |
|---|---|
_confirmation_error_message | Option<String>: the first refusal of a confirmation |
_prepare_confirmation_values | Vals<SaleOrder>: what a confirmation writes; add values through field handles |
_action_confirm | (): the step where satellites act; empty in sale |
_should_be_locked | Records: the orders a confirmation locks |
_action_cancel | (): the cancel step; writes state = cancel in sale |
_get_protected_fields | ProtectedFields<SaleOrder>: the header fields a locked order refuses |
#[method(override)]async fn _get_protected_fields( this: &RecordSet<SaleOrder>, tx: &mut Transaction, sup: Super,) -> Result<ProtectedFields<SaleOrder>> { let base: ProtectedFields<SaleOrder> = sup.call(tx, this.as_records(), ()).await?; Ok(base.with(SaleOrderCarrier::CARRIER_ID))}ProtectedFields::with takes a field handle of the order or of an extension of it, so a field that
does not exist cannot be named.
Order lines
Section titled “Order lines”sale.order.line (company rule by its company and through its order; the Sales administrator has full access).
A line is a product line (display_type empty) or a section, subsection or note line. Database
checks: a product line has a unit; a section or note line has no product, unit, price, quantity or
lead time (create clears them); the lead time is zero or more.
| Field | Rule |
|---|---|
product_id, name | The description is the product’s name unless written. |
product_uom_qty, product_uom_id | Quantity (default 1) and unit (the product’s unit unless written). |
allowed_uom_ids | The product’s units (product.product._get_available_uoms): its unit, plus its other units when several units are enabled. |
price_unit | From the order’s pricelist, else the product’s sales price; editable (see below). |
discount, tax_ids | Discount in percent; the taxes (see below). |
price_subtotal, price_tax, price_total | Computed amounts in the order currency; never written by a client. |
qty_delivered_method, qty_delivered | manual in sale: the delivered quantity is entered by hand. |
invoice_policy | The product’s invoice_policy, else the company’s sale_invoice_policy. |
qty_invoiced, qty_to_invoice | Signed quantity from linked draft and posted customer invoices and credit notes; to invoice is the ordered or delivered quantity less the invoiced one, on a confirmed order only. |
invoice_status | no, to invoice, upselling or invoiced. |
On the order: order_line, invoicing_closed (action_close_invoicing on confirmed orders,
action_reopen_order), invoice_status and delivery_status (over goods lines: pending,
partial, full).
The derived line fields (state, company_id, order_partner_id, salesman_id,
is_downpayment, qty_delivered_method, qty_invoiced, qty_to_invoice, invoice_status) are
refused on create and write for every caller, also with sudo, through the order’s order_line
commands and as default_<field> context keys. A line is not added to a cancelled or locked order,
not changed on a cancelled one, and not deleted from either. A line never moves to another order: a
write of order_id naming another order, directly or through another order’s order_line link or
set commands, is refused with a user error for every caller. A product line created without
description or unit takes the product’s display name and unit before the INSERT, and a product
created without invoice_policy gets the current company’s policy as its default.
Write guards, in order: the kind of a line does not change (a subsection may become a section); the
product does not change on a down payment, a cancelled order, or a confirmed order that is locked or
has delivered or invoiced quantities; a new quantity on a confirmed order calls
_update_line_quantity; a locked order refuses the fields of _get_protected_fields (product,
description, unit price, unit, quantity, discount, taxes, order), except a description change on down payments only.
A product line of a confirmed order is not deleted (_check_line_unlink).
Seams of the line (override, call sup once):
| Method | Result |
|---|---|
_get_consu_qty_delivered_method | BTreeMap<RecId, String>: the method of each goods line |
_prepare_qty_delivered | BTreeMap<RecId, Decimal>: the delivered quantity of the non-manual lines |
_prepare_qty_invoiced | BTreeMap<RecId, Decimal>: the invoiced quantity of each line |
_can_be_invoiced_alone | Records: the lines that may be invoiced without the others |
_get_protected_fields | ProtectedFields<SaleOrderLine> |
_update_line_quantity | (), with the new quantity |
_check_line_unlink | Records: the lines that may not be deleted |
The public write action sale.order.action_create_draft_invoice() accepts one confirmed
order. It requires Sales write rights on the order and its linked lines and ordinary invoice
creation rights in Accounting. The admitted company is applied to a new clean context before
creating a draft. The web action normalizer accepts a single-record form dialog (target=new) bound to
account.view_invoice_form and the created invoice ID.
The setting sale.max_invoice_source_rows bounds each source-line and tax-association scan
(default 10,000, range 1–100,000). A tax hidden by a record rule refuses the invoice. Select
Technical → System Parameters to change the bound. Quantity rounding uses Product Unit
precision, and Accounting resolves the journal, revenue account, receivable and tax entries.
Delivered-policy billing uses the existing sale line’s rounded qty_to_invoice. For direct
shipments, the sale_stock completion hook refreshes qty_delivered in the line’s sales unit
from its private sale.stock.delivery.move.link and completed direct returns. It sets the
source to stock_move, refuses manual edits on linked lines and notifies dependent stored
fields in the same transaction. Existing linked transfers are refreshed when upgrading
sale_stock to 1.1. A manual service line retains its normal delivery entry.
A customer invoice product line can supply sale_line_id when created or edited in draft.
Sales stores its source in sale.invoice.item, unique per invoice item. The link contributes
the invoice quantity or the negative of a credit quantity in the source unit. A cancelled
document contributes zero. The private link table has no end-user ACL. Changing a source
checks access to the invoice item and the affected order lines. The journal-item table and
the accounting posting actions retain their Accounting ownership.
The order’s delivery_status and invoice_status are computes that sale_stock and the invoicing
addons override with #[compute(override)].
Prices, taxes and totals
Section titled “Prices, taxes and totals”On the order: pricelist_id (none: the products’ sales prices; not changed once confirmed),
currency_id (the pricelist’s, else the company’s), currency_rate (company currency to order
currency on the order day, latest rate strictly before it), fiscal_position_id (computed from the
customer and delivery address with account.fiscal.position._get_fiscal_position in the order’s
company, editable), and amount_untaxed, amount_tax, amount_total.
- Price. A new product line without
price_unit, or with aprice_unitequal to thetechnical_price_unitsent with it (the line form sends its untouched default price 0 with the hidden technical price 0), takes the pricelist price (ProductPricelist::get_product_priceat the order date), else the product’slst_priceconverted from the company currency, in the line’s unit and rounded to “Product Price”. A pricelist in another currency than the company’s prices only through a fixed-price rule (ProductPricelist::get_product_rule); any other price would need a conversion inside the pricelist, which is not built, and is refused by name (a typed price is accepted). The price the line was priced at is kept intechnical_price_unit; a typed price keeps the technical price sent with it, so it counts as set by hand. A later change of product, unit or quantity prices the line again unless the same write gives a price, its price differs fromtechnical_price_unit(set by hand), it has an invoiced quantity, or it is a down payment. A pricelist change within one currency keeps hand-set prices and prices the other lines again; on a quotation with lines, a pricelist in another currency is refused by name (there is no update-prices operation yet). The rule’s minimum quantity is read in the product’s unit, the line’s quantity rounded at the Product Unit precision. - The form. A new quotation starts with the active company (
default_get) and a new line does not need a typed description: it takes the product’s (an empty or null description counts as not typed). A new line created withouttax_idstakes the product’s taxes; a given set, the empty one too, is kept (copies and API calls included). After confirmationdate_order,validity_dateandfiscal_position_idare refused on write, and on a locked orderuser_idandteam_id, as the form shows them read-only. - Taxes. Not given: the product’s
taxes_idof the order company or a parent; for a line without product and display type, the company’saccount_sale_tax_id; then mapped with the order’s fiscal position (map_tax). A new product takes its taxes again unless they are given. - Amounts.
erp_addon_account::tax::computeon price, quantity, discount and taxes, rounded per line in the order currency; the order sums its lines. A group of taxes and a reverse-charge tax are refused by name, as on invoices; the company’s “round globally” choice is not applied yet. - Derived fields.
amount_*,currency_idandcurrency_rateof the order, andprice_subtotal,price_tax,price_total,technical_price_unitandcurrency_idof a line, are refused oncreateandwrite, also asdefault_<field>context keys and insideorder_linecommands;technical_price_unitis accepted on a linecreateonly, where it tells an untouched price from a typed one (an untouched price is replaced by the computed one, a typed price keeps it, so the line counts as priced by hand).
Screens, menus and the Sales application
Section titled “Screens, menus and the Sales application”sale ships the views in views/sale_order_views.xml: the search view view_sales_order_filter,
the lists view_quotation_tree and view_order_tree, the form view_order_form, and the default
list and form of sale.order.line (sale_order_line_view_list, sale_order_line_view_form), which
the form’s order_line field shows; a line opens in its form as a dialog. The actions
sale.action_quotations and sale.action_orders have no domain and no context. The menus of
views/sale_menus.xml: sale_menu_root (Sales, salespeople) with sale_order_menu (Quotations,
Orders, Customers) and menu_sale_config (Sales administrators: Sales Teams).
The root menu ships inactive. The data-only addon sale_management (depends on sale, no crate)
is the Sales application: its data file sets sale.sale_menu_root active. Uninstalling it leaves
the menu active while sale stays installed: a data-only addon cannot undo its data, and an
uninstall hook would have to be linked into every binary that reads the addon folder. Extend a Sales screen with an inheriting
view of these ids; add a menu under sale.sale_order_menu or sale.menu_sale_config. What each
screen does and does not do yet: docs/design/sale-orders-views-matrix.md.
Configuration
Section titled “Configuration”| Value | Home | Default |
|---|---|---|
| Order number prefix, padding, next number, step | fields of the sale.order sequence record; a record per company may be added | S, 5, 1, 1 |
| Default invoicing policy | field sale_invoice_policy of the company; per product invoice_policy | ordered quantities |
| Lock confirmed sales | declared setting sale.lock_confirmed_sales, global, read by internal users, written by the system administrator | off |
Access
Section titled “Access”The rows of security/ir.access.csv (reference odoo/addons/sale/security/ir.access.csv:32-41):
| Group | sale.order | sale.order.line |
|---|---|---|
sales_team.group_sale_salesman | cru on own and unassigned orders | crud on lines of own and unassigned orders |
sales_team.group_sale_salesman_all_leads | cru on every order | crud on every line |
sales_team.group_sale_manager | crud | crud |
“Own and unassigned” is the domain ['|', ('user_id', '=', user.id), ('user_id', '=', False)] on
the order and the same over the stored salesman_id on the line. The company rule of each model is generated from its company_access declaration: an order by its
company_id (exact, no empty company), a line by its own stored company_id (the order’s) and through its order. The Sales administrator also
creates and changes partners, and manages pricelists, pricelist rules and activity types.
The five feature groups (sale.group_auto_done_setting, group_discount_per_so_line,
group_warning_sale, group_proforma_sales, group_services_and_material) are light feature
groups (res.groups._get_light_group_xmlids, extended in src/res_groups.rs): no implied group, no
access row, held by nobody until a setting switches them on. The lock is the declared setting
sale.lock_confirmed_sales; the other four switches come with the Sales settings page. A satellite
addon that adds a Sales role declares its own order and line rows.
Direct stock delivery
Section titled “Direct stock delivery”The native sale_stock addon is eligible for auto-install when the install operation sees Sales
and Stock Account. Ordinary upgrades of existing Sales and Stock Account installations keep an
absent bridge uninstalled. For those databases, upgrade the installed addons and then install
sale_stock with the accepted active candidate. It consumes
sale.order._action_confirm and keeps the resulting transfer and move origin links in
sale.stock.delivery.link and sale.stock.delivery.move.link. A client can save
sale.order.warehouse_id before calling the ordinary confirmation method. With an empty field
the bridge uses the company’s sole active warehouse with an attached delivery route, if any.
An explicit warehouse choice always requires a supported route for goods. Stock Manager can
manage warehouse delivery topology through the existing Inventory access policy.
The branch accepts an active one-step warehouse with a single outgoing make-to-stock rule.
Record and field access to the complete source membership is checked as the caller. This includes
the full conversion ancestry and fields of both the sale and inventory units, before Stock
elevation. Stock creates and confirms only the admitted transfer and moves. The bridge uses the native
Env::without_default_overrides scope for these writes and their nested reservations. Stock’s
declared defaults continue to apply. Ordinary Stock actions keep their configured defaults. The
base Sales confirmation
savepoint encompasses Stock writes, links, and later Sales hooks. Sales users retain their
ordinary Stock access. The system parameter sale_stock.max_confirmation_source_rows bounds
the number of orders and their source lines per confirmation call, including service and
display lines in admitted orders. Its default is 10,000 and its permitted range is 1–100,000.
The link rows record runtime origins. The reference has no shipped default sales orders or
moves to link. For deployment, upgrade Inventory and verify the configured warehouses before
enabling orders through the bridge. Inventory 1.13 supplies a missing route on existing active
one-step warehouses whose outgoing operation and locations match standard topology. It
preserves any attached route. Sales cancellation requires its linked transfer to be cancelled in
Inventory. Previously confirmed orders are outside the confirmation hook. SPEC-SALEDEL
defines the acceptance cases.
Not built yet
Section titled “Not built yet”Chatter tracking of the salesperson and team (tracking of recomputed fields is not built). The
partner’s own pricelist and fiscal position defaults beyond _get_fiscal_position, the discount
computed from a pricelist rule, currency conversion inside a pricelist; automatic cancellation of linked draft invoices when the order is cancelled; the signature fields; default search filters of the two actions.
The original direct delivery exposes its source through the computed field stock.picking.sale_order_id. Both directions resolve the immutable transfer association and apply the caller’s read access to each endpoint.