After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 638543 - [PATCH] Custom counter formatting and value editing
[PATCH] Custom counter formatting and value editing
Status: RESOLVED INCOMPLETE
Product: GnuCash
Classification: Other
Component: Business
git-master
Other Linux
: Normal minor
: ---
Assigned To: gnucash-core-maint
gnucash-core-maint
Depends on:
Blocks:
 
 
Reported: 2011-01-02 22:52 UTC by Matthijs Kooijman
Modified: 2018-06-29 22:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against r20023: 0001 - Remove the counter() method from the backends. (3.00 KB, patch)
2011-01-02 22:57 UTC, Matthijs Kooijman
committed Details | Review
Patch against r20023: 0002 - Split the qof_book_get_counter function. (6.58 KB, patch)
2011-01-02 22:58 UTC, Matthijs Kooijman
committed Details | Review
Patch against r20023: 0003 - Centralize the counter formatting in qofbook. (15.12 KB, patch)
2011-01-02 22:59 UTC, Matthijs Kooijman
committed Details | Review
Patch against r20023: 0004 - Make the various counter formats configurable. (4.02 KB, patch)
2011-01-02 23:02 UTC, Matthijs Kooijman
committed Details | Review
Patch against r20023: 0005 - Validate counter format strings before using them. (5.83 KB, patch)
2011-01-02 23:03 UTC, Matthijs Kooijman
committed Details | Review
Patch against r20023: 0006 - Add a GUI for the counter format and current value. (10.60 KB, patch)
2011-01-02 23:04 UTC, Matthijs Kooijman
none Details | Review
Patch against r20023: 0006 - Add a GUI for the counter format and current value. (10.62 KB, patch)
2011-01-02 23:30 UTC, Matthijs Kooijman
committed Details | Review

Description Matthijs Kooijman 2011-01-02 22:52:36 UTC
This is a patch series that achieves two things:

 * Allow using custom format strings for counters (to allow a different number of digits or a pre- or postfix to invoice numbers, for example).
 * Allow editing the format strings and the current counter values through the File->Properties GUI.


A couple of remarks regarding the implementation. The first patch removes the "counter" method from the backends. This method was meant for an (atomic?) increment-and-get operation in backends, but since backends could not define "get" and "set" operations in a similar methods, this "counter" method would conflict with this patch series. Since neither the xml and dbi backend implement this method, I've removed it altogether. An alternative would be to implement an addition "get" and "set" method for counters.

One of the patches introduces a function for validating format strings, to prevent (security) problems from invalid printf strings. This validator is a very simple parser that allows a string with a single gint64 format specifier surrounded by a literal pre- and postfix. I've considered using regular expressions for this, but pulling in a regex engine seemed too much to bother and making a special-cased validator manually seemed the easiest way to make this work and be secure.

The last patch is a bit tricky: It defines the GUI components to edit the counter values and formats. This is done by adding a section (tab) to the File -> Properties dialog. However, all of the other options offered in that dialog are saved in the "options"/<section> kvp slot, whereas the counters (and the new counter formats) as well are saved in different kvp slots next to the "options" slot. Since the options machinery is quite generic and also used for report options, there isn't a very clean and obvious way to handle this situation.

I've opted for a slightly ugly solution: Override the scm->kvp and kvp->scm methods on the options to simply ignore the "options"/<section> slot they get passed and just use "counters" or "counters_format" instead. I haven't been able to think of a really better way to handle this that didn't involve significant changes to the options/report framework, and I guess this way should be acceptable...

One alternative to this would be to actually move the counter values into the "options"/"Counters" slot (and then probably use special option naming for the format strings, like "gncInvoice_format") so the counter options can become normal options. I don't suppose this is worth the trouble of the backwards incompatible change (also this would mean this feature would be delayed to at least 2.6...)


I'll attach the patches in a minute, they're in git-format-patch format.
Comment 1 Matthijs Kooijman 2011-01-02 22:57:31 UTC
Created attachment 177377 [details] [review]
Patch against r20023: 0001 - Remove the counter() method from the backends.
Comment 2 Matthijs Kooijman 2011-01-02 22:58:34 UTC
Created attachment 177378 [details] [review]
Patch against r20023: 0002 - Split the qof_book_get_counter function.
Comment 3 Matthijs Kooijman 2011-01-02 22:59:39 UTC
Created attachment 177380 [details] [review]
Patch against r20023: 0003 - Centralize the counter formatting in qofbook.
Comment 4 Matthijs Kooijman 2011-01-02 23:02:24 UTC
Created attachment 177381 [details] [review]
Patch against r20023: 0004 - Make the various counter formats configurable.
Comment 5 Matthijs Kooijman 2011-01-02 23:03:15 UTC
Created attachment 177382 [details] [review]
Patch against r20023: 0005 - Validate counter format strings before using them.
Comment 6 Matthijs Kooijman 2011-01-02 23:04:05 UTC
Created attachment 177383 [details] [review]
Patch against r20023: 0006 - Add a GUI for the counter format and current value.
Comment 7 Matthijs Kooijman 2011-01-02 23:04:35 UTC
That's all six patches in the series. Sorry for the spam, folks... :-)
Comment 8 Matthijs Kooijman 2011-01-02 23:30:19 UTC
Created attachment 177384 [details] [review]
Patch against r20023: 0006 - Add a GUI for the counter format and current value.

