askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
exchange_resolve.py · 2.5 KB · 49 lines
| 1 | """action_exchange_resolve -- a person decides on a document a partner sent. |
| 2 | |
| 3 | POST {inbox_id, decision: accept | reject | refuse, note?} |
| 4 | |
| 5 | refuse (any document, with a note saying why): the sender is told with a |
| 6 | signed document_refusal naming the document, which its box records against |
| 7 | what it sent ("Refused by <us>: <why>" on its invoice or order, attention |
| 8 | there); here the decision is recorded and a bill made from a refused invoice |
| 9 | is disputed. Nothing is recorded unless the sender was told. |
| 10 | |
| 11 | accept and reject are for an order confirmation that differs: |
| 12 | |
| 13 | A seller's order confirmation is compared with our purchase order line by |
| 14 | line (quantity, unit, unit price; lines rejected, missing or added) and, |
| 15 | when anything differs, waits in the inbox as needs_attention with every |
| 16 | difference listed. Nothing changes our order until a person decides here: |
| 17 | |
| 18 | - accept: our purchase order becomes what the seller confirmed, through |
| 19 | recorded changes. Each line write carries this person's name in the change |
| 20 | log (actor exchange-accept:<user>); rejected lines go to quantity 0 and |
| 21 | stay visible; added lines are added; the order's totals are stamped from |
| 22 | its lines. The differences are recomputed from the stored, signed document |
| 23 | against the order as it stands now, so what is applied is what was shown. |
| 24 | - reject: our order stays as it is. |
| 25 | |
| 26 | Either way the inbox row records the decision, who made it and when, and |
| 27 | leaves the attention queue. Staff only (an admin, the owner role or |
| 28 | role:manager) who may update the order -- the object checks both, because |
| 29 | every write it makes is a trusted storage-level write. |
| 30 | """ |
| 31 | |
| 32 | import object_exchange |
| 33 | import object_exchange_box as box |
| 34 | |
| 35 | |
| 36 | def POST(request): |
| 37 | try: |
| 38 | if str(request.get("decision") or "") == "refuse": |
| 39 | return box.refuse_document(box.base_dir(), request.get("inbox_id") or "", |
| 40 | request.get("_identity"), |
| 41 | reason=str(request.get("note") or "")) |
| 42 | return box.resolve_confirmation(box.base_dir(), request.get("inbox_id") or "", |
| 43 | request.get("_identity"), |
| 44 | decision=str(request.get("decision") or ""), |
| 45 | note=str(request.get("note") or "")) |
| 46 | except box.Refusal as refusal: |
| 47 | return refusal.answer() |
| 48 | except object_exchange.ExchangeUnavailable as exc: |
| 49 | return {"status": 409, "code": "exchange_unavailable", "error": str(exc)} |