The human-gated path that carries a reviewed sandbox change to prod.
- promote-plan.sh: render a manifest (JSON array of write ops with symbolic @refs
instead of ids — portable sandbox->prod) as a human-readable change-set.
- promote-apply.sh <manifest> --target sandbox|prod: replay it, resolving each
@ref to the id actually created during the run (dependent ops wire up). sandbox
rehearses via dol-write.sh; prod via dol-prod-write.sh.
- dol-prod-write.sh: the ONLY prod-write path. Prod key read from the ENVIRONMENT
only (DOLIBARR_PROD_WRITE_KEY, never a stored .env); every write refused unless
ARCO_PROMOTE_CONFIRM=I-UNDERSTAND-THIS-WRITES-PROD.
- create scripts take a DOL_WRITE override so promote-apply reuses them per target.
- bin/arcodange: `promote {plan|apply}` group + example manifest.
- payment-record.sh: fixed supplier payments (payment_mode_id + closepaidinvoices).
Proven live: plan renders; apply --target sandbox replays a 3-op chain with refs
resolved (@tp1->id, invoice socid=@tp1, payment invoice=@inv1); --target prod
without the confirm flag is REFUSED before sending. Supplier payment now works
end-to-end via the script.
Limitation (documented): manifests reference entities they create (@ref);
pre-existing prod entities need business-key resolution (follow-up).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
61 lines
2.5 KiB
Bash
Executable File
61 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Record a payment (règlement) on a validated invoice in the SANDBOX.
|
|
#
|
|
# Input: a JSON object on stdin (or a file path in $1):
|
|
# invoice_id (required) the invoice to pay
|
|
# kind "customer" | "supplier" (default "customer")
|
|
# mode "VIR" | "CB" | "CHQ" | "LIQ" (default "VIR")
|
|
# account_id (required) the bank account id receiving/paying
|
|
# date "YYYY-MM-DD" (default today)
|
|
# amount (REQUIRED for supplier; customer pays the full remaining)
|
|
# num, comment (optional)
|
|
#
|
|
# The invoice must be VALIDATED first (invoice-create.sh ... "validate":true).
|
|
# Emits the new payment id on stdout.
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
W="${DOL_WRITE:-${SCRIPT_DIR}/dol-write.sh}"
|
|
|
|
SRC="${1:-}"
|
|
if [[ -n "${SRC}" && "${SRC}" != "-" ]]; then INPUT="$(cat "${SRC}")"; else INPUT="$(cat)"; fi
|
|
|
|
PYF="$(mktemp -t dolpy.XXXXXX)"; trap 'rm -f "${PYF}"' EXIT
|
|
cat > "${PYF}" <<'PY'
|
|
import json, sys, datetime
|
|
d = json.loads(sys.stdin.read())
|
|
if not d.get("invoice_id"):
|
|
sys.exit("payment-record.sh: 'invoice_id' is required")
|
|
if not d.get("account_id"):
|
|
sys.exit("payment-record.sh: 'account_id' is required")
|
|
# Stable Dolibarr c_paiement ids (sandbox seeded from prod / standard defaults).
|
|
MODE = {"VIR": 2, "CB": 6, "CHQ": 7, "LIQ": 4}
|
|
mode = MODE.get(str(d.get("mode", "VIR")).upper())
|
|
if mode is None:
|
|
sys.exit("payment-record.sh: unknown mode (use VIR|CB|CHQ|LIQ)")
|
|
supplier = 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())
|
|
inv = d["invoice_id"]
|
|
if supplier:
|
|
if d.get("amount") is None:
|
|
sys.exit("payment-record.sh: supplier payments require an 'amount'")
|
|
endpoint = "/supplierinvoices/%s/payments" % inv
|
|
body = {"datepaye": epoch, "payment_mode_id": mode, "closepaidinvoices": "yes",
|
|
"accountid": d["account_id"],
|
|
"amount": str(d["amount"]), "num_payment": d.get("num", ""),
|
|
"comment": d.get("comment", "")}
|
|
else:
|
|
endpoint = "/invoices/%s/payments" % inv
|
|
body = {"datepaye": epoch, "paymentid": mode, "closepaidinvoices": "yes",
|
|
"accountid": d["account_id"], "num_payment": d.get("num", ""),
|
|
"comment": d.get("comment", "")}
|
|
print(endpoint)
|
|
print(json.dumps(body))
|
|
PY
|
|
|
|
MAPPED="$(printf '%s' "${INPUT}" | python3 "${PYF}")"
|
|
ENDPOINT="$(sed -n 1p <<<"${MAPPED}")"
|
|
BODY="$(sed -n 2p <<<"${MAPPED}")"
|
|
"${W}" POST "${ENDPOINT}" "${BODY}"
|