Problems adding an invoice using python bindings
Tom Lofts
dev at loftx.co.uk
Sat Mar 23 11:04:02 EDT 2013
Hi there,
I'm looking at adding invoices to gnucash (2.4.11) using the python
bindings, but am running into some problems relating to the currency.
Based on the examples available, the following script fails on my
existing gnucash (mysql) database:
-----------------------
from gnucash import Session
from gnucash.gnucash_business import Customer
session = Session('mysql://user:password@localhost/gnucash_test')
book = session.book
commod_table = book.get_table()
currency = commod_table.lookup('CURRENCY', 'GBP')
new_customer = Customer(book, "22222", currency, "Test")
session.save()
session.end()
session.destroy()
-----------------------
With the following error (though the customer is inserted, but the
database is left locked):
-----------------------
* 14:44:14 CRIT <gnc.backend.dbi> [mysql_error_fn()] DBI error: 1048:
Column 'currency' cannot be null
* 14:44:14 CRIT <gnc.backend.dbi> [conn_execute_nonselect_statement()]
Error executing SQL INSERT INTO
customers(guid,name,id,notes,active,discount_num,discount_denom,credit_num,credit_denom,currency,tax_override,addr_name,addr_addr1,addr_addr2,addr_addr3,addr_addr4,addr_phone,addr_fax,addr_email,shipaddr_name,shipaddr_addr1,shipaddr_addr2,shipaddr_addr3,shipaddr_addr4,shipaddr_phone,shipaddr_fax,shipaddr_email,terms,tax_included,taxtable)
VALUES('b460bab5be705d67a7a89b1c8ae83509','','22222','',1,0,1,0,1,NULL,0,'','','','','','','','','','','','','','','','',NULL,3,NULL)
* 14:44:14 CRIT <gnc.backend.sql> [gnc_sql_do_db_operation()] SQL
error: INSERT INTO
customers(guid,name,id,notes,active,discount_num,discount_denom,credit_num,credit_denom,currency,tax_override,addr_name,addr_addr1,addr_addr2,addr_addr3,addr_addr4,addr_phone,addr_fax,addr_email,shipaddr_name,shipaddr_addr1,shipaddr_addr2,shipaddr_addr3,shipaddr_addr4,shipaddr_phone,shipaddr_fax,shipaddr_email,terms,tax_included,taxtable)
VALUES('b460bab5be705d67a7a89b1c8ae83509','','22222','',1,0,1,0,1,NULL,0,'','','','','','','','','','','','','','','','',NULL,3,NULL)
* 14:44:14 CRIT <gnc.business> [gncCustomerOnError()] Customer
QofBackend Failure: 12
Table Retrieval Error: 1048: Column 'currency' cannot be null
* 14:44:18 CRIT <gnc.backend.dbi> gnc_dbi_unlock: assertion
`dbi_conn_error( dcon, NULL ) == 0' failed
-----------------------
However when performed on a new database (i.e. using the line session =
Session('mysql://user:password@localhost/gnucash_test_new', is_new=True)
the command runs fine (there are still a few errors, shown below):
-----------------------
* 14:45:11 CRIT <qof> qof_book_is_readonly: assertion `book != NULL' failed
* 14:45:11 CRIT <gnc.business> [gncCustomerOnError()] Customer
QofBackend Failure: 9
* 14:45:11 CRIT <qof> qof_book_is_readonly: assertion `book != NULL' failed
* 14:45:11 CRIT <gnc.business> [gncCustomerOnError()] Customer
QofBackend Failure: 9
* 14:45:11 CRIT <qof> qof_book_is_readonly: assertion `book != NULL' failed
* 14:45:11 CRIT <gnc.business> [gncCustomerOnError()] Customer
QofBackend Failure: 9
-----------------------
I'm new to working with the gnucash python bindings (and python in
general) so any help would be much appreciated.
If you need any further information about my configuration or database
please let me know.
Kind regards,
Tom
More information about the gnucash-user
mailing list