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) <noreply@anthropic.com>
This commit is contained in:
@@ -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')}))"
|
||||
|
||||
Reference in New Issue
Block a user