frappex-client v0.1.1

Guides

Submit, cancel and rename#

Document status#

Submittable DocTypes, such as Sales Invoice, Journal Entry or Stock Entry, have a docstatus:

docstatus State Can be edited?
0 Draft Yes
1 Submitted Only fields marked "Allow on Submit"
2 Cancelled No
insert ──► Draft (0) ──submit──► Submitted (1) ──cancel──► Cancelled (2)
                ▲                                              │
                └──────────── amend: insert a new draft ◄──────┘

Submit#

invoice = client.insert(
    "Sales Invoice",
    {
        "customer": "Acme Corporation",
        "items": [{"item_code": "WIDGET-01", "qty": 2, "rate": 250}],
    },
)
client.submit("Sales Invoice", invoice["name"])

print(client.get_doc("Sales Invoice", invoice["name"])["docstatus"])  # 1

Submitting runs the DocType's validations and side effects: posting ledger entries, updating stock and so on. A failed check raises ValidationError with the site's message in error.server_messages.

submit and cancel return None. Call get_doc afterwards if you need the new state.

Cancel#

client.cancel("Sales Invoice", invoice["name"])

Cancelling reverses the side effects of submission. A document that other submitted documents link to (a payment against an invoice, for example) must have those cancelled first; the error names them.

Amend#

A cancelled document cannot be edited. To correct it, Frappe creates a new draft whose amended_from field points at the cancelled one, and names it with a suffix such as -1. The simplest way is the Amend button in the desk. From code, insert a new document with the corrected values and set amended_from to the cancelled document's name.

Rename#

new_name = client.rename("Customer", "Acme Corp", "Acme Corporation")

Renaming updates every link that points at the document. The DocType must allow renaming (Allow Rename in its settings).

Pass merge=True to merge into an existing document of the new name; the old document's links move to it and the old document is removed:

client.rename("Customer", "ACME Ltd", "Acme Corporation", merge=True)

Warning

Renaming and merging touch every linked record and can take a while on a large site. Merges cannot be undone.

Found a mistake? Open an issue.