sdementen / gnucash-utilities

Set of python scripts to work with GnuCash books
Other
15 stars 3 forks source link

Custom report not found in GnuCash #4

Open alensiljak opened 6 years ago

alensiljak commented 6 years ago

Hi, This is a fantastic concept for custom reports. I've managed to run the gc_report script and generate the .scm file from the report_simple, the first example in the documentation. The config.user gets updated with the path to the .scm. However, there is no report with this name to be found in GnuCash. I'd expect to find the report under Reports menu, Sample and Custom submenu. What am I missing? Cheers

I'm running Python 3.6.3 on Windows 10, GnuCash 2.6.18.

sdementen commented 6 years ago

Yes indeed on the concept :-) it is probably a guile error. You can start gnucash as CLI with the --debug flag and the --log=stdin (look for --help to get the precise syntax) and it will ouput all logs, logs in which you can probably find the error

sdementen commented 6 years ago

however, I am thinking about redesigning the report generation logic to spawn a simple web server in Flask/python that the guile/scheme code would call using the new web client modules (https://www.gnu.org/software/guile/manual/html_node/Web-Client.html). This would allow much easier debugging of the python code and faster run (as today, a new python interpreter is spawned each time a report is refreshed ... so if it imports pandas it can lag a bit). I keep you posted

alensiljak commented 6 years ago

Sounds great! Thanks. And, in the meantime, I'll be writing some experiments with ideas that I have, here. Eventually, some items might end up being worth including in the underlying libraries.

sdementen commented 6 years ago

btw, piecash also works on android :-)

alensiljak commented 6 years ago

Yes, one thing I'm looking foward to testing! What do you use to run it? QPython? I installed it (late) last night but still need some working scripts to try it out. :)

sdementen commented 6 years ago

I started writing a gnucash kivy app so I used the python needed to run kivy (I do not remember well which it is)

alensiljak commented 6 years ago

Unfortunately, nothing happens if I run gnucash.exe --help. Need to find a way to run the reports without GnuCash, I guess.

sdementen commented 6 years ago

are you on windows ?

alensiljak commented 6 years ago

Yep. v2.6.18

sdementen commented 6 years ago

the you need to add a log.conf file in you .gnucash folder with something like

[levels]
gnc = debug

gnc.bin = debug
gnc.gui = debug
gnc.backend.file = debug

gnc.engine.sx = debug
gnc.app - util.sx = debug
gnc.backend.file.sx = debug
gnc.gui.sx = debug
gnc.gui.frequency = debug

GLib = error

[output]
to = C:\a-path-for-your-logs\mylog.gnucash
alensiljak commented 6 years ago

