214 Commits
Author SHA1 Message Date
Noah R 859f0839ce [python-bindings] Add Split wrapping fixes, refactor tests for CI
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.
2026-03-06 15:05:30 -08:00
Noah R 556e7b0d70 [python-bindings] Add get_*_price GncNumeric wrapping, double-wrap protection, and tests
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.
2026-03-06 14:18:25 -08:00
Noah R 592b57ddbb [python-bindings] Fix missing return-type wrapping and clean up examples
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.
2026-03-06 12:53:56 -08:00
Noah R e4ec72c97c [python-bindings] Add SWIG typemap compatibility layer for wrapper objects
Add GNC_ACCEPT_WRAPPER macro that generates %typemap(in) entries for
all core engine and business pointer types. These typemaps accept both
raw SWIG pointers (zero-overhead fast path) and ClassFromFunctions
wrapper objects (fallback path that extracts .instance).

This is pure infrastructure for an upcoming change that fixes missing
return-type wrapping in gnucash_core.py. Once methods like
GncPriceDB.nth_price() return proper GncPrice wrapper objects instead
of raw SwigPyObjects, existing code that passes those objects to
gnucash_core_c C functions would break. These typemaps prevent that
breakage: the C functions transparently unwrap the .instance pointer.

Covered types:
  Core: Account, Split, Transaction, GNCLot, gnc_commodity,
        gnc_commodity_namespace, gnc_commodity_table, GNCPrice,
        GNCPriceDB, QofBook, QofSession, GncGUID
  Business: GncCustomer, GncEmployee, GncVendor, GncJob,
            GncAddress, GncBillTerm, GncTaxTable, GncInvoice, GncEntry

GncOwner is excluded — it has its own custom type-dispatching typemaps.
2026-03-06 12:35:35 -08:00
Oliver Lok Trevor 008980c497 Added unit test 2025-04-24 20:02:54 -04:00
Oliver Lok Trevor 479ecc7b2b Fixed GetInvoiceFromTxn to convert to the right type of Python object for a GncInvoice. 2025-04-16 13:28:26 -04:00
John Ralls 85084e75d6 Fix python bindings build with Swig-4.3.0. 2024-12-26 11:45:10 -08:00
John Ralls 6cabb5d884 Revisit Bug 799308.
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.
2024-10-26 17:59:25 -07:00
John Ralls 02e2fa0ead Bug 799308 - sqlite backend: Example Python script prints error...
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.
2024-09-05 11:53:47 -07:00
Geert Janssens e8d72ad53f Doxygen - merge separate txt files into respective header files 2024-05-23 15:10:05 +02:00
John Ralls a3f14759ab Asan: Make leak and ODR violation reporting CMake options.
pass -DLEAKS=ON or -DODR=ON to enable these features. They have an
effect only with CMAKE_BUILD_TYPE=Asan and don't work on Apple because
Apple clang doesn't enable them.
2023-11-25 11:17:14 -08:00
John Ralls 2234fa433e Add Asan build type that enables the Address and UB sanitizers.
Uses generator statements instead of CMAKE_<TYPE>_FLAGS_ASAN to support multiconfig generators like Xcode.
2023-11-02 12:58:46 -07:00
John Ralls 17ebb8a1d2 [simple-business-create.py] Overwrite an existing file instead of crashing. 2023-09-11 17:39:02 -07:00
Christopher Lam 7ce4198c20 rename string_to_gnc_numeric to gnc_numeric_from_string 2023-08-29 08:45:20 +08:00
Geert Janssens 29b7a9099d Fix cmake warnings while searching for python
There is a new find module since cmake 3.12. Cmake 3.27 will start
emitting warnings if the old modules are still in use.

Current implementation supports both. As soon as we can bump our minimal
cmake version to 3.12, the old support code can be dropped as well.
2023-08-17 18:23:33 +02:00
Richard Cohen e43982375c Valgrind: fix "definitely lost" memory in test - sqlite3test
==64824== 171 (88 direct, 83 indirect) bytes in 1 blocks are definitely lost in loss record 392 of 418
==64824==    at 0x4843FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==64824==    by 0x528A935: qof_session_new (qofsession.cpp:148)
==64824==    by 0x141832: main (sqlite3test.c:34)
2023-07-19 10:21:30 +01:00
Richard Cohen 27fe72496e Remove unused ${GLIB_LIBS} ${GLIB_INCLUDE_DIRS}
They have been replaced by GLIB2_*
2023-02-21 12:50:38 +00:00
Richard Cohen 56d950598d [-Wunused-variable] - pretend to use
Looks like a SWIG bug, creating an extra variable that it doesn't use

bindings/python/gnucash_core.c: In function ‘_wrap_xaccAccountGetReconcileLastDate’:
bindings/python/gnucash_core.c:10096:10: warning: unused variable ‘secs20’ [-Wunused-variable]
10096 |   time64 secs20 ;
      |          ^~~~~~
bindings/python/gnucash_core.c: In function ‘_wrap_xaccAccountGetReconcilePostponeDate’:
bindings/python/gnucash_core.c:10298:10: warning: unused variable ‘secs20’ [-Wunused-variable]
10298 |   time64 secs20 ;
      |          ^~~~~~
bindings/python/gnucash_core.c: In function ‘_wrap_qof_query_date_predicate_get_date’:
bindings/python/gnucash_core.c:20237:10: warning: unused variable ‘secs20’ [-Wunused-variable]
20237 |   time64 secs20 ;
      |          ^~~~~~
