gnc_start_of_week
* ICU has a mature C++ api, so prefer that one in our C++ code
* Use PERR instead of fprintf for consistent reporting
* Add the ICU specific linker flags to the test case
this function creates some business data. moved from test-invoice.scm
without the invoice-specific tests. verified all invoices/bills are
created correctly.
it returns a vector-list of the 8 invoices generated.
Changed MRO smallest-fraction to 100 based on information provided
by the reporter. ISO4217 has moved the MRO to the "Historical Currencies"
list that doesn't include CcyMnrUnits.
this can be used instead of delete-duplicates when the list must also
be sorted.
the main reason for this function will be for the upcoming aging.scm
report which will use it heavily to slice APAR splits into owner list.
This function helps to establish UI link from register split to an
owner's split. It should not be used anywhere else. Its use in reports
will be removed.
It is also unnecessarily complex -- it is called from an AP/AR account
register split, it should have all necessary information via split
metadata. e.g. this function *can* return a split owner if originating
from an Asset/Liability account which settles an invoice, but this
functionality is not used because there is no asset/liability register
hook to call it.
There are more, but these are most common ones.
There are also a number of urls that don't behave well when https, so those are skipped
At some point I have also started marking non-working URLs as [DEAD LINK], though
that's not a full coverage.
fixing a 17 year old bug.
previous version had defined (save-acc list count) and (save-item list
count) thereby overwriting the inbuilt 'list' keyword, and tried to use
the it later on with (list key)... best rewrite with neater code.
This version is available for all supported platforms and distros
(CentOS can have a version via EPEL, which is required anyway)
Advantages:
- one cmake version for all platforms
- we can drop all conditions based on cmake version
In the Preferences/Accounting Period, there is an option to specify
absolute dates but the end date was being set to start of day instead
of end of day, changed this.
crash when involving foreign currency stocks.
Scheme's inexact->exact function just converts the floating-point
representation of a number into an exact rational (documented in the
API Reference, Simple Generic Data Types, Numerical data types, Exact
and Inexact Numbers), which isn't what we want.
We want the number converted to exact directly from the string and to do
that we have gnc-fq-helper preface it with #e.
And in Windows only with the value from the environment if there is one.
Calling it with "" in Windows ignores the environment and sets it to the
system settings.
Ensure that all includes of swig-runtime.h are *followed* by
including guile-mappings.h so that the defines masking
scm_to_utf8_string and scm_from_utf8_string are undone.
When you have multiple loggers enabled, the log file indentations are
partly based on logger name length and so you can have false
indentations which can cause confusion. This change gets the maximum
name logger length and uses this for all with a minimum default length
of 12 characters.
Caused by the introduction of caching used in gnc_pricedb_nth_price,
when prices were deleted, the cached list was never updated and so the
tree model could reference a deleted price and hence crash. This also
affected adding prices as the new prices would not show due to the
cache not being updated. To fix this a function was added to reset the
cache when prices are updated from the model.
This reverts commit aa53c23239, reversing
changes made to 3c946a8449, because
aa53c23 was based on master and so undid other changes made to maint
since the last merge-to-master.
copied function created by Mark Weaver, core guile dev and augmented
to selectively replace substring indices
This is a much more efficient function than the previous
gnc:substring-replace which will constantly split lists using
substring, and create new strings using string-append.
It also does tail call optimization properly, unlike the previous
functions.
https://lists.gnu.org/archive/html/guile-devel/2013-09/msg00029.html -
original
"Here's an implementation that does this benchmark about 80 times
faster on my machine: (20 milliseconds vs 1.69 seconds)
--8<---------------cut here---------------start------------->8---
(define* (string-replace-substring s substr replacement
#:optional
(start 0)
(end (string-length s)))
(let ((substr-length (string-length substr)))
(if (zero? substr-length)
(error "string-replace-substring: empty substr")
(let loop ((start start)
(pieces (list (substring s 0 start))))
(let ((idx (string-contains s substr start end)))
(if idx
(loop (+ idx substr-length)
(cons* replacement
(substring s start idx)
pieces))
(string-concatenate-reverse (cons (substring s start)
pieces))))))))
--8<---------------cut here---------------end--------------->8---
The reason this is so much faster is because it avoids needless
generation of intermediate strings."
Add tests for libgnucash/scm/utilities.scm functions
- tests for list<->vec
- tests for gnc:substring-replace
- tests for gnc:substring-replace-from-to
The latter confirms that the comment before the function definition
is *incorrect* - it describes that substring-replace-from-to will
start from the 2nd substring for the first substitution, and
performs 2 substitutions. However the comment illustrates only 1
substitution. The test suite performs the test according to code
behaviour, rather than the comment. This issue is moot in practice
because the end-after is always called with negative in the code
base.
original comment:
;; gnc:substring-replace-from-to
;; same as gnc:substring-replace extended by:
;; start: from which occurrence onwards the replacement shall start
;; end-after: max. number times the replacement should executed
;;
;; Example: (gnc:substring-replace-from-to "foobarfoobarfoobar" "bar" "xyz" 2 2)
;; returns "foobarfooxyzfoobar".
When testing for a MS Windows path which has a ":", a gvfs path with the
format '/run/user/1000/gvfs/smb-share:server=192.168.1.11,share=public/
test-xml-file.gnucash' is recognised as a Windows path. To avoid this
expand the test to ":/" and also ":\"
On Windows boost::filesystem::path's string() produces a string
that goes out of scope with the function in which it's called, so
returning its c_str() ptr yields freed memory, usually full of garbage.
This has an interesting side effect in gnc-file.c's check_file_path():
Since the memory is freed, g_path_get_dirname() reuses it after an
iteration or two, writing its result into the same address. The
following strcmp naturally returns 0 because it's comparing two
instances of the same ptr, so check_file_path falsely reports that
the proposed save path is in GNC_USERDATA_DIR.
Windows file uri's can be of the form 'file:///N:/bob.txt' so change
the gnc_uri_get_components to remove a left over '/' at the start so
gnc_resolve_file_path gets the absolute path correctly. Also change
gnc_uri_create_uri to add an extra '/' for Windows file uri's.
Add function to create an absolute file path from a prefix path and a
relative one. If the prefix is null, then the root directory of the
current path is used.
If the original date is an end-of-month date, we take it as an
indicator they always want monthdelta dates to be end-of-months.
This works for monthly/quarterly/halfyearly/annual.
Addendum to commit 65bfeaf5de which was
deemed to be an incomplete fix.
Also I'd forgotten to activate a test in test-date-utilities. Enable it.
this will modify a test which was calibrated to record purchase price
only. fix transaction creation to add prices for both purchase and
sales, and also fix test which was assuming no sale price was bring
recorded.
This is the general case for any transaction creation. Rewrite other
transaction creation routines to use it. All tests still work
unchanged, which confirms this function works well.
This will allow tests to create multisplit transactions, of an
arbitrary number of splits. If the list-of-split's values are not
balanced (i.e. total 0), the engine will create an Imbalance-CUR
split.
The motivation is to allow creation of complex multisplit
multicommodity transactions eg USD50 + GBP20 (USD25) = EUR66 (USD75)
as well as their prices GBP/USD = 25/20 and EUR/USD = 75/66.
* USD -50
* USD -25 = GBP -20
* USD +75 = EUR +66
This will be useful in creating tests for stock-based reports, whereby
stock sales need splits in STOCK/ASSET/INCOME accounts.
the option lookup mechanism will dynamically translate option
names. warn the user if this takes place so that the report writer may
use new option names.
Use the Scheme rationalize method to convert the decimal numbers
from Finance::Quote to ratinal numbers. This avoids rediculous
precision like 8515625000000001/3906250000000000 for 2.18.
If a saved-report with e.g. relative date, multichoice option is
unknown, the report would crash, and the Report-Options would
segfault. This commit fixes both: report-date defaults to 'today',
multichoice-options defaults to default-value.
Following this commit, if a report loads a saved-report or .gcm from a
future version, a gnc:warn will be emitted and the report will not
crash; it will use relative-date today. Multichoice will remain the
default value. Report Options will not segfault.
The user will be notified via a gnc:gui-warn dialog
gnc:gui-[warn|error|msg] are new global functions.
By default they mirror gnc:warn/error/msg. However then gnome is
available, they will display appropriate warn/error/info dialog in
addition to outputting to console.
Instead of recursing the date, we calculate the next month using an
index-based multiplier, and apply modulo/remainder as appropriate to
determine the next month/year.
Then we attempt to create new mktime, and if the resulting mktime's
month is not as expected, reduce the mday by 1 until resulting month
is correct. This fixes monthly intervals for end-of-month days.
Test via monthly/quarterly deltas, and also includes leapyear
calculation.
Revert using boost::locale to generate std::locales as boost::locale-
generated locales don't implement std::locale::facet and there was
a bug in the boost::locale ICU wrapper code that caused the wrong year
to be output for the last 3 days of December.
GCC's libstdc++ supports only the "C" locale on Windows and throws if
one attempts to create any other kind. For dates we work around this
by using wstrftime() to format according to locale and then convert
the UTF16 string to UTF8. wstrftime() interprets the time zone flags
%z, %Z, and %ZP differently so we process those first before calling
strftime. This will have the unfortunate effect of not localizing
timezone names but it's as close as we can get.
Use built-in glib functions to retrieve the list of per-currency price
lists, concatenate them into a single list, instead of doing it all in
hand-rolled loops.
Sorting is preformed by the calling GncTreeViewPrice so this removes
sorting from gnc_pricedb_nth_price.
There's no concurrency concern because gnc_pricedb_nth_price is a
GUI callback and so must run in the GUI thread.
It seems that std::locales created by boost::locale::generator are
not entirely compatible: If used to create a new locale with a facet
for boost::date_time one ends up with the C locale and the facet.
For the time being avoid the problem by using boost::locale to format
dates and times. std::chrono gets calendar functions in C++20 so we
can switch date-time backends once we can adopt it.
We can't use std::locale::global because all streams imbue it by
default and if it's not 'C' (aka std::locale::classic) then we
must imbue all the streams that we don't want localized, and that's
most of them.
Provides error checking for setting the C++ locale from the environment.
This is necessary both because the environment might have an invalid
locale, which would cause an unhandled exception crash.
On windows std::locale("") can't handle some Microsoft-style locale
strings (e.g. Spanish_Spain) so we use boost::locale's gen("") function
to set the locale--though even that can't handle a Microsoft-style
locale string with an appended charset (e.g. Spanish_Spain.1252) and
that's what glibc's setlocale(LC_ALL, NULL) emits.
Testing notes: Based on the averages of 3 runs, the net
user CPU to save the XML file I use is:
10.2 seconds without this change
7.6 seconds with this change
In my environment the first call to the format routine
in question, the call that sets the cache value, is at
the end of the XML load.
The refactoring provides roughly 10% reduction in user CPU
use for XML file load by moving an expensive function
to within an if-clause where the result is used. The diff looks
like a full re-write but only the if statements, indenting,
and commentary changed.
This value is queried on each comparison of split or txn sort function,
which means it is called quite a lot. Avoiding the KVP lookup of this
property gains a lot in terms of CPU cycles.
Because of https://sourceforge.net/p/libdbi-drivers/bugs/24.
This issue causes trouble in save_may_clobber_data() as well, so
work around it by using a SQL query instead of dbi_conn_get_table_list.
Until now GNC_CONFIG_HOME was more or less hard-coded.
Now it can be set via environment variable GNC_CONFIG_HOME.
In addition it will automatically be created to avoid potential
user confusion.
when moving entry between accounts
When using the cut transaction option the 'associated file' value was
not being pasted to the new transaction. Added scheme code to get this
value and save it to new transaction when using 'cut/copy' and then
'paste' operations. When using the duplicate option, a dialogue allows
you to keep the copied association or not. It does not get copied for
autocomplete.
This involves renaming 3 functions:
gnc_uri_get_protocol -> gnc_uri_get_scheme
gnc_uri_is_known_protocol -> gnc_uri_is_known_scheme
gnc_uri_is_file_protocol -> gnc_uri_is_file_scheme
The *_protocol variants are marked as deprecated.
Additionally a number of local variables have been renamed from
protocol to scheme to support this change.