GnuCash c935c2f+
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
gnucash_rest Namespace Reference

Data Structures

class  Error
 

Functions

 api_accounts ()
 
 api_account (guid)
 
 api_account_splits (guid)
 
 api_transactions ()
 
 api_transaction (guid)
 
 api_bills ()
 
 api_bill (id)
 
 api_bill_entries (id)
 
 api_invoices ()
 
 api_invoice (id)
 
 api_invoice_entries (id)
 
 api_entry (guid)
 
 api_customers ()
 
 api_customer (id)
 
 api_customer_invoices (id)
 
 api_vendors ()
 
 api_vendor (id)
 
 api_vendor_bills (id)
 
 getCustomers (book)
 
 getCustomer (book, id)
 
 getVendors (book)
 
 getVendor (book, id)
 
 getAccounts (book)
 
 getAccountsFlat (book)
 
 getSubAccounts (account)
 
 getAccount (book, guid)
 
 getTransaction (book, guid)
 
 getTransactions (book, account_guid, date_posted_from, date_posted_to)
 
 getAccountSplits (book, guid, date_posted_from, date_posted_to)
 
 getInvoices (book, customer, is_paid, is_active, date_due_from, date_due_to)
 
 getBills (book, customer, is_paid, is_active, date_opened_from, date_opened_to)
 
 getGnuCashInvoice (book, id)
 
 getGnuCashBill (book, id)
 
 getInvoice (book, id)
 
 payInvoice (book, id, posted_account_guid, transfer_account_guid, payment_date, memo, num, auto_pay)
 
 payBill (book, id, posted_account_guid, transfer_account_guid, payment_date, memo, num, auto_pay)
 
 getBill (book, id)
 
 addVendor (book, id, currency_mnumonic, name, contact, address_line_1, address_line_2, address_line_3, address_line_4, phone, fax, email)
 
 addCustomer (book, id, currency_mnumonic, name, contact, address_line_1, address_line_2, address_line_3, address_line_4, phone, fax, email)
 
 updateCustomer (book, id, name, contact, address_line_1, address_line_2, address_line_3, address_line_4, phone, fax, email)
 
 addInvoice (book, id, customer_id, currency_mnumonic, date_opened, notes)
 
 updateInvoice (book, id, customer_id, currency_mnumonic, date_opened, notes, posted, posted_account_guid, posted_date, due_date, posted_memo, posted_accumulatesplits, posted_autopay)
 
 updateBill (book, id, vendor_id, currency_mnumonic, date_opened, notes, posted, posted_account_guid, posted_date, due_date, posted_memo, posted_accumulatesplits, posted_autopay)
 
 addEntry (book, invoice_id, date, description, account_guid, quantity, price)
 
 addBillEntry (book, bill_id, date, description, account_guid, quantity, price)
 
 getEntry (book, entry_guid)
 
 updateEntry (book, entry_guid, date, description, account_guid, quantity, price)
 
 deleteEntry (book, entry_guid)
 
 deleteTransaction (book, transaction_guid)
 
 addBill (book, id, vendor_id, currency_mnumonic, date_opened, notes)
 
 addAccount (book, name, currency_mnumonic, account_type_id, parent_account_guid, description, code)
 
 addTransaction (book, num, description, date_posted, currency_mnumonic, splits)
 
 editTransaction (book, transaction_guid, num, description, date_posted, currency_mnumonic, splits)
 
 gnc_numeric_from_decimal (decimal_value)
 
 shutdown ()
 

Variables

 app = Flask(__name__)
 
 debug
 
str host = '127.0.0.1'
 
bool is_new = False
 
 session = gnucash.Session(arguments[0], SessionOpenMode.SESSION_NEW_STORE)
 
 stream_handler = StreamHandler()
 

Detailed Description

gnucash_rest.py -- A Flask app which responds to REST requests
with JSON responses

Copyright (C) 2013 Tom Lofts <dev@loftx.co.uk>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, contact:

Free Software Foundation Voice: +1-617-542-5942
51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
Boston, MA 02110-1301, USA gnu@gnu.org

@author Tom Lofts <dev@loftx.co.uk>

Function Documentation

◆ addAccount()

gnucash_rest.addAccount (   book,
  name,
  currency_mnumonic,
  account_type_id,
  parent_account_guid,
  description,
  code 
)

Definition at line 1675 of file gnucash_rest.py.

1676 parent_account_guid, description, code):
1677
1678 from gnucash.gnucash_core_c import ACCT_TYPE_ROOT, ACCT_TYPE_TRADING
1679
1680 if name == '':
1681 raise Error('NoAccountName',
1682 'A name must be entered for this account',
1683 {'field': 'name'})
1684
1685 try:
1686 account_type_id = int(account_type_id)
1687 except (TypeError, ValueError):
1688 raise Error('InvalidAccountTypeID',
1689 'A valid account type id must be supplied for this account',
1690 {'field': 'account_type_id'})
1691
1692 # account types above TRADING (CHECKING, SAVINGS, MONEYMRKT, CREDITLINE)
1693 # are aliases that the engine refuses to set - see Account.h
1694 if (account_type_id < 0 or account_type_id > ACCT_TYPE_TRADING
1695 or account_type_id == ACCT_TYPE_ROOT):
1696 raise Error('InvalidAccountTypeID',
1697 'A valid account type id must be supplied for this account',
1698 {'field': 'account_type_id'})
1699
1700 commod_table = book.get_table()
1701 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1702
1703 if currency is None:
1704 raise Error('InvalidAccountCurrency',
1705 'A valid currency must be supplied for this account',
1706 {'field': 'currency'})
1707
1708 if parent_account_guid == '':
1709 raise Error('NoParentAccount',
1710 'A parent account guid must be supplied for this account',
1711 {'field': 'parent_account_guid'})
1712
1713 guid = gnucash.gnucash_core.GUID()
1714 gnucash.gnucash_core.GUIDString(parent_account_guid, guid)
1715 parent_account = guid.AccountLookup(book)
1716
1717 if parent_account is None:
1718 raise Error('InvalidParentAccount',
1719 'A parent account with this guid does not exist',
1720 {'field': 'parent_account_guid'})
1721
1722 account = Account(book)
1723 parent_account.append_child(account)
1724 account.SetName(name)
1725 account.SetType(account_type_id)
1726 account.SetCommodity(currency)
1727
1728 if description != '':
1729 account.SetDescription(description)
1730
1731 if code != '':
1732 account.SetCode(code)
1733
1734 return gnucash_simple.accountToDict(account)
1735
accountToDict(account)
STRUCTS.

◆ addBill()

gnucash_rest.addBill (   book,
  id,
  vendor_id,
  currency_mnumonic,
  date_opened,
  notes 
)

Definition at line 1640 of file gnucash_rest.py.

1640def addBill(book, id, vendor_id, currency_mnumonic, date_opened, notes):
1641
1642 vendor = book.VendorLookupByID(vendor_id)
1643
1644 if vendor is None:
1645 raise Error('NoVendor', 'A vendor with this ID does not exist',
1646 {'field': 'id'})
1647
1648 if id is None:
1649 id = book.BillNextID(vendor)
1650
1651 try:
1652 date_opened = datetime.datetime.strptime(date_opened, "%Y-%m-%d")
1653 except ValueError:
1654 raise Error('InvalidVendorDateOpened',
1655 'The date opened must be provided in the form YYYY-MM-DD',
1656 {'field': 'date_opened'})
1657
1658 if currency_mnumonic is None:
1659 currency_mnumonic = vendor.GetCurrency().get_mnemonic()
1660
1661 commod_table = book.get_table()
1662 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1663
1664 if currency is None:
1665 raise Error('InvalidVendorCurrency',
1666 'A valid currency must be supplied for this vendor',
1667 {'field': 'currency'})
1668
1669 bill = Bill(book, id, currency, vendor, date_opened.date())
1670
1671 bill.SetNotes(notes)
1672
1673 return gnucash_simple.billToDict(bill)
1674

◆ addBillEntry()

gnucash_rest.addBillEntry (   book,
  bill_id,
  date,
  description,
  account_guid,
  quantity,
  price 
)

Definition at line 1516 of file gnucash_rest.py.

1517 price):
1518
1519 bill = getGnuCashBill(book,bill_id)
1520
1521 if bill is None:
1522 raise Error('NoBill', 'No bill exists with this ID',
1523 {'field': 'bill_id'})
1524
1525 try:
1526 date = datetime.datetime.strptime(date, "%Y-%m-%d")
1527 except ValueError:
1528 raise Error('InvalidDateOpened',
1529 'The date opened must be provided in the form YYYY-MM-DD',
1530 {'field': 'date'})
1531
1532 guid = gnucash.gnucash_core.GUID()
1533 gnucash.gnucash_core.GUIDString(account_guid, guid)
1534
1535 account = guid.AccountLookup(book)
1536
1537 if account is None:
1538 raise Error('NoAccount', 'No account exists with this GUID',
1539 {'field': 'account_guid'})
1540
1541 try:
1542 quantity = Decimal(quantity).quantize(Decimal('.01'))
1543 except ArithmeticError:
1544 raise Error('InvalidQuantity', 'This quantity is not valid',
1545 {'field': 'quantity'})
1546
1547 try:
1548 price = Decimal(price).quantize(Decimal('.01'))
1549 except ArithmeticError:
1550 raise Error('InvalidPrice', 'This price is not valid',
1551 {'field': 'price'})
1552
1553 entry = Entry(book, bill, date.date())
1554 entry.SetDateEntered(datetime.datetime.now())
1555 entry.SetDescription(description)
1556 entry.SetBillAccount(account)
1557 entry.SetQuantity(gnc_numeric_from_decimal(quantity))
1558 entry.SetBillPrice(gnc_numeric_from_decimal(price))
1559
1560 return gnucash_simple.entryToDict(entry)
1561

