Commit Graph
465 Commits
Author SHA1 Message Date
Christopher Lam 6070bac87b [report-utilities.scm] convert account value accumulator to c++ 2026-06-29 10:21:11 +08:00
John Ralls cb6b140805 Merge Oliver Lok Trevor's 'fix-glist-python-bindings' into stable 2026-06-25 17:40:12 -07:00
Noah R 3e98c5d8c8 [engine] Add first-class online_id accessors for Split and Account
Promote the OFX/HBCI online_id to named engine accessors:
  xaccSplitGetOnlineID / SetOnlineID / HasOnlineID
  xaccAccountGetOnlineID / SetOnlineID
The getters return an instance-owned const char* (mirroring
xaccTransGetDocLink / xaccTransGetNotes), so the existing
add_methods_with_prefix auto-wrapper exposes them in the Python bindings
with no .i changes and no %newobject.  They write to the same engine KVP
slot ("online_id") the desktop importer uses, so there is no data or
behavior change.

With the accessors in place the gnc_import_*_online_id wrappers in
import-utilities are redundant, so replace every call site (OFX,
AqBanking, and the generic matcher/backend) with them, delete
import-utilities.cpp, and drop the online_id declarations from
import-utilities.h (its importer preference-key macros are retained).

- The engine getters return an instance-owned const char* instead of a
  g_strdup'd copy, so callers no longer free the result; the affected
  locals are retyped const and their g_free()s dropped.
  hash_account_online_ids() g_strdups before inserting, since its hash
  table owns its keys (g_free key-destructor).
- xaccAccountSetOnlineID(acc, "") clears the slot, matching the OFX
  "delete the online_id" intent (the old wrapper stored an empty string).
- Drop the two unused wrappers: gnc_import_set_trans_online_id (marked
  "Not actually used") and gnc_import_trans_has_online_id (no callers).
- Add xaccSplitGet/SetOnlineID to the Split gmock so test-import-backend
  links without import-utilities.
2026-06-21 16:43:03 -07:00
peter 2d0a3850ae Bug 799767 - POST /accounts route in rest-api example is broken
addAccount was rewritten to accept (name, currency, account_type_id,
parent_account_guid, description, code), validate each field, look up
the parent by GUID, and return gnucash_simple.accountToDict(account).
The route handler was updated to pull the form fields and call it with the
new signature.

README was updated to reflect these changes.
2026-05-25 14:40:50 -05:00
Oliver Lok Trevor 5dea8dfe5c Removed unnecessary list reversal as per code review. Removed stray include. 2026-04-28 17:45:46 -04:00
Oliver Lok Trevor 115ef7f657 Added unit test. 2026-04-28 17:39:32 -04:00
Oliver Lok Trevor b616838ce3 Made GList converter get type from SWIG itself to avoid long string of type-checks. 2026-04-28 17:39:32 -04:00
Oliver Lok Trevor 68eaeaae8b Moved list type conversions for Python to Python-specific binding definition files. 2026-04-28 17:39:32 -04:00
John Ralls bdbc08e0ab Python Bindings: Destroy the QofSession in the Python Session dtor.
Failing to do so can leave a DBI database locked, see
https://github.com/Gnucash/gnucash/pull/2203
2026-04-22 11:28:31 -07:00
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
Christopher Lam 2b7043b4ba [reports] use gnc_date_interval_format 2026-02-13 22:01:48 +08:00
Christopher Lam 47938d1a2c [gnc-date.cpp] gnc_date_interval_format localisable with ICU 2026-02-13 21:58:01 +08:00
John Ralls 79b43fb4f6 Guile: Use the right conversion for size_t. 2026-01-09 16:20:31 -08:00
John Ralls 6dc106ff08 SRFI-64 test-equal no longer considers exceptions equal to #f.
So convert test that raise an exception to test-error with the exception
type.
2025-12-07 13:03:07 -08:00
John Ralls 01f1d75198 Fix missing or incorrect expected exception test failures.
The new SRFI-64 implementation doesn't convert a missing expected
exception nor the symbol 'error to mean any exception. Use #t to mean any
exception.
2025-12-07 13:03:07 -08:00
John Ralls e618b98950 Show the full test result alist on failure if expected value isn't defined.
With the new SRFI-64 implementation tests are failing without setting
expected and actual values on the test result. Dump the test-result-alist
to get more information.
2025-12-07 13:03:07 -08:00
Richard Cohen 647d3b7221 Make a link in the build directory for options.scm 2025-11-09 15:06:17 +00:00
Christopher Lam 001c690a81 [account.cpp] gnc_account_foreach_split forward loops only
because the reverse iteration isn't used at all
2025-11-02 12:28:41 +08:00
Christopher Lam 8846ff4605 [test-engine-extras] add invoice IDs to test invoices 2025-08-24 17:48:57 +08:00
Christopher Lam b0c60fb310 [reports] use ICU for Unicode string comparison 2025-06-17 08:42:02 +08:00
Christopher Lam ff759c26bc [engine.i] convert gnc_account_accumulate_at_dates to c++
traversal of account->splits through std::vector instead of scm_list
2025-05-10 14:33:06 +08:00
Christopher Lam c01cccbddc [gnc-engine-guile.cpp] helper gnc_split_to_scm function 2025-05-10 14:33:06 +08:00
Christopher Lam b219744dba [gnc-engine-guile] reduce overhead of gnc_foo_to_scm
by caching the result of SWIG_TypeQuery(typestr)
2025-05-10 13:59:19 +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 b5b2221e72 Test gnc-option-date variable fy start days.
Leverages the FakePrefsBackend from the previous commit to change the
fiscal year for testing.

