481 Commits
Author SHA1 Message Date
Ryan Duguid 9b9cec4223 Use SetDatePostedSecs in the REST example transaction setters
SetDatePostedTS no longer exists in the Python bindings. SetDatePostedSecs
accepts the datetime parsed from the request.
2026-10-19 18:04:29 +11:00
Ryan Duguid e319713a12 Handle missing void time in REST transaction serialisation 2026-10-19 18:04:28 +11:00
Ryan Duguid 64334caa90 Fix transaction listing serializer arguments 2026-10-19 18:04:27 +11:00
Christopher Lam 887dfcaad6 [gnc-ui-util.cpp] remove number_to_words (double,int64_t) 2026-10-09 07:29:01 +08:00
John Ralls 7755418cb8 Merge Chris Lam's 'acc-templated-split-iterator' into stable. 2026-09-26 11:19:33 -07:00
John Ralls d8f0e151a7 engine.i: Fix typo. 2026-09-26 09:04:12 -07:00
Christopher Lam 5ed56e2b3d [engine.i] use gnc_account_foreach_split_between_dates
avoids calling callback on splits before start_date
2026-09-26 23:18:59 +08:00
John Ralls 3cf1352cbb Merge Noah Noerr's 'python-guard-price-set-source-string' into stable. 2026-09-25 16:10:42 -07:00
Noerr 0dc41c1212 [bindings/python] Deprecate set_source_string; remove it from the Guile bindings
gnc_price_set_source_string maps a source string to the PriceSource enum and
silently leaves the source unchanged for anything it doesn't recognize -- a
silent no-op a naive Python or Guile script can hit. Steer callers to
set_source() with a PriceSource member (added in #2317) instead.

Python bindings:
- Deprecate GncPrice.set_source_string(): it now emits a DeprecationWarning
  pointing at set_source(PriceSource.<...>). It still works during the
  deprecation period and still guards -- if the string is not recognized (the
  round-tripped source no longer equals the input) it raises ValueError rather
  than silently doing nothing.
- Fix the deprecated() decorator in deprecation.py: it referenced the undefined
  DeprecationWarnig and inspect.current_frame(), so it raised instead of
  warning (the one existing @deprecated use was latently broken).

Guile bindings:
- mark gnc-price-set-source-string deprecated in engine.i.
  (Python and Guile use separate SWIG interface files, so Python is
  handled separately). The only in-tree Guile caller is the QIF importer, updated to
  gnc-price-set-source with PRICE-SOURCE-USER-PRICE; the redundant
  set-source-string in test-engine-extras.scm's fixture helper is dropped.

Tests (test_price_and_wrapping.py):
- TestSetSourceStringGuard covers the guard (still raises on an unrecognized
  string) and the new DeprecationWarning.

Removing set_source_string from the Python bindings is a follow-up.
2026-09-25 16:05:19 -07:00
Noerr 89448ffd34 [bindings/python] Fix and modernize the price example scripts (Bug 799796)
PR #2187 made GncPrice.get_value() return a GncNumeric wrapper and clone() a
fully wrapped GncPrice. The price example scripts still used the pre-5.15 raw
_gnc_numeric idiom and broke -- reported as Bug 799796 (cloned prices silently
kept the original value).

Example scripts (bindings/python/example_scripts/):

* quotes_historic.py -- reworked to the modern idiom; it now actually runs on
  5.x (it had further latent breakage beyond the reported one):
  - Construct each price directly with GncPrice(book) + setters instead of
    cloning an existing price, so the script no longer needs a pre-existing
    price in the book. Look the pricing currency (USD) up from the commodity
    table rather than deriving it from a split.
  - Build the value with the double->GncNumeric constructor at GnuCash's
    standard price precision -- the pricing currency's SCU * COMMODITY_DENOM_MULT
    rounded HALF_UP (gnc-pricedb.h "Price policy") -- dropping the
    Fraction.from_float().limit_denominator(100000) dance and its import.
  - Set the source with the PriceSource enum -- set_source(PriceSource.FINANCE_QUOTE)
    (the enum added in #2317). The original set_source("Finance::Quotes::Historic")
    passed a string to what has been an enum setter since 2.6, which raises
    TypeError on modern bindings.
  - Open with Session(url), which defaults to SESSION_NORMAL_OPEN. The old
    Session(url, True, False, False) passed the deprecated ignore_lock=True,
    silently bypassing the book's lock file.

* priceDB_test.py, price_database_example.py -- num/denom are methods now, so
  read v.num() / v.denom().

Prevent silent recurrence (gnucash_core.py):
The write path failed *silently*, which is how this slipped through review and
CI. num/denom are read-only accessor methods, so assigning to them merely
shadows the method and changes nothing. Add a GncNumeric.__setattr__ that raises
AttributeError on assignment to num/denom, pointing at the correct idiom
GncNumeric(num, denom).

Test (bindings/python/tests/test_numeric.py):
New test_num_denom_read_only covering the guard. It needs no backend, so it runs
in the existing python-bindings CTest on all platforms.

The wiki page Stocks/get_prices, which the reporter copied from, is being
updated separately.
2026-09-24 22:08:37 -07:00
Noerr f21fec06be [bindings/python] Add a PriceSource enum for gnc_price_set_source()
Setting a price's source from Python meant reaching into gnucash_core_c for the
raw PRICE_SOURCE_* constants. Add a PriceSource(IntEnum) alongside SessionOpenMode,
with values sourced from the C enum (via gnucash_core_c) so they can't drift, so a
script can write price.set_source(PriceSource.FINANCE_QUOTE) with a plain top-level
import.

Add test_price_and_wrapping.TestPriceSourceEnum:
 - test_values_match_c_enum asserts the Python enum covers the C PRICE_SOURCE_*
   value set exactly, so adding, removing, or renumbering a C value fails CI until
   PriceSource is updated to match. (Member names are a Python-side choice --
   FINANCE_QUOTE spells out FQ -- so the check is on values.)
 - test_set_source_accepts_enum confirms a member flows through set_source() and
   round-trips.
2026-09-24 00:41:54 -07:00
Christopher Lam c8317b15a0 [test-scm-utilities.scm] addendum last commit "quote" now sanitized 2026-09-24 09:28:36 +08:00
Christopher Lam 0cbce35a47 [engine.i] delegate gnc:html-string-sanitize to g_markup_escape_text 2026-09-24 08:25:18 +08:00
John Ralls 4b5c0d0218 Merge Jitka Plesnikova's 'swig-4.5' into stable. 2026-08-08 17:15:09 -07:00
Gwyn Ciesla 17bb7f9e3f Replace removed Python 2 C API macros for SWIG 4.5.0 compatibility
Author: Jitka Plesnikova <jplesnik@redhat.com>
2026-08-08 17:09:54 -07:00
John Ralls fd43b2935d Guile Bindings: Fix error in GncOptionDB::foreach_section wrapper
By ignoring the function. It won't work with scheme even if it did
compile.
2026-08-08 17:01:11 -07:00
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