◆ addCustomer()

gnucash_rest.addCustomer (   book,
  id,
  currency_mnumonic,
  name,
  contact,
  address_line_1,
  address_line_2,
  address_line_3,
  address_line_4,
  phone,
  fax,
  email 
)

Definition at line 1206 of file gnucash_rest.py.

1207 address_line_2, address_line_3, address_line_4, phone, fax, email):
1208
1209 if name == '':
1210 raise Error('NoCustomerName',
1211 'A name must be entered for this company', {'field': 'name'})
1212
1213 if (address_line_1 == ''
1214 and address_line_2 == ''
1215 and address_line_3 == ''
1216 and address_line_4 == ''):
1217 raise Error('NoCustomerAddress',
1218 'An address must be entered for this company',
1219 {'field': 'address'})
1220
1221 commod_table = book.get_table()
1222 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1223
1224 if currency is None:
1225 raise Error('InvalidCustomerCurrency',
1226 'A valid currency must be supplied for this customer',
1227 {'field': 'currency'})
1228
1229 if id is None:
1230 id = book.CustomerNextID()
1231
1232 customer = Customer(session.book, id, currency, name)
1233
1234 address = customer.GetAddr()
1235 address.SetName(contact)
1236 address.SetAddr1(address_line_1)
1237 address.SetAddr2(address_line_2)
1238 address.SetAddr3(address_line_3)
1239 address.SetAddr4(address_line_4)
1240 address.SetPhone(phone)
1241 address.SetFax(fax)
1242 address.SetEmail(email)
1243
1244 return gnucash_simple.customerToDict(customer)
1245
customerToDict(customer)

◆ addEntry()

gnucash_rest.addEntry (   book,
  invoice_id,
  date,
  description,
  account_guid,
  quantity,
  price 
)

Definition at line 1471 of file gnucash_rest.py.

1471def addEntry(book, invoice_id, date, description, account_guid, quantity, price):
1472
1473 invoice = getGnuCashInvoice(book, invoice_id)
1474
1475 if invoice is None:
1476 raise Error('NoInvoice',
1477 'No invoice exists with this ID', {'field': 'invoice_id'})
1478
1479 try:
1480 date = datetime.datetime.strptime(date, "%Y-%m-%d")
1481 except ValueError:
1482 raise Error('InvalidDateOpened',
1483 'The date opened must be provided in the form YYYY-MM-DD',
1484 {'field': 'date'})
1485
1486 guid = gnucash.gnucash_core.GUID()
1487 gnucash.gnucash_core.GUIDString(account_guid, guid)
1488
1489 account = guid.AccountLookup(book)
1490
1491 if account is None:
1492 raise Error('NoAccount', 'No account exists with this GUID',
1493 {'field': 'account_guid'})
1494
1495 try:
1496 quantity = Decimal(quantity).quantize(Decimal('.01'))
1497 except ArithmeticError:
1498 raise Error('InvalidQuantity', 'This quantity is not valid',
1499 {'field': 'quantity'})
1500
1501 try:
1502 price = Decimal(price).quantize(Decimal('.01'))
1503 except ArithmeticError:
1504 raise Error('InvalidPrice', 'This price is not valid',
1505 {'field': 'price'})
1506
1507 entry = Entry(book, invoice, date.date())
1508 entry.SetDateEntered(datetime.datetime.now())
1509 entry.SetDescription(description)
1510 entry.SetInvAccount(account)
1511 entry.SetQuantity(gnc_numeric_from_decimal(quantity))
1512 entry.SetInvPrice(gnc_numeric_from_decimal(price))
1513
1514 return gnucash_simple.entryToDict(entry)
1515

◆ addInvoice()

gnucash_rest.addInvoice (   book,
  id,
  customer_id,
  currency_mnumonic,
  date_opened,
  notes 
)

Definition at line 1281 of file gnucash_rest.py.

1281def addInvoice(book, id, customer_id, currency_mnumonic, date_opened, notes):
1282
1283 customer = book.CustomerLookupByID(customer_id)
1284
1285 if customer is None:
1286 raise Error('NoCustomer',
1287 'A customer with this ID does not exist', {'field': 'id'})
1288
1289 if id is None:
1290 id = book.InvoiceNextID(customer)
1291
1292 try:
1293 date_opened = datetime.datetime.strptime(date_opened, "%Y-%m-%d")
1294 except ValueError:
1295 raise Error('InvalidDateOpened',
1296 'The date opened must be provided in the form YYYY-MM-DD',
1297 {'field': 'date_opened'})
1298
1299 if currency_mnumonic is None:
1300 currency_mnumonic = customer.GetCurrency().get_mnemonic()
1301
1302 commod_table = book.get_table()
1303 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1304
1305 if currency is None:
1306 raise Error('InvalidCustomerCurrency',
1307 'A valid currency must be supplied for this customer',
1308 {'field': 'currency'})
1309
1310 invoice = Invoice(book, id, currency, customer, date_opened.date())
1311
1312 invoice.SetNotes(notes)
1313
1314 return gnucash_simple.invoiceToDict(invoice)
1315
invoiceToDict(invoice)

◆ addTransaction()

gnucash_rest.addTransaction (   book,
  num,
  description,
  date_posted,
  currency_mnumonic,
  splits 
)

Definition at line 1736 of file gnucash_rest.py.

1736def addTransaction(book, num, description, date_posted, currency_mnumonic, splits):
1737
1738 transaction = Transaction(book)
1739
1740 transaction.BeginEdit()
1741
1742 commod_table = book.get_table()
1743 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1744
1745 if currency is None:
1746 raise Error('InvalidTransactionCurrency',
1747 'A valid currency must be supplied for this transaction',
1748 {'field': 'currency'})
1749
1750 try:
1751 date_posted = datetime.datetime.strptime(date_posted, "%Y-%m-%d")
1752 except ValueError:
1753 raise Error('InvalidDatePosted',
1754 'The date posted must be provided in the form YYYY-MM-DD',
1755 {'field': 'date_posted'})
1756
1757
1758 for split_values in splits:
1759 account_guid = gnucash.gnucash_core.GUID()
1760 gnucash.gnucash_core.GUIDString(split_values['account_guid'], account_guid)
1761
1762 account = account_guid.AccountLookup(book)
1763
1764 if account is None:
1765 raise Error('InvalidSplitAccount',
1766 'A valid account must be supplied for this split',
1767 {'field': 'account'})
1768
1769 split = Split(book)
1770 split.SetValue(GncNumeric(split_values['value'], 100))
1771 split.SetAccount(account)
1772 split.SetParent(transaction)
1773
1774 transaction.SetCurrency(currency)
1775 transaction.SetDescription(description)
1776 transaction.SetNum(num)
1777
1778 transaction.SetDatePostedTS(date_posted)
1779
1780 transaction.CommitEdit()
1781
1782 return gnucash_simple.transactionToDict(transaction, ['splits'])
1783
The primary numeric class for representing amounts and values.
transactionToDict(transaction, entities)

◆ addVendor()

gnucash_rest.addVendor (   book,
  id,
  currency_mnumonic,
  name,
  contact,
  address_line_1,
  address_line_2,
  address_line_3,
  address_line_4,
  phone,
  fax,
  email 
)

Definition at line 1166 of file gnucash_rest.py.

1167 address_line_2, address_line_3, address_line_4, phone, fax, email):
1168
1169 if name == '':
1170 raise Error('NoVendorName', 'A name must be entered for this company',
1171 {'field': 'name'})
1172
1173 if (address_line_1 == ''
1174 and address_line_2 == ''
1175 and address_line_3 == ''
1176 and address_line_4 == ''):
1177 raise Error('NoVendorAddress',
1178 'An address must be entered for this company',
1179 {'field': 'address'})
1180
1181 commod_table = book.get_table()
1182 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1183
1184 if currency is None:
1185 raise Error('InvalidVendorCurrency',
1186 'A valid currency must be supplied for this vendor',
1187 {'field': 'currency'})
1188
1189 if id is None:
1190 id = book.VendorNextID()
1191
1192 vendor = Vendor(session.book, id, currency, name)
1193
1194 address = vendor.GetAddr()
1195 address.SetName(contact)
1196 address.SetAddr1(address_line_1)
1197 address.SetAddr2(address_line_2)
1198 address.SetAddr3(address_line_3)
1199 address.SetAddr4(address_line_4)
1200 address.SetPhone(phone)
1201 address.SetFax(fax)
1202 address.SetEmail(email)
1203
1204 return gnucash_simple.vendorToDict(vendor)
1205

◆ api_account()

gnucash_rest.api_account (   guid)

Definition at line 112 of file gnucash_rest.py.

112def api_account(guid):
113
114 account = getAccount(session.book, guid)
115
116 if account is None:
117 abort(404)
118 else:
119 return Response(json.dumps(account), mimetype='application/json')
120
121@app.route('/accounts/<guid>/splits', methods=['GET'])

◆ api_account_splits()

gnucash_rest.api_account_splits (   guid)

Definition at line 122 of file gnucash_rest.py.

