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_send.py · 1.9 KB · 42 lines
| 1 | """action_exchange_send -- send a business record to a trading partner. |
| 2 | |
| 3 | POST {collection, record_id, partner?, response?, credits_invoice_id?} |
| 4 | |
| 5 | Makes the signed document for one record and queues it in exchange_outbox; |
| 6 | the daemon delivers it (system_exchange_deliver). What a record becomes: |
| 7 | |
| 8 | - an orders row of doc_type purchase -> purchase_order (name the partner); |
| 9 | - an orders row of doc_type sale -> order_confirmation (to the partner whose |
| 10 | purchase order it came from; `response` accepted | rejected | amended); |
| 11 | - an invoices row -> invoice, or credit_note for doc_type credit_note |
| 12 | (to the partner whose purchase order the invoice's source order came |
| 13 | from, or the one named; `credits_invoice_id` refers a credit note to the |
| 14 | invoice it credits); |
| 15 | - a supplier_bills row a person marked paid -> remittance (to the supplier |
| 16 | it came from); |
| 17 | - a receipts row (app-receiving) that is received -> receipt (to the |
| 18 | supplier of its purchase order). |
| 19 | |
| 20 | Sending commits the business, so the caller must be staff (an admin, the |
| 21 | owner role or role:manager; a plain registered user is a customer, who owns |
| 22 | the orders and invoices checkout raises for them) AND allowed to UPDATE the |
| 23 | record (object_access). One document per record and type: |
| 24 | a second send is refused naming the first. The partner must be connected |
| 25 | and the type switched on for sending to them. |
| 26 | """ |
| 27 | |
| 28 | import object_exchange |
| 29 | import object_exchange_box as box |
| 30 | |
| 31 | |
| 32 | def POST(request): |
| 33 | try: |
| 34 | return box.send(box.base_dir(), request.get("_identity"), |
| 35 | collection=request.get("collection") or "", |
| 36 | record_id=request.get("record_id") or "", |
| 37 | partner_domain=request.get("partner") or "", |
| 38 | requested=request) |
| 39 | except box.Refusal as refusal: |
| 40 | return refusal.answer() |
| 41 | except object_exchange.ExchangeUnavailable as exc: |
| 42 | return {"status": 409, "code": "exchange_unavailable", "error": str(exc)} |