Add missing gnc_numeric wrapping for two Split methods:
- GetNoclosingBalance → GncNumeric
- GetCapGains → GncNumeric
Refactor test_price_and_wrapping.py to create all test data
programmatically in in-memory sessions, eliminating external data file
dependencies (pricedb1.gml2, sample1.gnucash) and XML backend
requirement. All 27 tests now run unconditionally.
Register tests in CI: add imports to runTests.py.in and add
test_price_and_wrapping.py to CMakeLists.txt dist list.
Wrap GncPriceDB.get_latest_price, get_nearest_price, and
get_nearest_before_price to return GncNumeric instead of raw
_gnc_numeric SWIG proxies.
Add double-wrap safety in ClassFromFunctions.__init__: if a wrapper
object is passed as instance=, unwrap it to the underlying SWIG proxy.
This prevents breakage when callers re-wrap a return value that changed
from a raw SWIG proxy to a wrapper class, e.g.
GncNumeric(instance=pricedb.get_latest_price(...)).
New tests:
TestGetPriceReturnsGncNumeric (4 tests):
get_latest_price, get_nearest_price, get_nearest_before_price
return GncNumeric; arithmetic works on the result.
TestDoubleWrapProtection (4 tests):
GncNumeric, GncCommodity double-wrap; raw SWIG proxy still works.
Many Python binding methods silently returned raw SwigPyObject pointers
instead of proper Python wrapper objects because the methods_return_instance
dicts were incomplete. This adds the missing entries and activates the
DeprecationWarning in the SWIG typemap fallback path from PR 1.
Return-type wrapping fixes (gnucash_core.py):
GncPrice (new dict — no wrapping existed before):
get_commodity → GncCommodity, get_currency → GncCommodity,
clone → GncPrice, get_value → GncNumeric
GncPriceDB (added to existing dict):
nth_price → GncPrice, lookup_day_t64 → GncPrice,
convert_balance_nearest_before_price_t64 → GncNumeric
GncPriceDB (new list wrapping):
lookup_latest_any_currency → list[GncPrice],
lookup_nearest_before_any_currency_t64 → list[GncPrice],
lookup_nearest_in_time_any_currency_t64 → list[GncPrice]
GncCommodity: obtain_twin → GncCommodity,
get_namespace_ds → GncCommodityNamespace
Account: get_currency_or_parent → GncCommodity,
GetLotList → list[GncLot]
GncLot: get_split_list → list[Split]
Example script cleanup:
Remove type(x).__name__ == 'SwigPyObject' workarounds from
gnc_convenience.py, gncinvoicefkt.py, str_methods.py — these are
no longer needed now that methods return proper wrapper objects.
SWIG typemap (gnucash_core.i):
Activate DeprecationWarning on the .instance fallback path, replacing
the TODO placeholder from the typemap compatibility layer commit.
New test file (test_price_and_wrapping.py):
18 tests covering all wrapping fixes and typemap compatibility,
using in-repo test data (pricedb1.gml2, sample1.gnucash).
Tests auto-skip when XML backend is unavailable.
Existing files/databases obviously should still be loaded. What's
changed is that databases no longer need to be loaded to force creation,
they do that on their own.
when creating new file.
Reverts the fix for https://bugs.gnucash.org/show_bug.cgi?id=726891. The
underlying problem, that a new SQL database needed to be loaded to force
its creation, is no longer a problem. It was probably corrected as part
of the C++ rewrite of the SQL backend.
Python bindings already have some wrapping objects for
qof predicates. This adds the one missing for GncNumeric
comparisons.
Additionally fixes a wrong number for QOF_NUMERIC_MATCH_ANY
in example file.
allow keyword arguments for function_class methods
and functions. process_dict_convert_to_instance() is added to
mimic the behavior of the process_list_convert_to_instance()
Derived methods in gnucash_core.py like raise_backend_errors_after_call
get modified to accept being called with keyword args.
Also adds some docstrings.
make gnc_path_get_localedir() and GETTEXT_PACKAGE available for python
to access locales. Import gettext module to provide _ as translator
method. Provide null _-method returning english text in case of missing gettext.
Make a lot of messages translatable by adding _-method. Include python
files to create .pot-files.
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.
The last three commits fix the main part of Bug 796137. An inconvenience
with GSList remains as for the moment qof_query_add_boolean_match only
accepts bytes as parameter and no strings. This still needs to be fixed.
Change all instances of bugzilla.gnome.org to bugs.gnucash.org, reflecting
our migration to a self-hosted bug tracker.
Inform the Translation Project Coordinator at release that this affects
translatable strings and that all message catalogs have been updated.
This switches swig to use python 3 specific features when generating the
bindings, switches the build over to python 3 and makes the neccesary
python 2 to 3 conversions in the bindings and tests.
Using the function gnc_price_create and book as a parameter, it is possible to create the new GncPrice object. This will remove the necessity of cloning the prices from existing ones in Python scripts.
Where possible in the Python SWIG code use the builtin SWIG conversion
code over custom code. This ensures appropriate overflow/type checking.
With this I have enabled GncNumeric from longs and tested for correct
overflow handling.
Note: This could be extended to GUILE but I am not familiar enought to
safely enable this.
At current the Python GncNumeric has issues with type conversion eg.
* GncNumeric(1.3) = 1.00
* GncNumeric("1.3") is OK but any future methods error
This behaviour was relied on for the Account tests to pass as it used
GncNumeric(0.5) == GncNumeric(1.0) but this is not what many users would
expect.
This fix alows GncNumeric to be constructed from a (int, int)
numerator/denominator pair or int/float/str where double_to_gnc_numeric
and string_to_gnc_numeric from C is used.