122def api_account_splits(guid):
123
124 date_posted_from = request.args.get('date_posted_from', None)
125 date_posted_to = request.args.get('date_posted_to', None)
126
127 # check account exists
128 account = getAccount(session.book, guid)
129
130 if account is None:
131 abort(404)
132
133 splits = getAccountSplits(session.book, guid, date_posted_from,
134 date_posted_to)
135
136 return Response(json.dumps(splits), mimetype='application/json')
137
138
139@app.route('/transactions', methods=['POST'])

◆ api_accounts()

gnucash_rest.api_accounts ( )

Definition at line 80 of file gnucash_rest.py.

80def api_accounts():
81
82 if request.method == 'GET':
83
84 accounts = getAccounts(session.book)
85
86 return Response(json.dumps(accounts), mimetype='application/json')
87
88 elif request.method == 'POST':
89
90 name = str(request.form.get('name', ''))
91 currency = str(request.form.get('currency', ''))
92 account_type_id = request.form.get('account_type_id', '')
93 parent_account_guid = str(request.form.get('parent_account_guid', ''))
94 description = str(request.form.get('description', ''))
95 code = str(request.form.get('code', ''))
96
97 try:
98 account = addAccount(session.book, name, currency,
99 account_type_id, parent_account_guid, description, code)
100 except Error as error:
101 return Response(json.dumps({'errors': [{'type' : error.type,
102 'message': error.message, 'data': error.data}]}), status=400,
103 mimetype='application/json')
104 else:
105 return Response(json.dumps(account), status=201,
106 mimetype='application/json')
107
108 else:
109 abort(405)
110
111@app.route('/accounts/<guid>', methods=['GET'])

◆ api_bill()

gnucash_rest.api_bill (   id)

Definition at line 284 of file gnucash_rest.py.

284def api_bill(id):
285
286 if request.method == 'GET':
287
288 bill = getBill(session.book, id)
289
290 if bill is None:
291 abort(404)
292 else:
293 return Response(json.dumps(bill), mimetype='application/json')
294
295 elif request.method == 'POST':
296
297 vendor_id = str(request.form.get('vendor_id', ''))
298 currency = str(request.form.get('currency', ''))
299 date_opened = request.form.get('date_opened', None)
300 notes = str(request.form.get('notes', ''))
301 posted = request.form.get('posted', None)
302 posted_account_guid = str(request.form.get('posted_account_guid', ''))
303 posted_date = request.form.get('posted_date', '')
304 due_date = request.form.get('due_date', '')
305 posted_memo = str(request.form.get('posted_memo', ''))
306 posted_accumulatesplits = request.form.get('posted_accumulatesplits',
307 '')
308 posted_autopay = request.form.get('posted_autopay', '')
309
310 if posted == '1':
311 posted = 1
312 else:
313 posted = 0
314
315 if (posted_accumulatesplits == '1'
316 or posted_accumulatesplits == 'true'
317 or posted_accumulatesplits == 'True'
318 or posted_accumulatesplits == True):
319 posted_accumulatesplits = True
320 else:
321 posted_accumulatesplits = False
322
323 if posted_autopay == '1':
324 posted_autopay = True
325 else:
326 posted_autopay = False
327 try:
328 bill = updateBill(session.book, id, vendor_id, currency,
329 date_opened, notes, posted, posted_account_guid, posted_date,
330 due_date, posted_memo, posted_accumulatesplits, posted_autopay)
331 except Error as error:
332 return Response(json.dumps({'errors': [{'type' : error.type,
333 'message': error.message, 'data': error.data}]}), status=400,
334 mimetype='application/json')
335 else:
336 return Response(json.dumps(bill), status=200,
337 mimetype='application/json')
338
339 if bill is None:
340 abort(404)
341 else:
342 return Response(json.dumps(bill),
343 mimetype='application/json')
344
345 elif request.method == 'PAY':
346
347 posted_account_guid = str(request.form.get('posted_account_guid', ''))
348 transfer_account_guid = str(request.form.get('transfer_account_guid',
349 ''))
350 payment_date = request.form.get('payment_date', '')
351 num = str(request.form.get('num', ''))
352 memo = str(request.form.get('posted_memo', ''))
353 auto_pay = request.form.get('auto_pay', '')
354
355 try:
356 bill = payBill(session.book, id, posted_account_guid,
357 transfer_account_guid, payment_date, memo, num, auto_pay)
358 except Error as error:
359 return Response(json.dumps({'errors': [{'type' : error.type,
360 'message': error.message, 'data': error.data}]}), status=400,
361 mimetype='application/json')
362 else:
363 return Response(json.dumps(bill), status=200,
364 mimetype='application/json')
365
366 else:
367 abort(405)
368
369@app.route('/bills/<id>/entries', methods=['GET', 'POST'])

◆ api_bill_entries()

gnucash_rest.api_bill_entries (   id)

Definition at line 370 of file gnucash_rest.py.

370def api_bill_entries(id):
371
372 bill = getBill(session.book, id)
373
374 if bill is None:
375 abort(404)
376 else:
377 if request.method == 'GET':
378 return Response(json.dumps(bill['entries']), mimetype='application/json')
379 elif request.method == 'POST':
380
381 date = str(request.form.get('date', ''))
382 description = str(request.form.get('description', ''))
383 account_guid = str(request.form.get('account_guid', ''))
384 quantity = str(request.form.get('quantity', ''))
385 price = str(request.form.get('price', ''))
386
387 try:
388 entry = addBillEntry(session.book, id, date, description,
389 account_guid, quantity, price)
390 except Error as error:
391 return Response(json.dumps({'errors': [{'type' : error.type,
392 'message': error.message, 'data': error.data}]}),
393 status=400, mimetype='application/json')
394 else:
395 return Response(json.dumps(entry), status=201,
396 mimetype='application/json')
397
398 else:
399 abort(405)
400
401@app.route('/invoices', methods=['GET', 'POST'])

◆ api_bills()

gnucash_rest.api_bills ( )

Definition at line 227 of file gnucash_rest.py.

227def api_bills():
228
229 if request.method == 'GET':
230
231 is_paid = request.args.get('is_paid', None)
232 is_active = request.args.get('is_active', None)
233 date_opened_to = request.args.get('date_opened_to', None)
234 date_opened_from = request.args.get('date_opened_from', None)
235
236 if is_paid == '1':
237 is_paid = 1
238 elif is_paid == '0':
239 is_paid = 0
240 else:
241 is_paid = None
242
243 if is_active == '1':
244 is_active = 1
245 elif is_active == '0':
246 is_active = 0
247 else:
248 is_active = None
249
250 bills = getBills(session.book, None, is_paid, is_active,
251 date_opened_from, date_opened_to)
252
253 return Response(json.dumps(bills), mimetype='application/json')
254
255 elif request.method == 'POST':
256
257 id = str(request.form.get('id', None))
258
259 if id == '':
260 id = None
261 elif id != None:
262 id = str(id)
263
264 vendor_id = str(request.form.get('vendor_id', ''))
265 currency = str(request.form.get('currency', ''))
266 date_opened = str(request.form.get('date_opened', ''))
267 notes = str(request.form.get('notes', ''))
268
269 try:
270 bill = addBill(session.book, id, vendor_id, currency, date_opened,
271 notes)
272 except Error as error:
273 # handle incorrect parameter errors
274 return Response(json.dumps({'errors': [{'type' : error.type,
275 'message': error.message, 'data': error.data}]}), status=400, mimetype='application/json')
276 else:
277 return Response(json.dumps(bill), status=201,
278 mimetype='application/json')
279
280 else:
281 abort(405)
282
283@app.route('/bills/<id>', methods=['GET', 'POST', 'PAY'])

◆ api_customer()

gnucash_rest.api_customer (   id)

Definition at line 656 of file gnucash_rest.py.

656def api_customer(id):
657
658 if request.method == 'GET':
659
660 customer = getCustomer(session.book, id)
661
662 if customer is None:
663 abort(404)
664 else:
665 return Response(json.dumps(customer), mimetype='application/json')
666
667 elif request.method == 'POST':
668
669 id = str(request.form.get('id', None))
670
671 name = str(request.form.get('name', ''))
672 contact = str(request.form.get('contact', ''))
673 address_line_1 = str(request.form.get('address_line_1', ''))
674 address_line_2 = str(request.form.get('address_line_2', ''))
675 address_line_3 = str(request.form.get('address_line_3', ''))
676 address_line_4 = str(request.form.get('address_line_4', ''))
677 phone = str(request.form.get('phone', ''))
678 fax = str(request.form.get('fax', ''))
679 email = str(request.form.get('email', ''))
680
681 try:
682 customer = updateCustomer(session.book, id, name, contact,
683 address_line_1, address_line_2, address_line_3, address_line_4,
684 phone, fax, email)
685 except Error as error:
686 if error.type == 'NoCustomer':
687 return Response(json.dumps({'errors': [{'type' : error.type,
688 'message': error.message, 'data': error.data}]}),
689 status=404, mimetype='application/json')
690 else:
691 return Response(json.dumps({'errors': [{'type' : error.type,
692 'message': error.message, 'data': error.data}]}),
693 status=400, mimetype='application/json')
694 else:
695 return Response(json.dumps(customer), status=200,
696 mimetype='application/json')
697
698 else:
699 abort(405)
700
701@app.route('/customers/<id>/invoices', methods=['GET'])

◆ api_customer_invoices()

gnucash_rest.api_customer_invoices (   id)

Definition at line 702 of file gnucash_rest.py.

