feat(write-skill): GED attach op — upload the source document onto its invoice (erp#43)
document-attach.sh uploads a source piece (the supplier's own PDF) onto an invoice's GED via POST /documents/upload — idempotent by (object, filename, sha256): before any POST the object's GED is listed and a same-named entry is downloaded back and sha256-compared. Identical → deduped no-op; different content → ABORT (refuse-never-repair, overwriteifexists always 0, never Dolibarr's overwrite flag). Read-back after upload: re-list + download + sha256-verify. Module-relative download paths are derived from the listing's fullname (supplier invoices carry an id-derived get_exdir prefix like 9/2/FAF2026013/…, so reconstruction would be wrong). Promote integration: new `attach` op in promote-plan/promote-apply (OP_SCRIPT), object_id resolvable via @ref and #supplierinvoice lookups; a relative `file` resolves against the manifest's directory (replay packs carry pdfs/ beside the manifest, gitignored — README documents the books@ re-fetch message ids). promote-plan prints each file's sha256 (or a loud MISSING) at review time. CLI: `arcodange sandbox attach`. Proof: offline case 12 in tests/run-tests.sh (upload body, dedupe, conflict abort, field refusal, manifest-relative resolution via stubbed /documents); live: manifest-C-ged-attach.json applied twice on the sandbox — run 1 four created, run 2 four deduped, one GED file per FAF2026010-013, stored sha256s equal to the re-fetched sources; tests/replay-idempotency.sh extended with an attach op (4 created → 4 deduped, ged_files count unchanged) and a live same-name/different-bytes abort verified. Closes erp#43 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VRShc4QhLLU73FLHx9vskh
This commit is contained in:
@@ -38,7 +38,8 @@ manifest_path, script_dir = sys.argv[1], sys.argv[2]
|
||||
ops = json.load(open(manifest_path))
|
||||
OP_SCRIPT = {"thirdparty": "thirdparty-create.sh", "invoice": "invoice-create.sh",
|
||||
"creditnote": "creditnote-create.sh", "payment": "payment-record.sh",
|
||||
"thirdparty_update": "thirdparty-update.sh", "contact": "contact-create.sh"}
|
||||
"thirdparty_update": "thirdparty-update.sh", "contact": "contact-create.sh",
|
||||
"attach": "document-attach.sh"}
|
||||
refmap = {}
|
||||
n_created = n_deduped = 0
|
||||
|
||||
@@ -100,6 +101,11 @@ for i, op in enumerate(ops, 1):
|
||||
if not script:
|
||||
sys.exit("promote-apply: unknown op '%s'" % t)
|
||||
inp = resolve(op.get("input", {}))
|
||||
# attach: a relative "file" is relative to the MANIFEST, not the CWD — the
|
||||
# manifest is the portable unit (replay packs carry their pdfs/ beside it).
|
||||
if t == "attach" and isinstance(inp.get("file"), str) and not os.path.isabs(inp["file"]):
|
||||
inp["file"] = os.path.normpath(os.path.join(
|
||||
os.path.dirname(os.path.abspath(manifest_path)), inp["file"]))
|
||||
r = subprocess.run([os.path.join(script_dir, script)], input=json.dumps(inp),
|
||||
capture_output=True, text=True, env=os.environ)
|
||||
if r.returncode != 0:
|
||||
|
||||
Reference in New Issue
Block a user