2023-02-16 09:20:59 +00:00
John Ralls 732a005710 Merge Christoph Holtermann's 'python-log-access' into master. 2023-02-06 15:24:04 -08:00
Christopher Lam 119356752f Merge branch 'maint' 2023-01-30 09:56:13 +08:00
luzpaz 67ab9e90d2 Fix some typos 2023-01-26 13:48:58 +01:00
John Ralls 939a77407c Merge branch 'price-quotes-cpp' 2022-10-14 11:25:14 -07:00
Geert Janssens e97fc3e408 Drop price-quotes.scm, gnc-fq-helper.in and gnc-fq-check.in - no longer used 2022-10-02 11:50:26 -07:00
John Ralls a6e2842ea0 More distcheck fixes. 2022-10-02 09:47:35 -07:00
Christopher Lam 161b07b241 Merge branch 'maint' 2022-09-09 21:23:40 +08:00
luz paz ba94730a23 Fix various typos
Found via `codespell`
2022-09-06 10:44:29 -04:00
Christopher Lam 0b5a4cd298 Merge branch 'maint' 2022-08-03 20:38:08 +08:00
John Ralls 688832b5f8 Bug 798585 - segfault running sample script
The root cause of which is that on recent releases of GLib (recent
meaning 2.66 in the current Debian stable!) g_type_instance_get_private
looks in the wrong place for the private data. When running the script
in question it returned NULL and since the code didn't check for a valid
pointer, it crashed.

So this change replaces all calls to g_type_instance_get_private with
the function [type_prefix]_get_instance_private() added in glib-2.36
except for two register2 files that have been removed from master; those
are ignored to avoid unnecessary merge conflicts.
2022-07-30 16:50:51 -07:00
Christopher Lam f1adb5da34 Merge branch 'TXN_TYPE-is-dynamic' xaccTransGetTxnType into maint #1201 2022-07-18 09:24:32 +08:00
Christopher Lam fd12d3900c [Transaction.c] use heuristics to determine txn->txn_type 2022-07-18 09:24:05 +08:00
John Ralls f4c27d4494 Move gnc_ui_account_get_tax_info_string to gnc-locale-tax.c
To prevent a circular dependency between libgnc-app-utils and
libgnucash-guile.
2022-07-17 10:00:23 -07:00
John Ralls 426b30c37e Fix python tests dependencies
So that ninja check works from a clean build directory with Python enabled.
2022-07-16 16:36:46 -07:00
John Ralls 7d94ade599 [python]Remove non-namespace "All non-currency" fom namespace test. 2022-03-25 15:19:57 -07:00
Christoph Holtermann 6a015c8744 make GncNumeric.invert() return GncNumeric 2022-03-20 20:04:56 +01:00
Christoph Holtermann 567df27cc7 Implement some comparisons and arithmetics for GncNumeric
Derive some numeric comparisons and arithmetics from Fraction
class
https://github.com/python/cpython/blob/3.7/Lib/fractions.py
and general information from
https://docs.python.org/3/library/numbers.html#numbers.Integral

These methods are bound closer to the gnucash-C-api than those
from the fraction class.

This is not the full set of comparisons and arithmetics, needs
to be extended. It would be good to extend tests to cover this.
2022-03-20 20:04:44 +01:00
John Ralls cbfacdcd55 Merge Christoff Holtermann's 'python-qof-example' into maint. 2022-03-08 13:46:07 -08:00
John Ralls d841b322d0 Merge Frank Ellenberger's 'Bug684507' into maint. 2022-03-08 12:39:47 -08:00
Christoph Holtermann 64920e7c70 Small fix in expected result 2022-03-08 10:49:44 +01:00
Christoph Holtermann 07cfe9e45c Missed one redundancy 2022-03-08 10:45:17 +01:00
Christoph Holtermann 395c7a7052 Modify examples to respect previous patch 2022-03-08 10:40:12 +01:00
Christoph Holtermann 62f8acf6ae Provide the complete set of QOF enums in gnucash 2022-03-08 10:33:25 +01:00
Christoph Holtermann 06e17dfd5c Provide wrapper for qof numeric predicate
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.
2022-03-08 09:45:48 +01:00
Christoph Holtermann f44d23035e python qof examples 2022-03-06 23:52:32 +01:00
John Ralls 9ad24321b4 Remove investment-type namespaces.
Leave it to users to categorize their non-currency commodities. In the
QIF importer default non-classifiable commodities to
GNC_COMMODITY_NS_NONCURRENCY.
2022-03-01 19:58:23 -08:00
Frank H. Ellenberger c7f842c081 Bug 684507 - commodity namespace should be localized 2022-03-01 19:58:11 -08:00
John Ralls b8552a8070 Fix python transaction test_date on Ubuntu-81.04.
Python3 there is too old for fromisoformat, use direct construction
instead.
2021-09-10 17:01:38 -07:00
John Ralls fcab298245 Add test for Transaction GetDate() in python bindings.
Pursuant to Bug 798284.
2021-09-10 13:26:59 -07:00
Steven Walter 5f721614ad Remove unneeded .decode() from Invoice*.tex.templ
These values are already str's, don't decode them
2021-08-03 15:59:54 -04:00
Steven Walter 3ed6b4dab9 latex_invoices.py: write takes string not bytes
write() fails if you give it bytes, so don't encode
2021-08-01 22:17:41 -04:00
Steven Walter ba4852a9da latex_invoices.py: use default locale
Don't hardcode a locale.  Empty string means to use the user's locale
(e.g. $LANG)
2021-08-01 22:17:11 -04:00