Makes now_t a defaulted parameter of gnc_relative_date_to_time64 so
that we can inject different reference dates for testing.
2025-03-23 15:32:07 -07:00
John Ralls 0185a2fec8 Bug 799533 - Saved reports configurations are opening with…
No Accounts selected error
Revert "[gnc-optiondb.i] don't add null accounts"
2025-03-17 16:47:46 -07:00
John Ralls 218aa4ad87 Fix test-gnc-option-scheme-output to match fix for bug 799501. 2025-03-17 16:31:06 -07:00
John Ralls 2f0ed09bf1 Bug 799501 - Gnucash grashes on startup ice-9/read.scm error
Correctly format ("'~s" instead of "'~a") the scheme string returned from
gnc_query2scm.
2025-03-10 14:24:33 -07:00
John Ralls 85084e75d6 Fix python bindings build with Swig-4.3.0. 2024-12-26 11:45:10 -08:00
Christopher Lam 5661c45d2a gnc_commodity_table_get_namespaces must be g_list_freed 2024-11-28 08:23:30 +08:00
David Seifert c06bc18dc4 Add missing #include <cstdint>
* GCC 15 has reduced transitive dependencies between headers.

Bug: https://bugs.gentoo.org/939856
2024-11-02 09:55:15 +01:00
Christopher Lam 6d7f4ec4c8 [engine.i] expose xaccAccountGetSplits in bindings
because xaccAccountGetSplitList will create GList, scan and build SCM
reverse order, and scm_reverse.

xaccAccountGetSplits scans the vector, builds the SCM list in reverse.
2024-10-27 22:22:51 +08:00
Christopher Lam e2f5c74bb4 [engine.i] VECTORREF_HELPER_INOUT to handle SplitsVec& 2024-10-27 22:22:51 +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
Christopher Lam 1718fa0b6e [gnc-pricedb.h] remove unused gnc_pricedb_lookup_at_time64 2024-08-31 20:45:32 +08:00
Christopher Lam 664b1cb77a [gnc-optiondb.i] instead of scm_list_ref, walk the list 2024-07-27 08:39:00 +08:00
Christopher Lam 3e5d6a510b [gnc-optiondb.i] don't add null accounts 2024-07-27 08:38:59 +08:00
John Ralls ad7a51a6ef Merge Chris Lam's 'acc-children-vector' into stable. 2024-06-27 13:21:49 -07:00
Geert Janssens 1def3ce8fd Cleanup - remove deprecated function (re-)defines
They were deprected 11 years ago
2024-06-23 18:23:49 +02:00
Christopher Lam d1807b6c15 [engine.i] move gnc_accounts_and_all_descendants to engine.i 2024-06-07 18:10:40 +08:00
Geert Janssens e8d72ad53f Doxygen - merge separate txt files into respective header files 2024-05-23 15:10:05 +02:00
Geert Janssens 39aa5f9c09 Remove texi design document in engine
It's extremely out of date and we no longer use it to keep track
of our design decisions and suggestions.

Only a section on KVP policy has been move into kvp_doc.txt
as it may make sense there.
2024-05-23 15:10:05 +02:00
Christopher Lam 4c29f69d67 [engine.i] even faster gnc_get_match_commodity_splits
gnc_get_match_commodity_splits needs to scan the account splitlists to
find suitable splits upto end_date. Because splitlist is date-sorted,
use gnc_account_foreach_split_until_date to avoid scanning later
splits.
2024-05-02 22:21:31 +08:00
Christopher Lam 8fb5a6afd6 Fix tests so that they don't fail unnecessarily
- test-begin/test-end names must be consistent
- remove empty test group in test-scm-engine
2024-04-29 22:06:45 +08:00
Christopher Lam 68f60fef68 [engine.i] gnc_get_match_commodity_splits from scheme to c++
The scheme version is very inefficient: (1) it uses QofQuery to
retrieve all splits, and QofQuery is slow. (2) The whole splitlist
typically is thousands splits long needs to be converted from C to
guile via consing and reverse. (3) The scheme list is immediately
filtered to select "interesting" splits only.

This function performs all of the above using Account's efficient
methods, selecting only interesting splits into a GList. This list is
then converted to scheme via cons and reverse.
2024-04-22 19:34:02 +08:00