702def api_customer_invoices(id):
703
704 customer = getCustomer(session.book, id)
705
706 if customer is None:
707 abort(404)
708
709 invoices = getInvoices(session.book, customer['guid'], None, None, None,
710 None)
711
712 return Response(json.dumps(invoices), mimetype='application/json')
713
714@app.route('/vendors', methods=['GET', 'POST'])

◆ api_customers()

gnucash_rest.api_customers ( )

Definition at line 615 of file gnucash_rest.py.

615def api_customers():
616
617 if request.method == 'GET':
618 customers = getCustomers(session.book)
619 return Response(json.dumps(customers), mimetype='application/json')
620 elif request.method == 'POST':
621
622 id = str(request.form.get('id', None))
623
624 if id == '':
625 id = None
626 elif id != None:
627 id = str(id)
628
629 currency = str(request.form.get('currency', ''))
630 name = str(request.form.get('name', ''))
631 contact = str(request.form.get('contact', ''))
632 address_line_1 = str(request.form.get('address_line_1', ''))
633 address_line_2 = str(request.form.get('address_line_2', ''))
634 address_line_3 = str(request.form.get('address_line_3', ''))
635 address_line_4 = str(request.form.get('address_line_4', ''))
636 phone = str(request.form.get('phone', ''))
637 fax = str(request.form.get('fax', ''))
638 email = str(request.form.get('email', ''))
639
640 try:
641 customer = addCustomer(session.book, id, currency, name, contact,
642 address_line_1, address_line_2, address_line_3, address_line_4,
643 phone, fax, email)
644 except Error as error:
645 return Response(json.dumps({'errors': [{'type' : error.type,
646 'message': error.message, 'data': error.data}]}), status=400,
647 mimetype='application/json')
648 else:
649 return Response(json.dumps(customer), status=201,
650 mimetype='application/json')
651
652 else:
653 abort(405)
654
655@app.route('/customers/<id>', methods=['GET', 'POST'])

◆ api_entry()

gnucash_rest.api_entry (   guid)

Definition at line 577 of file gnucash_rest.py.

577def api_entry(guid):
578
579 entry = getEntry(session.book, guid)
580
581 if entry is None:
582 abort(404)
583 else:
584 if request.method == 'GET':
585 return Response(json.dumps(entry), mimetype='application/json')
586 elif request.method == 'POST':
587
588 date = str(request.form.get('date', ''))
589 description = str(request.form.get('description', ''))
590 account_guid = str(request.form.get('account_guid', ''))
591 quantity = str(request.form.get('quantity', ''))
592 price = str(request.form.get('price', ''))
593
594 try:
595 entry = updateEntry(session.book, guid, date, description,
596 account_guid, quantity, price)
597 except Error as error:
598 return Response(json.dumps({'errors': [{'type' : error.type,
599 'message': error.message, 'data': error.data}]}),
600 status=400, mimetype='application/json')
601 else:
602 return Response(json.dumps(entry), status=200,
603 mimetype='application/json')
604
605 elif request.method == 'DELETE':
606
607 deleteEntry(session.book, guid)
608
609 return Response('', status=201, mimetype='application/json')
610
611 else:
612 abort(405)
613
614@app.route('/customers', methods=['GET', 'POST'])

◆ api_invoice()

gnucash_rest.api_invoice (   id)

Definition at line 459 of file gnucash_rest.py.

459def api_invoice(id):
460
461 if request.method == 'GET':
462
463 invoice = getInvoice(session.book, id)
464
465 if invoice is None:
466 abort(404)
467 else:
468 return Response(json.dumps(invoice), mimetype='application/json')
469
470 elif request.method == 'POST':
471
472 customer_id = str(request.form.get('customer_id', ''))
473 currency = str(request.form.get('currency', ''))
474 date_opened = request.form.get('date_opened', None)
475 notes = str(request.form.get('notes', ''))
476 posted = request.form.get('posted', None)
477 posted_account_guid = str(request.form.get('posted_account_guid', ''))
478 posted_date = request.form.get('posted_date', '')
479 due_date = request.form.get('due_date', '')
480 posted_memo = str(request.form.get('posted_memo', ''))
481 posted_accumulatesplits = request.form.get('posted_accumulatesplits',
482 '')
483 posted_autopay = request.form.get('posted_autopay', '')
484
485 if posted == '1':
486 posted = 1
487 else:
488 posted = 0
489
490 if (posted_accumulatesplits == '1'
491 or posted_accumulatesplits == 'true'
492 or posted_accumulatesplits == 'True'
493 or posted_accumulatesplits == True):
494 posted_accumulatesplits = True
495 else:
496 posted_accumulatesplits = False
497
498 if posted_autopay == '1':
499 posted_autopay = True
500 else:
501 posted_autopay = False
502 try:
503 invoice = updateInvoice(session.book, id, customer_id, currency,
504 date_opened, notes, posted, posted_account_guid, posted_date,
505 due_date, posted_memo, posted_accumulatesplits, posted_autopay)
506 except Error as error:
507 return Response(json.dumps({'errors': [{'type' : error.type,
508 'message': error.message, 'data': error.data}]}), status=400,
509 mimetype='application/json')
510 else:
511 return Response(json.dumps(invoice), status=200,
512 mimetype='application/json')
513
514 if invoice is None:
515 abort(404)
516 else:
517 return Response(json.dumps(invoice), mimetype='application/json')
518
519 elif request.method == 'PAY':
520
521 posted_account_guid = str(request.form.get('posted_account_guid', ''))
522 transfer_account_guid = str(request.form.get('transfer_account_guid',
523 ''))
524 payment_date = request.form.get('payment_date', '')
525 num = str(request.form.get('num', ''))
526 memo = str(request.form.get('posted_memo', ''))
527 auto_pay = request.form.get('auto_pay', '')
528
529 try:
530 invoice = payInvoice(session.book, id, posted_account_guid,
531 transfer_account_guid, payment_date, memo, num, auto_pay)
532 except Error as error:
533 return Response(json.dumps({'errors': [{'type' : error.type,
534 'message': error.message, 'data': error.data}]}), status=400,
535 mimetype='application/json')
536 else:
537 return Response(json.dumps(invoice), status=200,
538 mimetype='application/json')
539
540 else:
541 abort(405)
542
543@app.route('/invoices/<id>/entries', methods=['GET', 'POST'])

◆ api_invoice_entries()

gnucash_rest.api_invoice_entries (   id)

Definition at line 544 of file gnucash_rest.py.

544def api_invoice_entries(id):
545
546 invoice = getInvoice(session.book, id)
547
548 if invoice is None:
549 abort(404)
550 else:
551 if request.method == 'GET':
552 return Response(json.dumps(invoice['entries']),
553 mimetype='application/json')
554 elif request.method == 'POST':
555
556 date = str(request.form.get('date', ''))
557 description = str(request.form.get('description', ''))
558 account_guid = str(request.form.get('account_guid', ''))
559 quantity = str(request.form.get('quantity', ''))
560 price = str(request.form.get('price', ''))
561
562 try:
563 entry = addEntry(session.book, id, date, description,
564 account_guid, quantity, price)
565 except Error as error:
566 return Response(json.dumps({'errors': [{'type' : error.type,
567 'message': error.message, 'data': error.data}]}),
568 status=400, mimetype='application/json')
569 else:
570 return Response(json.dumps(entry), status=201,
571 mimetype='application/json')
572
573 else:
574 abort(405)
575
576@app.route('/entries/<guid>', methods=['GET', 'POST', 'DELETE'])

◆ api_invoices()

gnucash_rest.api_invoices ( )

Definition at line 402 of file gnucash_rest.py.

402def api_invoices():
403
404 if request.method == 'GET':
405
406 is_paid = request.args.get('is_paid', None)
407 is_active = request.args.get('is_active', None)
408 date_due_to = request.args.get('date_due_to', None)
409 date_due_from = request.args.get('date_due_from', None)
410
411 if is_paid == '1':
412 is_paid = 1
413 elif is_paid == '0':
414 is_paid = 0
415 else:
416 is_paid = None
417
418 if is_active == '1':
419 is_active = 1
420 elif is_active == '0':
421 is_active = 0
422 else:
423 is_active = None
424
425 invoices = getInvoices(session.book, None, is_paid, is_active,
426 date_due_from, date_due_to)
427
428 return Response(json.dumps(invoices), mimetype='application/json')
429
430 elif request.method == 'POST':
431
432 id = str(request.form.get('id', None))
433
434 if id == '':
435 id = None
436 elif id != None:
437 id = str(id)
438
439 customer_id = str(request.form.get('customer_id', ''))
440 currency = str(request.form.get('currency', ''))
441 date_opened = str(request.form.get('date_opened', ''))
442 notes = str(request.form.get('notes', ''))
443
444 try:
445 invoice = addInvoice(session.book, id, customer_id, currency,
446 date_opened, notes)
447 except Error as error:
448 return Response(json.dumps({'errors': [{'type' : error.type,
449 'message': error.message, 'data': error.data}]}), status=400,
450 mimetype='application/json')
451 else:
452 return Response(json.dumps(invoice), status=201,
453 mimetype='application/json')
454
455 else:
456 abort(405)
457
458@app.route('/invoices/<id>', methods=['GET', 'POST', 'PAY'])

◆ api_transaction()

gnucash_rest.api_transaction (   guid)

Definition at line 173 of file gnucash_rest.py.