:( No reaction whatsoever. I do see a few trace files in my temp folder, though. They only have an odd warning or two from the previous days. Nothing significant in there.

sdementen commented 6 years ago

If you look at the file specified in the last line of you log.conf, nothing appears ?

alensiljak commented 6 years ago

The file doesn't even get created, unfortunately. I put it in c:\temp but it never appears after I run gnucash either with or without --help.

alensiljak commented 6 years ago

I'll try log.conf, as per this :)

sdementen commented 6 years ago

And if you use to = stdout ?

alensiljak commented 6 years ago

Nothing at all, with different combinations of log.conf file name, outputs, or gnucash parameters.

sdementen commented 6 years ago

A post in the gnucash mailing list ?

Sent from my Samsung Galaxy smartphone.

-------- Original message -------- From: Alen Siljak notifications@github.com Date: 11/16/17 09:21 (GMT+01:00) To: sdementen/gnucash-utilities gnucash-utilities@noreply.github.com Cc: "de Menten Sébastien (Electrabel)" sebastien.dementen@engie.com, Comment comment@noreply.github.com Subject: Re: [sdementen/gnucash-utilities] Custom report not found in GnuCash (#4)

Nothing at all, with different combinations of log.conf file name, outputs, or gnucash parameters.

- You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/sdementen/gnucash-utilities/issues/4#issuecomment-344848659, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABPpdormR15U2yW0rShOj-eZMWUZD9WJks5s2_B_gaJpZM4QbBAC. ENGIE Mail Disclaimer: http://www.engie.com/disclaimer/

alensiljak commented 6 years ago

I'll try to search for something first and then join the list. Thanks!

alensiljak commented 6 years ago

I wonder if it works for you, since they say

In the GnuCash application, all error messages are redirected to a trace file. There will be one trace file for each time GnuCash is run. For a user named "myname" these files are located in the folder

c:\Documents and Settings\myname\Local Settings\Temp (Windows XP) or
C:\Users\myname\AppData\Local\Temp (Windows Vista/7).

They are named

gnucash.trace.ABCDEF (GnuCash 2.2.9 and older) or
gnucash.trace.ABCDEF.log (GnuCash 2.4.0 and newer)

where the ABCDEF part is changed randomly on each start of gnucash. See also Tracefile.

If you experience crashes or unexpected behavior, check the latest of these files (or the one created when the problem started) and add all interesting-looking lines of that file to your error reports, at least the lines with the keywords WARNing and CRITical warning.

sdementen commented 6 years ago

yes, I get files generated of the form C:\a-path-for-your-logs\mylog.gnucash.GFDGER (with "a-path-for-your-logs" pointing to my .gnucash folder)

alensiljak commented 6 years ago

ok, then it is possible that I have those already. As mentioned in that Windows page, there is a bunch of trace files in my temp folder. Containing stuff like

* 10:30:05  CRIT <GLib> g_utf8_to_utf16: assertion 'str != NULL' failed
* 10:30:05  WARN <gnc.backend.dbi> [gnc_dbi_unlock()] There was no lock entry in the Lock table
* 10:30:08  WARN <gnc.scm> In C:\Program Files (x86)\gnucash\share\gnucash/scm/report.scm:
 727: 15* (set! doc (if template (let* (# # # ...) (if # # ...) ...) ...))
 727: 16* (if template (let* (# # # ...) (if # # ...) ...) ...)
 728: 17  (let* (# # # #) (if # # #) (gnc:report-set-ctext! report html) ...)
 730: 18* [cash-flow-renderer #]
In unknown file:
   ?: 19  (letrec ((get-option (lambda # #))) (gnc:report-starting reportname) ...)
In C:\Program Files (x86)\gnucash\share\gnucash/scm/gnucash/report/standard-reports/cash-flow.scm:
 127: 20  (let* (# # # ...) (gnc:html-document-set-title! doc #) ...)
 181: 21* (if (not (null? accounts)) (let* (# # # ...) (letrec # #)) ...)
 183: 22  (let* (# # # # ...) (letrec # #))

However, nothing from today, for example.

sdementen commented 6 years ago

yes, that's the file! did you restart gnucash today ?

alensiljak commented 6 years ago

Yes, I close it every time. My sessions are pretty short. There's about 5-6 trace files for today but the length is 0. I will try again later. gc_report also does not generate anything. This is a different machine, though, so I'll try to debug when I have some spare time.

alensiljak commented 6 years ago

ok, back in action. Only when I call gc_report from a debugger, from a git repo, does it generate the .scm files. The regular one, installed through pip, does not do anything. Could be something with permissions on Windows 10(?).

However, even though now there are .scm files in my profile directory and in user.config, they are not visible in GnuCash and there is absolutely nothing in the trace files. :'( Not a good start.

sdementen commented 6 years ago

yes, the pip package is not yet updated! always use the git ...

alensiljak commented 6 years ago

yes, this brings me to the question - how do I test the dev version of the code? Should I uninstall the gnucash-utilities package with pip first? Because, when I run gc_report, it still uses the config.py from the installed package, not from the repo. That's what I understand, at least.

sdementen commented 6 years ago

have a look at https://stackoverflow.com/questions/30306099/pip-install-editable-vs-python-setup-py-develop (and do this from your git repo after uninstalling the official pip package) (I am in a hurry so can't take more time now)

alensiljak commented 6 years ago

That's awesome! Thanks. Editable installs

alensiljak commented 6 years ago

Yeah, finally:

* 21:50:59  WARN <gnc.app-utils> Function: open-file, system-error

<unnamed port>: In procedure open-file in expression (primitive-load name):
<unnamed port>: Invalid argument: "C:\\Users\\alen_\\.gnucash\\report_simple\x0deport_simple.scm"
In unknown file:
   ?: 0* [primitive-load "C:\\Users\\alen_\\.gnucash\\report_simple\x0deport_simple.scm"]

The reason is one backslash in the report path (load (gnc-build-dotgnucash-path "report_simple\report_simple.scm")), when it should be (load (gnc-build-dotgnucash-path "report_simple\\report_simple.scm")). I'm not even sure why you decided to put the reports into a subdirectory. All the documentation assumes that the work is done directly in the .gnucash directory. In any case, it's a simple fix.

So, finally I have some output in GnuCash even if it is a blank page! I guess that most of the scripts I'm doing in gnucash-portfolio would end up being run as reports.

alensiljak commented 6 years ago

I'm not sure what is the best way to fix it since the path is generated using os utils and is correct for direct use in file paths. But, once it needs to be stored in .scm, it requires double slash for the file separator.

sdementen commented 6 years ago

maybe changing lines_report.append('(load (gnc-build-dotgnucash-path "scm_name}"))'.format(scm_name=os.path.join(name, scm_name))) to lines_report.append('(load (gnc-build-dotgnucash-path {scm_name}))'.format(scm_name=repr(os.path.join(name, scm_name))))

sdementen commented 6 years ago

I build also nice reports that shows the KVP structure stored in a gnucash book (for debugging purposes)

alensiljak commented 6 years ago

That was a good try. However, it generates the double backslash separator (load (gnc-build-dotgnucash-path 'report_simple\\report_simple.scm')) and, in turn,

* 23:08:12  WARN <gnc.app-utils> Function: SWIG_Guile_scm2newstr, wrong-type-arg

<unnamed port>:4:7: In procedure SWIG_Guile_scm2newstr in expression (gnc-build-dotgnucash-path (quote report_simple\\report_simple.scm')):
<unnamed port>:4:7: Wrong type argument in position 1: report_simple\\report_simple.scm'
In current input:
   4: 0* [load-module ...
   4: 1*  [gnc-build-dotgnucash-path report_simple\\report_simple.scm']

Any other ideas? This is the first I'm seriously using Python so consider me a newbie here.

alensiljak commented 6 years ago

Hm, now it doesn't work whatever I put there for the path. But at least I figured out that I have to exit GnuCash with Ctrl+Q in order to exit cleanly. Then I get decent trace files. Closing on X crashes it somehow and the logs never get flushed. The lock is also not removed from the database in that case.

alensiljak commented 6 years ago

Now the reason is the quotes. The only accepted option is with double-quotes only. Either double slash or double backslash will work for separator, it seems. (load (gnc-build-dotgnucash-path "report_simple\\report_simple.scm"))

It seems that repr is not a solution. (See this)

alensiljak commented 6 years ago

Any reason why this would not work?

report_path = name + "//" + scm_name
lines_report.append('(load (gnc-build-dotgnucash-path "{scm_name}"))'.format(scm_name=report_path))
alensiljak commented 6 years ago

6 Fixes this by correcting the path to the .scm file.