Hi Allen,

As part of some of the work I've been doing to create a REST like API via the Python bindings I've also been trying to make payments via the Python API.

I think I've managed to find out how this is intended to be done but can't quite get it to work.

The relevant function in the GnuCash core is I believe is gncOwnerApplyPayment. This isn't exposed in the Python bindings, so I add it to the Customer object with (I can provide an example file with this in, but don't have a clean version of the code at the moment):

gnucash.gnucash_business.Customer.add_method('gncOwnerApplyPayment', 'ApplyPayment')

I also use xaccAccountGetLotList (as it's the lots parameter I'm having problems with)

gnucash.gnucash_core.Account.add_method('xaccAccountGetLotList', 'GetLotList')

Then attempt to use the following (please note I've hardcoded the GUIDs used for the accounts:

session = gnucash.Session(arguments[0], ignore_lock=True)

invoice = session.book.InvoiceLookupByID('000001')
customer = invoice.GetOwner()

transaction = invoice.GetPostedTxn()
lot = invoice.GetPostedLot()

account_guid = gnucash.gnucash_core.GUID()
gnucash.gnucash_core.GUIDString('6ab0f12d91e944d00a2ffa0588e252e6', account_guid) # AR

posted_acc = account_guid.AccountLookup(session.book)

account_guid2 = gnucash.gnucash_core.GUID()
gnucash.gnucash_core.GUIDString('1886b76bb07786f2a821356d928ec461', account_guid2) # Liabilities: CC

xfer_acc = account_guid2.AccountLookup(session.book)

customer.ApplyPayment(transaction, posted_acc.GetLotList(), posted_acc, xfer_acc, invoice.GetTotal(), GncNumeric(0), datetime.datetime.strptime('2014-08-11', '%Y-%m-%d'), '', '', False)

Unfortunately this fails with the error:

Traceback (most recent call last):
  File "gnucash_rest.py", line 1622, in <module>
customer.ApplyPayment(transaction, posted_acc.GetLotList(), posted_acc, xfer_acc, invoice.GetTotal(), GncNumeric(0), datetime.datetime.strptime('2014-08-11', '%Y-%m-%d'), '', '', False) File "/usr/local/lib/python2.7/dist-packages/gnucash/function_class.py", line 91, in method_function
    *process_list_convert_to_instance(meth_func_args) )
File "/usr/local/lib/python2.7/dist-packages/gnucash/gnucash_core_c.py", line 2922, in gncOwnerApplyPayment
    return _gnucash_core_c.gncOwnerApplyPayment(*args)
TypeError: in method 'gncOwnerApplyPayment', argument 3 of type 'GList *'

I'm afraid I'm not an expert in either Python, C or SWIG, so I'm not sure what the problem is. I've tried a large number of values for the lots parameter which this is failing on which is a GList in core:

gncOwnerApplyPayment(GncOwner owner, Transaction txn, GList lots, Account posted_acc, Account xfer_acc, gnc_numeric amount,
        gnc_numeric exch, Timespec date, char memo,
        char num, gboolean auto_pay)

So I had assumed this would be a list of lots in Python, but nothing I try seems to work here.

Would anyone with experience in this area be able to lend a hand?

Thanks,

Tom

On 14/11/14 16:01, Allen S. Rout wrote:
On 11/14/2014 10:37 AM, John Ralls wrote:

On Nov 14, 2014, at 5:00 AM, Allen S. Rout <a...@ufl.edu> wrote:


Ah, from your original question it sounded like you wanted to pass
arguments to the command line.

I don't know what you mean by "hooks for payments",

The python includes bindings to make an invoice, make an entry, add the
entry to the invoice, etc.   No similar collection for payments leapt
out at my grep. :)

but it's possible
that the code you want is in the GUI (yeah, we know it doesn't belong
there) which would prevent it being exposed in bindings, or written
in Scheme.

Understood, and I totally get your 'yeah, we know'.  I have deep
sympathy for the fact that you're maintaining, in spare time,  a code
base which does 'X' pretty darn well and reliably, and people like me
are whining that it doesn't do 'Y'.

At the moment it takes me an hour or so to give my club's customer base
their monthly statements.   It takes me about another hour to carefully
type in all their payments.  Barring those two repetitive tasks, GnuCash
is just what the doctor ordered.

I'm now thinking I'll take a shot at translating Stripe payments
downloads into quicken format, so GnuCash can absorb them.   I'd be
pleased to contribute that, if it's something the project would like.


I'll pay my personal out-of-pocket money for someone to make it possible
to tell GnuCash, at some command line, the equivalent of

please export a customer report, for customer [thus], in HTML, to
[thus].html, with all the other options defaulted.

I've tilted at that three different times now, and feel like I've
stopped making progress.


- Allen S. Rout

_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to