173def api_transaction(guid):
174
175 if request.method == 'GET':
176
177 transaction = getTransaction(session.book, guid)
178
179 if transaction is None:
180 abort(404)
181
182 return Response(json.dumps(transaction), mimetype='application/json')
183
184 elif request.method == 'POST':
185
186 currency = str(request.form.get('currency', ''))
187 description = str(request.form.get('description', ''))
188 num = str(request.form.get('num', ''))
189 date_posted = str(request.form.get('date_posted', ''))
190
191 splitguid1 = str(request.form.get('splitguid1', ''))
192 splitvalue1 = int(request.form.get('splitvalue1', ''))
193 splitaccount1 = str(request.form.get('splitaccount1', ''))
194 splitguid2 = str(request.form.get('splitguid2', ''))
195 splitvalue2 = int(request.form.get('splitvalue2', ''))
196 splitaccount2 = str(request.form.get('splitaccount2', ''))
197
198 splits = [
199 {'guid': splitguid1,
200 'value': splitvalue1,
201 'account_guid': splitaccount1},
202 {'guid': splitguid2,
203 'value': splitvalue2,
204 'account_guid': splitaccount2}
205 ]
206
207 try:
208 transaction = editTransaction(session.book, guid, num, description,
209 date_posted, currency, splits)
210 except Error as error:
211 return Response(json.dumps({'errors': [{'type' : error.type,
212 'message': error.message, 'data': error.data}]}), status=400, mimetype='application/json')
213 else:
214 return Response(json.dumps(transaction), status=200,
215 mimetype='application/json')
216
217 elif request.method == 'DELETE':
218
219 deleteTransaction(session.book, guid)
220
221 return Response('', status=200, mimetype='application/json')
222
223 else:
224 abort(405)
225
226@app.route('/bills', methods=['GET', 'POST'])

◆ api_transactions()

gnucash_rest.api_transactions ( )

Definition at line 140 of file gnucash_rest.py.

140def api_transactions():
141
142 if request.method == 'POST':
143
144 currency = str(request.form.get('currency', ''))
145 description = str(request.form.get('description', ''))
146 num = str(request.form.get('num', ''))
147 date_posted = str(request.form.get('date_posted', ''))
148
149 splitvalue1 = int(request.form.get('splitvalue1', ''))
150 splitaccount1 = str(request.form.get('splitaccount1', ''))
151 splitvalue2 = int(request.form.get('splitvalue2', ''))
152 splitaccount2 = str(request.form.get('splitaccount2', ''))
153
154 splits = [
155 {'value': splitvalue1, 'account_guid': splitaccount1},
156 {'value': splitvalue2, 'account_guid': splitaccount2}]
157
158 try:
159 transaction = addTransaction(session.book, num, description,
160 date_posted, currency, splits)
161 except Error as error:
162 return Response(json.dumps({'errors': [{'type' : error.type,
163 'message': error.message, 'data': error.data}]}), status=400,
164 mimetype='application/json')
165 else:
166 return Response(json.dumps(transaction), status=201,
167 mimetype='application/json')
168
169 else:
170 abort(405)
171
172@app.route('/transactions/<guid>', methods=['GET', 'POST', 'DELETE'])

◆ api_vendor()

gnucash_rest.api_vendor (   id)

Definition at line 756 of file gnucash_rest.py.

756def api_vendor(id):
757
758 if request.method == 'GET':
759
760 vendor = getVendor(session.book, id)
761
762 if vendor is None:
763 abort(404)
764 else:
765 return Response(json.dumps(vendor), mimetype='application/json')
766 else:
767 abort(405)
768
769@app.route('/vendors/<id>/bills', methods=['GET'])

◆ api_vendor_bills()

gnucash_rest.api_vendor_bills (   id)

Definition at line 770 of file gnucash_rest.py.

770def api_vendor_bills(id):
771
772 vendor = getVendor(session.book, id)
773
774 if vendor is None:
775 abort(404)
776
777 bills = getBills(session.book, vendor['guid'], None, None, None, None)
778
779 return Response(json.dumps(bills), mimetype='application/json')
780

◆ api_vendors()

gnucash_rest.api_vendors ( )

Definition at line 715 of file gnucash_rest.py.

715def api_vendors():
716
717 if request.method == 'GET':
718 vendors = getVendors(session.book)
719 return Response(json.dumps(vendors), mimetype='application/json')
720 elif request.method == 'POST':
721
722 id = str(request.form.get('id', None))
723
724 if id == '':
725 id = None
726 elif id != None:
727 id = str(id)
728
729 currency = str(request.form.get('currency', ''))
730 name = str(request.form.get('name', ''))
731 contact = str(request.form.get('contact', ''))
732 address_line_1 = str(request.form.get('address_line_1', ''))
733 address_line_2 = str(request.form.get('address_line_2', ''))
734 address_line_3 = str(request.form.get('address_line_3', ''))
735 address_line_4 = str(request.form.get('address_line_4', ''))
736 phone = str(request.form.get('phone', ''))
737 fax = str(request.form.get('fax', ''))
738 email = str(request.form.get('email', ''))
739
740 try:
741 vendor = addVendor(session.book, id, currency, name, contact,
742 address_line_1, address_line_2, address_line_3, address_line_4,
743 phone, fax, email)
744 except Error as error:
745 return Response(json.dumps({'errors': [{'type' : error.type,
746 'message': error.message, 'data': error.data}]}), status=400,
747 mimetype='application/json')
748 else:
749 return Response(json.dumps(vendor), status=201,
750 mimetype='application/json')
751
752 else:
753 abort(405)
754
755@app.route('/vendors/<id>', methods=['GET', 'POST'])

◆ deleteEntry()

gnucash_rest.deleteEntry (   book,
  entry_guid 
)

Definition at line 1612 of file gnucash_rest.py.

1612def deleteEntry(book, entry_guid):
1613
1614 guid = gnucash.gnucash_core.GUID()
1615 gnucash.gnucash_core.GUIDString(entry_guid, guid)
1616
1617 entry = book.EntryLookup(guid)
1618
1619 invoice = entry.GetInvoice()
1620 bill = entry.GetBill()
1621
1622 if invoice != None and entry != None:
1623 invoice.RemoveEntry(entry)
1624 elif bill != None and entry != None:
1625 bill.RemoveEntry(entry)
1626
1627 if entry != None:
1628 entry.Destroy()
1629

◆ deleteTransaction()

gnucash_rest.deleteTransaction (   book,
  transaction_guid 
)

Definition at line 1630 of file gnucash_rest.py.

1630def deleteTransaction(book, transaction_guid):
1631
1632 guid = gnucash.gnucash_core.GUID()
1633 gnucash.gnucash_core.GUIDString(transaction_guid, guid)
1634
1635 transaction = guid.TransLookup(book)
1636
1637 if transaction != None :
1638 transaction.Destroy()
1639

◆ editTransaction()

gnucash_rest.editTransaction (   book,
  transaction_guid,
  num,
  description,
  date_posted,
  currency_mnumonic,
  splits 
)

Definition at line 1796 of file gnucash_rest.py.

1797 currency_mnumonic, splits):
1798
1799 guid = gnucash.gnucash_core.GUID()
1800 gnucash.gnucash_core.GUIDString(transaction_guid, guid)
1801
1802 transaction = guid.TransLookup(book)
1803
1804 if transaction is None:
1805 raise Error('NoCustomer',
1806 'A transaction with this GUID does not exist',
1807 {'field': 'guid'})
1808
1809 transaction.BeginEdit()
1810
1811 commod_table = book.get_table()
1812 currency = commod_table.lookup('CURRENCY', currency_mnumonic)
1813
1814 if currency is None:
1815 raise Error('InvalidTransactionCurrency',
1816 'A valid currency must be supplied for this transaction',
1817 {'field': 'currency'})
1818
1819
1820 try:
1821 date_posted = datetime.datetime.strptime(date_posted, "%Y-%m-%d")
1822 except ValueError:
1823 raise Error('InvalidDatePosted',
1824 'The date posted must be provided in the form YYYY-MM-DD',
1825 {'field': 'date_posted'})
1826
1827 for split_values in splits:
1828
1829 split_guid = gnucash.gnucash_core.GUID()
1830 gnucash.gnucash_core.GUIDString(split_values['guid'], split_guid)
1831
1832 split = split_guid.SplitLookup(book)
1833
1834 if split is None:
1835 raise Error('InvalidSplitGuid',
1836 'A valid guid must be supplied for this split',
1837 {'field': 'guid'})
1838
1839 account_guid = gnucash.gnucash_core.GUID()
1840 gnucash.gnucash_core.GUIDString(
1841 split_values['account_guid'], account_guid)
1842
1843 account = account_guid.AccountLookup(book)
1844
1845 if account is None:
1846 raise Error('InvalidSplitAccount',
1847 'A valid account must be supplied for this split',
1848 {'field': 'account'})
1849
1850 split.SetValue(GncNumeric(split_values['value'], 100))
1851 split.SetAccount(account)
1852 split.SetParent(transaction)
1853
1854 transaction.SetCurrency(currency)
1855 transaction.SetDescription(description)
1856 transaction.SetNum(num)
1857
1858 transaction.SetDatePostedTS(date_posted)
1859
1860 transaction.CommitEdit()
1861
1862 return gnucash_simple.transactionToDict(transaction, ['splits'])
1863

◆ getAccount()

gnucash_rest.getAccount (   book,
  guid 
)

Definition at line 866 of file gnucash_rest.py.

