From 64d2cb42379b06d7d4b54287c13223c94edd73c4 Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Tue, 30 Jun 2026 00:07:48 +0200 Subject: [PATCH] feat(skills,cli): supplier avoirs + banque lire (bank-account discovery) The two V9 follow-ups, both proven live on the sandbox. - creditnote-create.sh: `kind:"supplier"` makes an avoir fournisseur on /supplierinvoices (type=2 + fk_facture_source, carries ref_supplier); default customer path unchanged. Proven: customer AVC002 (-240) + supplier AVF2026001 (-144, ref_supplier carried, linked to source, validated). - bank-accounts.sh + `arcodange sandbox accounts`: list bank accounts (id/label/ bank) so a payment can pick its account_id. Needs `banque lire` (rights 111), now added to the provisioner's WRITE_IDS so fresh runs include it; the existing ai_agent_sandbox user was granted it live. GET /bankaccounts now returns the 3 accounts (QONTO, WISE EURO, Compte Courant Asso). - SKILL.md: supplier-avoir example + accounts helper + updated banque-lire note. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../skills/dolibarr-sandbox-write/SKILL.md | 24 ++++++++++++------ .../scripts/bank-accounts.sh | 14 +++++++++++ .../scripts/creditnote-create.sh | 25 +++++++++++++------ bin/arcodange | 4 ++- test/provisionSandbox.ts | 2 ++ 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100755 .claude/skills/dolibarr-sandbox-write/scripts/bank-accounts.sh diff --git a/.claude/skills/dolibarr-sandbox-write/SKILL.md b/.claude/skills/dolibarr-sandbox-write/SKILL.md index ec8b6be..83e83ea 100644 --- a/.claude/skills/dolibarr-sandbox-write/SKILL.md +++ b/.claude/skills/dolibarr-sandbox-write/SKILL.md @@ -102,20 +102,27 @@ echo '{"invoice_id":13,"kind":"supplier","mode":"VIR","account_id":1,"amount":96 ``` The invoice must be **validated** first. `mode`: `VIR|CB|CHQ|LIQ`. Customer payments settle the full remaining amount and mark the invoice paid; **supplier** -payments require an explicit `amount`. `account_id` is the bank account id (the -read-only `dolibarr-payments-state` skill lists them; `ai_agent_sandbox` does not -yet have `banque lire`, so pass the id). Emits the new payment id. +payments require an explicit `amount`. `account_id` is the bank account id — list +them with `scripts/bank-accounts.sh` (`ai_agent_sandbox` now holds `banque lire`). +Emits the new payment id. ### 4 · Credit note (avoir) — `scripts/creditnote-create.sh` ```sh +# customer avoir echo '{"socid":42,"source_invoice":19,"validate":true, "lines":[{"desc":"Avoir partiel conseil","qty":1,"price_ht":100,"tva":20,"type":"service"}]}' \ | scripts/creditnote-create.sh +# supplier avoir (avoir fournisseur) +echo '{"socid":12,"kind":"supplier","source_invoice":17,"ref_supplier":"AV-2026-77","validate":true, + "lines":[{"desc":"Avoir hosting","qty":1,"price_ht":120,"tva":20,"type":"service"}]}' \ + | scripts/creditnote-create.sh ``` -A customer invoice of `type=2` referencing `source_invoice` (`fk_facture_source`); -amounts come out negative (a credit). `validate:true` turns the draft into a -numbered `AVC…` avoir. Emits `{id, ref, total_ht, total_ttc, fk_facture_source, statut}`. +An invoice of `type=2` referencing `source_invoice` (`fk_facture_source`); amounts +come out negative. `kind:"supplier"` targets `/supplierinvoices` (carry +`ref_supplier`); default `customer` targets `/invoices`. `validate:true` numbers it +(`AVC…` for customer, `AVF…` for supplier). Emits `{id, ref, ref_supplier, total_ht, +total_ttc, fk_facture_source, statut}`. ## Promote to prod (rehearse → review → replay) @@ -163,8 +170,9 @@ sandbox KissMetrics on `--target sandbox` and the prod one on `--target prod`. REST create needs `code_client`/`code_fournisseur = "-1"` to trigger it — the script does this; without it the API errors `ErrorCustomerCodeRequired`. - **Dates** are sent as Unix epochs; pass `date:"YYYY-MM-DD"` or omit for today. -- **`banque lire`** isn't granted yet → `GET /bankaccounts` returns empty. Add it - to the provisioner's rights set if account discovery from this skill is needed. +- **`banque lire`** (rights id 111) is granted → `scripts/bank-accounts.sh` lists + accounts (id/label/bank) so a payment can pick its `account_id`. It's in the + provisioner's `WRITE_IDS`, so a fresh `provisionSandbox.ts` run includes it. - **Avoirs (credit notes)** → `creditnote-create.sh` (customer invoice `type=2` referencing `source_invoice`; amounts negative, ref `AVC…`). Supplier avoirs are a follow-up. diff --git a/.claude/skills/dolibarr-sandbox-write/scripts/bank-accounts.sh b/.claude/skills/dolibarr-sandbox-write/scripts/bank-accounts.sh new file mode 100755 index 0000000..217355a --- /dev/null +++ b/.claude/skills/dolibarr-sandbox-write/scripts/bank-accounts.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# List the sandbox bank accounts (id + label) so a payment can pick its account_id. +# Read-only; needs the ai_agent_sandbox user to hold `banque lire` (rights id 111). +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +W="${DOL_WRITE:-${SCRIPT_DIR}/dol-write.sh}" +"${W}" GET "/bankaccounts" | python3 -c "import json,sys +d = json.load(sys.stdin); rows = d if isinstance(d, list) else [] +if not rows: + print('(no bank accounts defined)'); sys.exit(0) +print('%-4s %-34s %-10s %s' % ('id', 'label', 'bank', 'currency')) +for a in rows: + print('%-4s %-34s %-10s %s' % (a.get('id'), (a.get('label') or '')[:34], + a.get('bank') or '', a.get('currency_code') or ''))" diff --git a/.claude/skills/dolibarr-sandbox-write/scripts/creditnote-create.sh b/.claude/skills/dolibarr-sandbox-write/scripts/creditnote-create.sh index 98ce9c9..f8e8ed5 100755 --- a/.claude/skills/dolibarr-sandbox-write/scripts/creditnote-create.sh +++ b/.claude/skills/dolibarr-sandbox-write/scripts/creditnote-create.sh @@ -1,16 +1,20 @@ #!/usr/bin/env bash -# Create a customer credit note (avoir) in the SANDBOX — a customer invoice of -# type 2 that references the original invoice. Amounts come out negative. +# Create a credit note (avoir) in the SANDBOX — an invoice of type 2 that +# references the original invoice. Amounts come out negative. Customer avoir = +# /invoices; supplier avoir (avoir fournisseur) = /supplierinvoices. # # Input: a JSON object on stdin (or a file path in $1): -# socid (required) the client (must match the source invoice's client) +# socid (required) the third party (must match the source invoice's) # source_invoice (required) the original invoice id being credited +# kind "customer" (default) | "supplier" +# ref_supplier (supplier only) the supplier's avoir reference (recommended — +# some supplier setups require it to validate) # date "YYYY-MM-DD" (default today) # validate true|false (default false = leave draft) # lines: [ { desc, qty, price_ht, tva, type: "product"|"service", product_id? } ] # the lines being credited (positive amounts; Dolibarr nets them as a credit) # -# Emits {id, ref, total_ht, total_ttc, fk_facture_source, statut} on stdout. +# Emits {id, ref, ref_supplier, total_ht, total_ttc, fk_facture_source, statut}. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" W="${DOL_WRITE:-${SCRIPT_DIR}/dol-write.sh}" @@ -25,6 +29,7 @@ d = json.loads(sys.stdin.read()) for req in ("socid", "source_invoice"): if not d.get(req): sys.exit("creditnote-create.sh: '%s' is required" % req) +is_supplier = str(d.get("kind", "customer")).lower() in ("supplier", "fournisseur") ds = d.get("date") epoch = int((datetime.datetime.strptime(ds, "%Y-%m-%d") if ds else datetime.datetime.now()).timestamp()) @@ -43,22 +48,26 @@ for ln in d.get("lines", []): lines.append(L) body = {"socid": d["socid"], "type": 2, "fk_facture_source": d["source_invoice"], "date": epoch, "lines": lines} +if is_supplier and d.get("ref_supplier"): + body["ref_supplier"] = d["ref_supplier"] print(json.dumps(body)) print("1" if d.get("validate") else "0") +print("/supplierinvoices" if is_supplier else "/invoices") PY MAPPED="$(printf '%s' "${INPUT}" | python3 "${PYF}")" BODY="$(sed -n 1p <<<"${MAPPED}")" VALIDATE="$(sed -n 2p <<<"${MAPPED}")" +ENDPOINT="$(sed -n 3p <<<"${MAPPED}")" -ID="$("${W}" POST /invoices "${BODY}")" +ID="$("${W}" POST "${ENDPOINT}" "${BODY}")" if [[ ! "${ID}" =~ ^[0-9]+$ ]]; then echo "creditnote-create.sh: create did not return an id: ${ID}" >&2 exit 1 fi if [[ "${VALIDATE}" == "1" ]]; then - "${W}" POST "/invoices/${ID}/validate" '{}' >/dev/null + "${W}" POST "${ENDPOINT}/${ID}/validate" '{}' >/dev/null fi -"${W}" GET "/invoices/${ID}" | python3 -c "import json,sys +"${W}" GET "${ENDPOINT}/${ID}" | python3 -c "import json,sys d=json.load(sys.stdin) -print(json.dumps({k:d.get(k) for k in ('id','ref','total_ht','total_ttc','fk_facture_source','statut')}))" +print(json.dumps({k:d.get(k) for k in ('id','ref','ref_supplier','total_ht','total_ttc','fk_facture_source','statut')}))" diff --git a/bin/arcodange b/bin/arcodange index 6ef7616..92683e7 100755 --- a/bin/arcodange +++ b/bin/arcodange @@ -86,7 +86,8 @@ COMMANDS thirdparty Create a client/supplier fiche invoice Customer/supplier invoice + product/service lines payment Record a règlement on a validated invoice - creditnote Create an avoir (credit note) of a source invoice + creditnote Create an avoir — customer or supplier (kind) + accounts List bank accounts (id/label) to pick account_id write [body] Raw host-guarded write promote Replay a reviewed change-set sandbox -> prod (ADR-0003) @@ -285,6 +286,7 @@ EOF invoice) exec "${SKILLS}/dolibarr-sandbox-write/scripts/invoice-create.sh" "$@" ;; payment) exec "${SKILLS}/dolibarr-sandbox-write/scripts/payment-record.sh" "$@" ;; creditnote) exec "${SKILLS}/dolibarr-sandbox-write/scripts/creditnote-create.sh" "$@" ;; + accounts) exec "${SKILLS}/dolibarr-sandbox-write/scripts/bank-accounts.sh" "$@" ;; write) exec "${SKILLS}/dolibarr-sandbox-write/scripts/dol-write.sh" "$@" ;; help|-h|--help) cat <<'EOF' diff --git a/test/provisionSandbox.ts b/test/provisionSandbox.ts index 8939cbc..bd3819a 100644 --- a/test/provisionSandbox.ts +++ b/test/provisionSandbox.ts @@ -38,6 +38,7 @@ import userSetup from "./scripts/admin/userSetup.ts"; societe contact: lire=281, creer=282 fournisseur: lire=1181, facture lire=1231, facture creer=1232 produit: lire=31, creer=32 + banque: lire=111 */ const WRITE_IDS = [ 11, // facture lire @@ -54,6 +55,7 @@ const WRITE_IDS = [ 1232, // fournisseur facture creer 31, // produit lire 32, // produit creer + 111, // banque lire — list bank accounts (GET /bankaccounts) to pick account_id ]; const KEY_FILE = ".ai_agent_sandbox.key";