Last active
April 25, 2020 17:25
-
-
Save dawoodjee/6952205776dc678f61b0a1fb7773c5fb to your computer and use it in GitHub Desktop.
Using Frappe Client API (Python) to insert new Sales Invoices can be tricky. So here's how I did it:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def http_connection(): | |
connection = [] | |
try: | |
connection = FrappeClient("https://erp-site.com", "username or email", "password") | |
except SocketTimeout as st: | |
print("Connection to %s timed out. (timeout=%s)" % (st.host, st.timeout)) | |
connection = False | |
except SocketError as e: | |
# print("Failed to establish a new connection: %s" % e) | |
print("Failed to establish a network connection") | |
connection = False | |
return connection | |
def insert_invoice(): | |
https = http_connection() | |
if https: | |
resonse = https.insert({ | |
"doctype": "Sales Invoice", | |
"naming_series": "ACC-SINV-.YYYY.-", | |
"company": "Company Mould Public", | |
"set_posting_time": "1", | |
"posting_date": "1900-12-01", | |
"is_pos": "1", | |
"conversion_rate": 1.0, | |
"currency": "ZMW", | |
"debit_to": "Debtors - CMP", | |
"customer": "Customer Name", | |
"customer_name": "Customer Name", | |
"grand_total": 100.000, | |
"base_grand_total": 100.000, | |
"net_total": 84.000, | |
"base_net_total": 84.000, | |
"base_rounded_total": 100.000, | |
"rounded_total": 100.000, | |
"plc_conversion_rate": 1.0, | |
"price_list_currency": "ZMW", | |
"price_list_name": "Standard Selling", | |
"docstatus":1, | |
"items": [{ | |
"item_code": "Milk", | |
"item_name": "Milk", | |
"description": "Milk", | |
"uom": "ml", | |
"conversion_factor":1, | |
"rate": 50.000, | |
"base_rate": 50.000, | |
"amount": 100.000, | |
"base_amount": 100.000, | |
"income_account": "Cash - CMP", | |
"stock_qty":2, | |
"qty": 2 | |
}], | |
"payments":[{ | |
"mode_of_payment":"Cash", | |
"amount":100.000, | |
"base_amount":100.000, | |
"account":"Cash - CMP" | |
}], | |
"taxes": [{ | |
"account_head": "VAT - CMP", | |
"charge_type": "On Net Total", | |
"description": "VAT @ 16.0", | |
"tax_amount": 16.00 | |
}] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TIP: To use Python 3 you have to merge all the Pull Requests on the Frappe Client repo or use a Fork that already does like https://github.com/MohammadAhmad1990/frappe-client