866def getAccount(book, guid):
867
868 account_guid = gnucash.gnucash_core.GUID()
869 gnucash.gnucash_core.GUIDString(guid, account_guid)
870
871 account = account_guid.AccountLookup(book)
872
873 if account is None:
874 return None
875
876 account = gnucash_simple.accountToDict(account)
877
878 if account is None:
879 return None
880 else:
881 return account
882
883

◆ getAccounts()

gnucash_rest.getAccounts (   book)

Definition at line 829 of file gnucash_rest.py.

829def getAccounts(book):
830
831 accounts = gnucash_simple.accountToDict(book.get_root_account())
832
833 return accounts
834

◆ getAccountsFlat()

gnucash_rest.getAccountsFlat (   book)

Definition at line 835 of file gnucash_rest.py.

835def getAccountsFlat(book):
836
837 accounts = gnucash_simple.accountToDict(book.get_root_account())
838
839 flat_accounts = getSubAccounts(accounts)
840
841 for n, account in enumerate(flat_accounts):
842 account.pop('subaccounts')
843
844 filtered_flat_account = []
845
846 type_ids = [9]
847
848 for n, account in enumerate(flat_accounts):
849 if account['type_id'] in type_ids:
850 filtered_flat_account.append(account)
851 print(account['name'] + ' ' + str(account['type_id']))
852
853 return filtered_flat_account
854

◆ getAccountSplits()

gnucash_rest.getAccountSplits (   book,
  guid,
  date_posted_from,
  date_posted_to 
)

Definition at line 918 of file gnucash_rest.py.

918def getAccountSplits(book, guid, date_posted_from, date_posted_to):
919
920 account_guid = gnucash.gnucash_core.GUID()
921 gnucash.gnucash_core.GUIDString(guid, account_guid)
922
923 query = gnucash.Query()
924 query.search_for('Split')
925 query.set_book(book)
926
927 SPLIT_TRANS= 'trans'
928
929 TRANS_DATE_POSTED = 'date-posted'
930
931 if date_posted_from != None:
932 pred_data = gnucash.gnucash_core.QueryDatePredicate(
933 QOF_COMPARE_GTE, QOF_DATE_MATCH_NORMAL, datetime.datetime.strptime(
934 date_posted_from, "%Y-%m-%d").date())
935 param_list = [SPLIT_TRANS, TRANS_DATE_POSTED]
936 query.add_term(param_list, pred_data, QOF_QUERY_AND)
937
938 if date_posted_to != None:
939 pred_data = gnucash.gnucash_core.QueryDatePredicate(
940 QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, datetime.datetime.strptime(
941 date_posted_to, "%Y-%m-%d").date())
942 param_list = [SPLIT_TRANS, TRANS_DATE_POSTED]
943 query.add_term(param_list, pred_data, QOF_QUERY_AND)
944
945 SPLIT_ACCOUNT = 'account'
946 QOF_PARAM_GUID = 'guid'
947
948 if guid != None:
949 gnucash.gnucash_core.GUIDString(guid, account_guid)
950 query.add_guid_match(
951 [SPLIT_ACCOUNT, QOF_PARAM_GUID], account_guid, QOF_QUERY_AND)
952
953 splits = []
954
955 for split in query.run():
956 splits.append(gnucash_simple.splitToDict(
957 gnucash.gnucash_business.Split(instance=split),
958 ['account', 'transaction', 'other_split']))
959
960 query.destroy()
961
962 return splits
963
splitToDict(split, entities)

◆ getBill()

gnucash_rest.getBill (   book,
  id 
)

Definition at line 1162 of file gnucash_rest.py.

1162def getBill(book, id):
1163
1164 return gnucash_simple.billToDict(getGnuCashBill(book, id))
1165

◆ getBills()

gnucash_rest.getBills (   book,
  customer,
  is_paid,
  is_active,
  date_opened_from,
  date_opened_to 
)

Definition at line 1017 of file gnucash_rest.py.

1018 date_opened_to):
1019
1020 query = gnucash.Query()
1021 query.search_for('gncInvoice')
1022 query.set_book(book)
1023
1024 if is_paid == 0:
1025 query.add_boolean_match([INVOICE_IS_PAID], False, QOF_QUERY_AND)
1026 elif is_paid == 1:
1027 query.add_boolean_match([INVOICE_IS_PAID], True, QOF_QUERY_AND)
1028
1029 # active = JOB_IS_ACTIVE
1030 if is_active == 0:
1031 query.add_boolean_match(['active'], False, QOF_QUERY_AND)
1032 elif is_active == 1:
1033 query.add_boolean_match(['active'], True, QOF_QUERY_AND)
1034
1035 QOF_PARAM_GUID = 'guid'
1036 INVOICE_OWNER = 'owner'
1037
1038 if customer != None:
1039 customer_guid = gnucash.gnucash_core.GUID()
1040 gnucash.gnucash_core.GUIDString(customer, customer_guid)
1041 query.add_guid_match(
1042 [INVOICE_OWNER, QOF_PARAM_GUID], customer_guid, QOF_QUERY_AND)
1043
1044 if date_opened_from != None:
1045 pred_data = gnucash.gnucash_core.QueryDatePredicate(
1046 QOF_COMPARE_GTE, 2, datetime.datetime.strptime(
1047 date_opened_from, "%Y-%m-%d").date())
1048 query.add_term(['date_opened'], pred_data, QOF_QUERY_AND)
1049
1050 if date_opened_to != None:
1051 pred_data = gnucash.gnucash_core.QueryDatePredicate(
1052 QOF_COMPARE_LTE, 2, datetime.datetime.strptime(
1053 date_opened_to, "%Y-%m-%d").date())
1054 query.add_term(['date_opened'], pred_data, QOF_QUERY_AND)
1055
1056 # return only bills (2 = bills)
1057 pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 2)
1058 query.add_term([INVOICE_TYPE], pred_data, QOF_QUERY_AND)
1059
1060 bills = []
1061
1062 for result in query.run():
1063 bills.append(gnucash_simple.billToDict(
1064 gnucash.gnucash_business.Bill(instance=result)))
1065
1066 query.destroy()
1067
1068 return bills
1069

◆ getCustomer()

gnucash_rest.getCustomer (   book,
  id 
)

Definition at line 796 of file gnucash_rest.py.

796def getCustomer(book, id):
797
798 customer = book.CustomerLookupByID(id)
799
800 if customer is None:
801 return None
802 else:
803 return gnucash_simple.customerToDict(customer)
804

◆ getCustomers()

gnucash_rest.getCustomers (   book)

Definition at line 781 of file gnucash_rest.py.

781def getCustomers(book):
782
783 query = gnucash.Query()
784 query.search_for('gncCustomer')
785 query.set_book(book)
786 customers = []
787
788 for result in query.run():
789 customers.append(gnucash_simple.customerToDict(
790 gnucash.gnucash_business.Customer(instance=result)))
791
792 query.destroy()
793
794 return customers
795

◆ getEntry()

gnucash_rest.getEntry (   book,
  entry_guid 
)

Definition at line 1562 of file gnucash_rest.py.

1562def getEntry(book, entry_guid):
1563
1564 guid = gnucash.gnucash_core.GUID()
1565 gnucash.gnucash_core.GUIDString(entry_guid, guid)
1566
1567 entry = book.EntryLookup(guid)
1568
1569 if entry is None:
1570 return None
1571 else:
1572 return gnucash_simple.entryToDict(entry)
1573

◆ getGnuCashBill()

gnucash_rest.getGnuCashBill (   book,
  id 
)

Definition at line 1098 of file gnucash_rest.py.

1098def getGnuCashBill(book ,id):
1099
1100 # we don't use book.InvoicelLookupByID(id) as this is identical to
1101 # book.BillLookupByID(id) so can return the same object if they share IDs
1102
1103 query = gnucash.Query()
1104 query.search_for('gncInvoice')
1105 query.set_book(book)
1106
1107 # return only bills (2 = bills)
1108 pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 2)
1109 query.add_term([INVOICE_TYPE], pred_data, QOF_QUERY_AND)
1110
1111 INVOICE_ID = 'id'
1112
1113 pred_data = gnucash.gnucash_core.QueryStringPredicate(
1114 QOF_COMPARE_EQUAL, id, QOF_STRING_MATCH_NORMAL, False)
1115 query.add_term([INVOICE_ID], pred_data, QOF_QUERY_AND)
1116
1117 bill = None
1118
1119 for result in query.run():
1120 bill = gnucash.gnucash_business.Bill(instance=result)
1121
1122 query.destroy()
1123
1124 return bill
1125

◆ getGnuCashInvoice()

gnucash_rest.getGnuCashInvoice (   book,
  id 
)

Definition at line 1070 of file gnucash_rest.py.

1070def getGnuCashInvoice(book ,id):
1071
1072 # we don't use book.InvoicelLookupByID(id) as this is identical to
1073 # book.BillLookupByID(id) so can return the same object if they share IDs
1074
1075 query = gnucash.Query()
1076 query.search_for('gncInvoice')
1077 query.set_book(book)
1078
1079 # return only invoices (1 = invoices)
1080 pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 1)
1081 query.add_term([INVOICE_TYPE], pred_data, QOF_QUERY_AND)
1082
1083 INVOICE_ID = 'id'
1084
1085 pred_data = gnucash.gnucash_core.QueryStringPredicate(
1086 QOF_COMPARE_EQUAL, id, QOF_STRING_MATCH_NORMAL, False)
1087 query.add_term([INVOICE_ID], pred_data, QOF_QUERY_AND)
1088
1089 invoice = None
1090
1091 for result in query.run():
1092 invoice = gnucash.gnucash_business.Invoice(instance=result)
1093
1094 query.destroy()
1095
1096 return invoice
1097

