ERP: Record a sale (write-off, invoice, payment)
erp_record_saleRecord a SALE that already happened — in the shop, by hand, from stock — in ONE confirmation card: the sales order, the stock written off for each item, an invoice linked to it and the payment. Use it for «відміть / зафіксуй продаж», «продав …», «отметь продажу», «я продал …», a list of items with prices and a buyer. NOT invoice_create (that only bills, it does not write stock off) and NOT erp_stock_batch (that only moves stock). One call with EVERY line. 'client' = the buyer's name as said (found among leads / clients; nobody of that name → a NEW client, the card says so); several matches are refused with candidates — ask, then pass lead_id / organization_id. Each line: 'item' as the person wrote it (name words, number or barcode; «B12(G&G)» is fine), 'quantity' (default 1), 'price' = what ONE unit was sold for, after the discount («1060-%=980» → price 980, list_price 1060); without 'price' the catalog price is used. 'total' = the total the person stated, if any (checked against the lines). 'payment': paid (paid in full — «оплатила», «оплачено»), partial (+ paid_amount) or unpaid (will pay later); 'method' cash / card / transfer if said; 'date' YYYY-MM-DD only if not today. Items not in the catalog, several matches or not enough stock refuse the proposal with the reason — tell the person, never write stock off blindly. A sale already recorded with the same buyer, items and prices is refused (no duplicates): when the person later says the buyer paid, mark THAT sale's invoice paid (invoice_mark_paid). Proposed write — one card, one «Так». CONFIRMATION: this tool is PROPOSED, never performed directly. You get status='confirmation_required' with an action_id and a plan_token, and the write happens only after confirm_action.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"lines": "<lines>",
"payment": "<payment>"
},
"name": "erp_record_sale"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| note | No | ||
| lines | Yes | ||
| total | No | The total the person stated. | |
| client | No | The buyer's name as the person said it. | |
| method | No | ||
| lead_id | No | ||
| payment | Yes | ||
| currency | No | ||
| again_ref | No | Only for a SECOND identical sale the person confirmed: any new word. | |
| warehouse | No | ||
| new_client | No | The person said it is a NEW client with this exact name. | |
| paid_amount | No | ||
| organization_id | No |