W00ps, made a last-minute thinko while cleaning up the patches. I've replaced the 0006 patch with one that does actually work.

I also just realized there is a seventh patch missing: To actually use the validator to check the format strings after they're entered in the GUI (that's why I made the validator actually return useful error messages. While writing this down, I also realized that those error messages should really be made translatable, which they aren't in the current patch.
Comment 9 Christian Stimming 2011-01-03 09:03:10 UTC
Comment on attachment 177380 [details] [review]
Patch against r20023: 0003 - Centralize the counter formatting in qofbook.

This patch#3 might have implications on the python wrappers, but that's acceptable.
Comment 10 Christian Stimming 2011-01-03 09:08:52 UTC
Comment on attachment 177384 [details] [review]
Patch against r20023: 0006 - Add a GUI for the counter format and current value.

This finally makes the (default) invoice ID counter editable from the GUI. Great!
Comment 11 Derek Atkins 2011-01-03 18:25:36 UTC
Review of attachment 177377 [details] [review]:

Removing the counter() method from the backend is a bad idea.  It was put in there in order to allow the backends to provide an atomic counter.  The fact that the SQL backend didn't implement it is arguably a bug; because we're single-user it doesn't matter now.  HOWEVER if we do move to a multi-user system we will DEFINITELY need to have the database create/modify/increment the counter.
Comment 12 Christian Stimming 2011-01-10 21:32:25 UTC
(In reply to comment #11)
> Review of attachment 177377 [details] [review]:
> 
> Removing the counter() method from the backend is a bad idea.  It was put in
> there in order to allow the backends to provide an atomic counter.  The fact
> that the SQL backend didn't implement it is arguably a bug; because we're
> single-user it doesn't matter now.  HOWEVER if we do move to a multi-user
> system we will DEFINITELY need to have the database create/modify/increment the
> counter.

Err... I do not agree. To me, it is enough of an argument that this method hasn't been implemented so far anyway. This is purely a declaration without any implementation, which is useless for us as application project, and can be removed. If we do move to a multi-user system, we will have to modify so many things anyway (and more of the implemented ones instead of the non-implemented ones) that this single part here doesn't have to pay respect to those potential future plans.
Comment 13 Christian Stimming 2011-01-10 21:38:25 UTC
The unimplemented "counter" of the QofBook can very well be implemented again at a later point in time. Until then, it doesn't matter at all whether the field exists but is unused, or it is just directly removed altogether as proposed by Matthijs here. Hence, I'll commit the patch series.
Comment 14 Christian Stimming 2011-01-10 21:39:56 UTC
r20052 - r20057.
Comment 15 Matthijs Kooijman 2011-01-10 22:05:20 UTC
After thinking about Derek's comments for a while last week, I realized he did make a valid point. I agree with Christian that re-adding it would be trivial. However, right now the final patch in this series, that adds the GUI, quite heavily relies on saving the counter values into a kvp. There's already a bit of stretching the (report) options logic to save into a non-standard kvp, but I don't think the current code can handle saving to completely different place in any sane way.

So as Christian says, implementing a proper multi-user system later on will be a lot of work anyway. However, now (re-)adding proper atomically incrementing counters to the dbi backend also needs some (unrelated) substantial refactoring of the options framework, not just making the qof code respect the counter method again (though I'm not sure that that is a problem).

Anyway, good to see this patch series is in. Like I said, I still need to create the final patch to make formats entered in the GUI be validated, I'll just reopen this ticket when I get around to making that patch.
Comment 16 Christian Stimming 2011-01-15 21:09:23 UTC
@Matthijs: Is it correct that the new options for the format don't have a default value? Does that mean by default the counter values cannot be used (because they need a %d as format)? Can you come up with a patch that adds a default value for the format which gives some plain numbers?
Comment 17 John Ralls 2013-09-21 00:17:52 UTC
Christian, does this need attention or can it be closed again?
Comment 18 Christian Stimming 2013-09-21 21:23:50 UTC
Closing this bug report as no further information has been provided. Please feel free to reopen this bug if you can provide the information asked for.
Thanks!
Comment 19 John Ralls 2018-06-29 22:50:44 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=638543. Please update any external references or bookmarks.