◆ getInvoice()

gnucash_rest.getInvoice (   book,
  id 
)

Definition at line 1126 of file gnucash_rest.py.

1126def getInvoice(book, id):
1127
1128 return gnucash_simple.invoiceToDict(getGnuCashInvoice(book, id))
1129

◆ getInvoices()

gnucash_rest.getInvoices (   book,
  customer,
  is_paid,
  is_active,
  date_due_from,
  date_due_to 
)

Definition at line 964 of file gnucash_rest.py.

965 date_due_to):
966
967 query = gnucash.Query()
968 query.search_for('gncInvoice')
969 query.set_book(book)
970
971 if is_paid == 0:
972 query.add_boolean_match([INVOICE_IS_PAID], False, QOF_QUERY_AND)
973 elif is_paid == 1:
974 query.add_boolean_match([INVOICE_IS_PAID], True, QOF_QUERY_AND)
975
976 # active = JOB_IS_ACTIVE
977 if is_active == 0:
978 query.add_boolean_match(['active'], False, QOF_QUERY_AND)
979 elif is_active == 1:
980 query.add_boolean_match(['active'], True, QOF_QUERY_AND)
981
982 QOF_PARAM_GUID = 'guid'
983 INVOICE_OWNER = 'owner'
984
985 if customer != None:
986 customer_guid = gnucash.gnucash_core.GUID()
987 gnucash.gnucash_core.GUIDString(customer, customer_guid)
988 query.add_guid_match(
989 [INVOICE_OWNER, QOF_PARAM_GUID], customer_guid, QOF_QUERY_AND)
990
991 if date_due_from != None:
992 pred_data = gnucash.gnucash_core.QueryDatePredicate(
993 QOF_COMPARE_GTE, 2, datetime.datetime.strptime(
994 date_due_from, "%Y-%m-%d").date())
995 query.add_term(['date_due'], pred_data, QOF_QUERY_AND)
996
997 if date_due_to != None:
998 pred_data = gnucash.gnucash_core.QueryDatePredicate(
999 QOF_COMPARE_LTE, 2, datetime.datetime.strptime(
1000 date_due_to, "%Y-%m-%d").date())
1001 query.add_term(['date_due'], pred_data, QOF_QUERY_AND)
1002
1003 # return only invoices (1 = invoices)
1004 pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 1)
1005 query.add_term([INVOICE_TYPE], pred_data, QOF_QUERY_AND)
1006
1007 invoices = []
1008
1009 for result in query.run():
1010 invoices.append(gnucash_simple.invoiceToDict(
1011 gnucash.gnucash_business.Invoice(instance=result)))
1012
1013 query.destroy()
1014
1015 return invoices
1016

◆ getSubAccounts()

gnucash_rest.getSubAccounts (   account)

Definition at line 855 of file gnucash_rest.py.

855def getSubAccounts(account):
856
857 flat_accounts = []
858
859 if 'subaccounts' in list(account.keys()):
860 for n, subaccount in enumerate(account['subaccounts']):
861 flat_accounts.append(subaccount)
862 flat_accounts = flat_accounts + getSubAccounts(subaccount)
863
864 return flat_accounts
865

◆ getTransaction()

gnucash_rest.getTransaction (   book,
  guid 
)

Definition at line 884 of file gnucash_rest.py.

884def getTransaction(book, guid):
885
886 transaction_guid = gnucash.gnucash_core.GUID()
887 gnucash.gnucash_core.GUIDString(guid, transaction_guid)
888
889 transaction = transaction_guid.TransactionLookup(book)
890
891 if transaction is None:
892 return None
893
894 transaction = gnucash_simple.transactionToDict(transaction, ['splits'])
895
896 if transaction is None:
897 return None
898 else:
899 return transaction
900

◆ getTransactions()

gnucash_rest.getTransactions (   book,
  account_guid,
  date_posted_from,
  date_posted_to 
)

Definition at line 901 of file gnucash_rest.py.

901def getTransactions(book, account_guid, date_posted_from, date_posted_to):
902
903 query = gnucash.Query()
904
905 query.search_for('Trans')
906 query.set_book(book)
907
908 transactions = []
909
910 for transaction in query.run():
911 transactions.append(gnucash_simple.transactionToDict(
912 gnucash.gnucash_business.Transaction(instance=transaction)))
913
914 query.destroy()
915
916 return transactions
917

◆ getVendor()

gnucash_rest.getVendor (   book,
  id 
)

Definition at line 820 of file gnucash_rest.py.

820def getVendor(book, id):
821
822 vendor = book.VendorLookupByID(id)
823
824 if vendor is None:
825 return None
826 else:
827 return gnucash_simple.vendorToDict(vendor)
828

◆ getVendors()

gnucash_rest.getVendors (   book)

Definition at line 805 of file gnucash_rest.py.

805def getVendors(book):
806
807 query = gnucash.Query()
808 query.search_for('gncVendor')
809 query.set_book(book)
810 vendors = []
811
812 for result in query.run():
813 vendors.append(gnucash_simple.vendorToDict(
814 gnucash.gnucash_business.Vendor(instance=result)))
815
816 query.destroy()
817
818 return vendors
819

◆ gnc_numeric_from_decimal()

gnucash_rest.gnc_numeric_from_decimal (   decimal_value)

Definition at line 1864 of file gnucash_rest.py.

1864def gnc_numeric_from_decimal(decimal_value):
1865 sign, digits, exponent = decimal_value.as_tuple()
1866
1867 # convert decimal digits to a fractional numerator
1868 # equivalent to
1869 # numerator = int(''.join(digits))
1870 # but without the wated conversion to string and back,
1871 # this is probably the same algorithm int() uses
1872 numerator = 0
1873 TEN = int(Decimal(0).radix()) # this is always 10
1874 numerator_place_value = 1
1875 # add each digit to the final value multiplied by the place value
1876 # from least significant to most significant
1877 for i in range(len(digits)-1,-1,-1):
1878 numerator += digits[i] * numerator_place_value
1879 numerator_place_value *= TEN
1880
1881 if decimal_value.is_signed():
1882 numerator = -numerator
1883
1884 # if the exponent is negative, we use it to set the denominator
1885 if exponent < 0 :
1886 denominator = TEN ** (-exponent)
1887 # if the exponent isn't negative, we bump up the numerator
1888 # and set the denominator to 1
1889 else:
1890 numerator *= TEN ** exponent
1891 denominator = 1
1892
1893 return GncNumeric(numerator, denominator)
1894

◆ payBill()

gnucash_rest.payBill (   book,
  id,
  posted_account_guid,
  transfer_account_guid,
  payment_date,
  memo,
  num,
  auto_pay 
)

Definition at line 1145 of file gnucash_rest.py.

1146 memo, num, auto_pay):
1147
1148 bill = getGnuCashBill(book, id)
1149
1150 account_guid = gnucash.gnucash_core.GUID()
1151 gnucash.gnucash_core.GUIDString(transfer_account_guid, account_guid)
1152
1153 xfer_acc = account_guid.AccountLookup(session.book)
1154
1155 # We pay the negative total as the bill as this seemed to cause issues
1156 # with the split not being set correctly and not being marked as paid
1157 bill.ApplyPayment(None, xfer_acc, bill.GetTotal().neg(), GncNumeric(0),
1158 datetime.datetime.strptime(payment_date, '%Y-%m-%d'), memo, num)
1159
1160 return gnucash_simple.billToDict(bill)
1161

◆ payInvoice()

gnucash_rest.payInvoice (   book,
  id,
  posted_account_guid,
  transfer_account_guid,
  payment_date,
  memo,
  num,
  auto_pay 
)

Definition at line 1130 of file gnucash_rest.py.

1131 payment_date, memo, num, auto_pay):
1132
1133 invoice = getGnuCashInvoice(book, id)
1134
1135 account_guid2 = gnucash.gnucash_core.GUID()
1136 gnucash.gnucash_core.GUIDString(transfer_account_guid, account_guid2)
1137
1138 xfer_acc = account_guid2.AccountLookup(session.book)
1139
1140 invoice.ApplyPayment(None, xfer_acc, invoice.GetTotal(), GncNumeric(0),
1141 datetime.datetime.strptime(payment_date, '%Y-%m-%d'), memo, num)
1142
1143 return gnucash_simple.invoiceToDict(invoice)
1144

◆ shutdown()

gnucash_rest.shutdown ( )

Definition at line 1895 of file gnucash_rest.py.

1895def shutdown():
1896 session.save()
1897 session.end()
1898 session.destroy()
1899 print('Shutdown')
1900

◆ updateBill()

gnucash_rest.updateBill (   book,
  id,
  vendor_id,
  currency_mnumonic,
  date_opened,
  notes,
  posted,
  posted_account_guid,
  posted_date,
  due_date,
  posted_memo,
  posted_accumulatesplits,
  posted_autopay 
)

Definition at line 1394 of file gnucash_rest.py.

