cybermaggedon / gnucash-uk-vat

A bridge between GnuCash and UK HMRC VAT return MTD APIs for automating VAT returns
GNU General Public License v3.0
13 stars 2 forks source link

Exception: module 'gnucash' has no attribute 'SessionOpenMode' #20

Closed scutumelectrum closed 2 years ago

scutumelectrum commented 2 years ago

Hi cybermaggedon, thank you very much for this library!

My setup: -Debian 10 Buster -gnucash/oldstable,now 1:3.4-1+b10 (Version: 3.4, Build ID: 3.4+ (2018-12-30))

I'm trying to get the sandbox test working, and I'm hitting an exception when gnucash-uk-vat is trying to get the session mode: (see accounts_gnucash.py#l42) mode = gnucash.SessionOpenMode.SESSION_READ_ONLY

Exception: module 'gnucash' has no attribute 'SessionOpenMode'

From a different issue (https://github.com/MatzeB/pygnucash/issues/12), I tried a different strategy I imported "gnucash" in interactive shell, and indeed there was no SessionOpenMode object. Saw no enums of similar name either. Doing print(gnucash.__file__) did point me to the lib file, here: /usr/lib/python3/dist-packages/gnucash And grep'ing for SESSION_READ_ONLY, found no matches. Checking the file headers, gnucash_core_c.py is of the Version 3.0.10, and latest copyright date I saw was 2010. So I'm guessing I don't have the right lib, or my gnucash is too old.

Also tried installing pygnucash from pypi, however that lib is completely different (at least the one I have seems to be the right one, but perhaps outdated).

Have you had a similar issue before?

Again, thanks for your efforts (it's amazing to not have to proprietary software for tax).

scutumelectrum commented 2 years ago

Realised the stable version of the package is 4.4. Tried it on a spare machine and it has the correct enums in the python API. Will check on my work machine a little later.

cybermaggedon commented 2 years ago

Thanks for the report @scutumelectrum

The gnucash Python libraries are a bit weird. On Fedora they are packaged with the gnucash package itself. The Python libraries are tightly embedded with the gnucash package libraries, so I don't think they could be released separately. I don't know what Debian does off the top of my head, but I would guess it's the same. Had a quick look, looks like there's a python-gnucash package you can install, I think that must be the one you need.

pygnucash looks like something totally different. Hasn't been updated for 5 years. I don't think that's going to work with gnucash-uk-vat.

If you're stuck trying to get gnucash libraries working, you might try pycash, it has a much simpler architecture and is written in pure Python, works out of the box. To get that to work you would have to export your gnucash books in Sqlite form if they're not in that format already.

scutumelectrum commented 2 years ago

Thanks for the explanation @cybermaggedon

I tried on a Debian 11 machine with stable repo (as opposed to old-stable). Installed gnucash 4.4 and it came with the right API out of the box. Used HMRC's sandbox API and was also able to try out the post-bill feature by uncommenting some of your code. Btw in gnucash-uk-vat line #118 there's a missing await call (although I can see it's still on the experimental side, I just needed to see how you implemented the posting).

Given my other machine is needed for a different project, I'll work the Debian 11 one.

Also applied for production credentials, didn't quite realise how much you need to agree to (I can see why your service is convenient). If you need someone to test your code, I'll be happy to do what I can. Here's my email: andrey@scutumelectrum.co.uk

Again thank you this library and for responding!