fix(write-skill): la garde de chronologie ne vise que les factures émises #95

Merged
arcodange merged 1 commits from arcodange/chronology-fac-only into main 2026-08-17 15:15:29 +02:00
@@ -194,6 +194,22 @@ fi
# an earlier date, which is a numbering break. This bites whenever two documents # an earlier date, which is a numbering break. This bites whenever two documents
# of the same cycle are issued on different days (a deferred part issued after # of the same cycle are issued on different days (a deferred part issued after
# the next fixed part, for instance). Refuse rather than create the break. # the next fixed part, for instance). Refuse rather than create the break.
#
# CUSTOMER INVOICES ONLY. L'article 289 impose une numérotation chronologique et
# continue aux factures que la société ÉMET. Il ne dit rien de la référence de
# classement que Dolibarr attribue aux factures qu'elle REÇOIT : le numéro qui
# fait foi pour celles-là est celui du fournisseur, porté par ref_supplier, et la
# séquence FAF suit l'ordre d'ENREGISTREMENT — c'est sa construction normale.
#
# Appliquer la garde aux deux registres produisait un faux positif systématique :
# la production porte déjà cinq ruptures dans la séquence FAF (FAF2026003 daté du
# 4 janvier suit FAF2026002 daté du 9), et zéro dans la séquence FAC. Toute
# facture fournisseur enregistrée après coup — le cas ordinaire, cf. adc-008 qui
# prescrit d'enregistrer à la date du document — se heurtait au refus et exigeait
# ARCO_ALLOW_BACKDATE. Une garde qu'on outrepasse par routine ne garde plus rien.
if [[ "${ENDPOINT}" != "/invoices" ]]; then
CHRONO_SKIP=1
fi
NEW_DATE="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['date'])" "${BODY}")" NEW_DATE="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['date'])" "${BODY}")"
LAST="$("${W}" GET "${ENDPOINT}?sortfield=t.rowid&sortorder=DESC&limit=1" 2>/dev/null \ LAST="$("${W}" GET "${ENDPOINT}?sortfield=t.rowid&sortorder=DESC&limit=1" 2>/dev/null \
| python3 -c " | python3 -c "
@@ -204,7 +220,7 @@ try:
else: print('0|-') else: print('0|-')
except Exception: print('0|-')" 2>/dev/null || echo "0|-")" except Exception: print('0|-')" 2>/dev/null || echo "0|-")"
LAST_DATE="${LAST%%|*}"; LAST_REF="${LAST##*|}" LAST_DATE="${LAST%%|*}"; LAST_REF="${LAST##*|}"
if [[ "${LAST_DATE}" =~ ^[0-9]+$ ]] && (( LAST_DATE > 0 )) && (( NEW_DATE < LAST_DATE )); then if [[ -z "${CHRONO_SKIP:-}" ]] && [[ "${LAST_DATE}" =~ ^[0-9]+$ ]] && (( LAST_DATE > 0 )) && (( NEW_DATE < LAST_DATE )); then
if [[ "${ARCO_ALLOW_BACKDATE:-}" != "I-UNDERSTAND-THIS-BREAKS-CHRONOLOGY" ]]; then if [[ "${ARCO_ALLOW_BACKDATE:-}" != "I-UNDERSTAND-THIS-BREAKS-CHRONOLOGY" ]]; then
printf 'invoice-create.sh: REFUSED — chronology break.\n' >&2 printf 'invoice-create.sh: REFUSED — chronology break.\n' >&2
printf ' new document dated %s, but %s is already issued at %s.\n' \ printf ' new document dated %s, but %s is already issued at %s.\n' \