1396 posted_accumulatesplits, posted_autopay):
1397
1398 bill = getGnuCashBill(book, id)
1399
1400 if bill is None:
1401 raise Error('NoBill', 'A bill with this ID does not exist',
1402 {'field': 'id'})
1403
1404 vendor = book.VendorLookupByID(vendor_id)
1405
1406 if vendor is None:
1407 raise Error('NoVendor',
1408 'A vendor with this ID does not exist',
1409 {'field': 'vendor_id'})
1410
1411 try:
1412 date_opened = datetime.datetime.strptime(date_opened, "%Y-%m-%d")
1413 except ValueError:
1414 raise Error('InvalidDateOpened',
1415 'The date opened must be provided in the form YYYY-MM-DD',
1416 {'field': 'date_opened'})
1417
1418 if posted_date == '':
1419 if posted == 1:
1420 raise Error('NoDatePosted',
1421 'The date posted must be supplied when posted=1',
1422 {'field': 'date_posted'})
1423 else:
1424 try:
1425 posted_date = datetime.datetime.strptime(posted_date, "%Y-%m-%d")
1426 except ValueError:
1427 raise Error('InvalidDatePosted',
1428 'The date posted must be provided in the form YYYY-MM-DD',
1429 {'field': 'posted_date'})
1430
1431 if due_date == '':
1432 if posted == 1:
1433 raise Error('NoDatePosted',
1434 'The due date must be supplied when posted=1',
1435 {'field': 'date_posted'})
1436 else:
1437 try:
1438 due_date = datetime.datetime.strptime(due_date, "%Y-%m-%d")
1439 except ValueError:
1440 raise Error('InvalidDatePosted',
1441 'The due date must be provided in the form YYYY-MM-DD',
1442 {'field': 'due_date'})
1443
1444 if posted_account_guid == '':
1445 if posted == 1:
1446 raise Error('NoPostedAccountGuid',
1447 'The posted account GUID must be supplied when posted=1',
1448 {'field': 'posted_account_guid'})
1449 else:
1450 guid = gnucash.gnucash_core.GUID()
1451 gnucash.gnucash_core.GUIDString(posted_account_guid, guid)
1452
1453 posted_account = guid.AccountLookup(book)
1454
1455 if posted_account is None:
1456 raise Error('NoAccount',
1457 'No account exists with the posted account GUID',
1458 {'field': 'posted_account_guid'})
1459
1460 bill.SetOwner(vendor)
1461 bill.SetDateOpened(date_opened)
1462 bill.SetNotes(notes)
1463
1464 # post if currently unposted and posted=1
1465 if bill.GetDatePosted().strftime('%Y-%m-%d') == '1970-01-01' and posted == 1:
1466 bill.PostToAccount(posted_account, posted_date, due_date, posted_memo,
1467 posted_accumulatesplits, posted_autopay)
1468
1469 return gnucash_simple.billToDict(bill)
1470

◆ updateCustomer()

gnucash_rest.updateCustomer (   book,
  id,
  name,
  contact,
  address_line_1,
  address_line_2,
  address_line_3,
  address_line_4,
  phone,
  fax,
  email 
)

Definition at line 1246 of file gnucash_rest.py.

1247 address_line_3, address_line_4, phone, fax, email):
1248
1249 customer = book.CustomerLookupByID(id)
1250
1251 if customer is None:
1252 raise Error('NoCustomer', 'A customer with this ID does not exist',
1253 {'field': 'id'})
1254
1255 if name == '':
1256 raise Error('NoCustomerName',
1257 'A name must be entered for this company', {'field': 'name'})
1258
1259 if (address_line_1 == ''
1260 and address_line_2 == ''
1261 and address_line_3 == ''
1262 and address_line_4 == ''):
1263 raise Error('NoCustomerAddress',
1264 'An address must be entered for this company',
1265 {'field': 'address'})
1266
1267 customer.SetName(name)
1268
1269 address = customer.GetAddr()
1270 address.SetName(contact)
1271 address.SetAddr1(address_line_1)
1272 address.SetAddr2(address_line_2)
1273 address.SetAddr3(address_line_3)
1274 address.SetAddr4(address_line_4)
1275 address.SetPhone(phone)
1276 address.SetFax(fax)
1277 address.SetEmail(email)
1278
1279 return gnucash_simple.customerToDict(customer)
1280

◆ updateEntry()

gnucash_rest.updateEntry (   book,
  entry_guid,
  date,
  description,
  account_guid,
  quantity,
  price 
)

Definition at line 1574 of file gnucash_rest.py.

1575 price):
1576
1577 guid = gnucash.gnucash_core.GUID()
1578 gnucash.gnucash_core.GUIDString(entry_guid, guid)
1579
1580 entry = book.EntryLookup(guid)
1581
1582 if entry is None:
1583 raise Error('NoEntry', 'No entry exists with this GUID',
1584 {'field': 'entry_guid'})
1585
1586 try:
1587 date = datetime.datetime.strptime(date, "%Y-%m-%d")
1588 except ValueError:
1589 raise Error('InvalidDateOpened',
1590 'The date opened must be provided in the form YYYY-MM-DD',
1591 {'field': 'date'})
1592
1593 gnucash.gnucash_core.GUIDString(account_guid, guid)
1594
1595 account = guid.AccountLookup(book)
1596
1597 if account is None:
1598 raise Error('NoAccount', 'No account exists with this GUID',
1599 {'field': 'account_guid'})
1600
1601 entry.SetDate(date.date())
1602 entry.SetDateEntered(datetime.datetime.now())
1603 entry.SetDescription(description)
1604 entry.SetInvAccount(account)
1605 entry.SetQuantity(
1606 gnc_numeric_from_decimal(Decimal(quantity).quantize(Decimal('.01'))))
1607 entry.SetInvPrice(
1608 gnc_numeric_from_decimal(Decimal(price).quantize(Decimal('.01'))))
1609
1610 return gnucash_simple.entryToDict(entry)
1611

◆ updateInvoice()

gnucash_rest.updateInvoice (   book,
  id,
  customer_id,
  currency_mnumonic,
  date_opened,
  notes,
  posted,
  posted_account_guid,
  posted_date,
  due_date,
  posted_memo,
  posted_accumulatesplits,
  posted_autopay 
)

Definition at line 1316 of file gnucash_rest.py.

1318 posted_accumulatesplits, posted_autopay):
1319
1320 invoice = getGnuCashInvoice(book, id)
1321
1322 if invoice is None:
1323 raise Error('NoInvoice',
1324 'An invoice with this ID does not exist',
1325 {'field': 'id'})
1326
1327 customer = book.CustomerLookupByID(customer_id)
1328
1329 if customer is None:
1330 raise Error('NoCustomer', 'A customer with this ID does not exist',
1331 {'field': 'customer_id'})
1332
1333 try:
1334 date_opened = datetime.datetime.strptime(date_opened, "%Y-%m-%d")
1335 except ValueError:
1336 raise Error('InvalidDateOpened',
1337 'The date opened must be provided in the form YYYY-MM-DD',
1338 {'field': 'date_opened'})
1339
1340 if posted_date == '':
1341 if posted == 1:
1342 raise Error('NoDatePosted',
1343 'The date posted must be supplied when posted=1',
1344 {'field': 'date_posted'})
1345 else:
1346 try:
1347 posted_date = datetime.datetime.strptime(posted_date, "%Y-%m-%d")
1348 except ValueError:
1349 raise Error('InvalidDatePosted',
1350 'The date posted must be provided in the form YYYY-MM-DD',
1351 {'field': 'posted_date'})
1352
1353 if due_date == '':
1354 if posted == 1:
1355 raise Error('NoDatePosted',
1356 'The due date must be supplied when posted=1',
1357 {'field': 'date_posted'})
1358 else:
1359 try:
1360 due_date = datetime.datetime.strptime(due_date, "%Y-%m-%d")
1361 except ValueError:
1362 raise Error('InvalidDatePosted',
1363 'The due date must be provided in the form YYYY-MM-DD',
1364 {'field': 'due_date'})
1365
1366 if posted_account_guid == '':
1367 if posted == 1:
1368 raise Error('NoPostedAccountGuid',
1369 'The posted account GUID must be supplied when posted=1',
1370 {'field': 'posted_account_guid'})
1371 else:
1372 guid = gnucash.gnucash_core.GUID()
1373 gnucash.gnucash_core.GUIDString(posted_account_guid, guid)
1374
1375 posted_account = guid.AccountLookup(book)
1376
1377 if posted_account is None:
1378 raise Error('NoAccount',
1379 'No account exists with the posted account GUID',
1380 {'field': 'posted_account_guid'})
1381
1382 invoice.SetOwner(customer)
1383 invoice.SetDateOpened(date_opened)
1384 invoice.SetNotes(notes)
1385
1386 # post if currently unposted and posted=1
1387 if (invoice.GetDatePosted().strftime('%Y-%m-%d') == '1970-01-01'
1388 and posted == 1):
1389 invoice.PostToAccount(posted_account, posted_date, due_date,
1390 posted_memo, posted_accumulatesplits, posted_autopay)
1391
1392 return gnucash_simple.invoiceToDict(invoice)
1393

Variable Documentation

◆ app

gnucash_rest.app = Flask(__name__)

Definition at line 76 of file gnucash_rest.py.

◆ debug

gnucash_rest.debug

Definition at line 77 of file gnucash_rest.py.

◆ host

gnucash_rest.host = '127.0.0.1'

Definition at line 1920 of file gnucash_rest.py.

◆ is_new

bool gnucash_rest.is_new = False

Definition at line 1927 of file gnucash_rest.py.

◆ session

gnucash_rest.session = gnucash.Session(arguments[0], SessionOpenMode.SESSION_NEW_STORE)

Definition at line 1937 of file gnucash_rest.py.

◆ stream_handler

gnucash_rest.stream_handler = StreamHandler()

Definition at line 1958 of file gnucash_rest.py.