Commit Graph
65 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
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
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
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
John Ralls 17ebb8a1d2 [simple-business-create.py] Overwrite an existing file instead of crashing. 2023-09-11 17:39:02 -07: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
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
luz paz ba94730a23 Fix various typos
Found via `codespell`
2022-09-06 10:44:29 -04: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
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 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
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
Steven Walter ad3895fa07 latex_invoices.py: don't decode() a str
These functions all return str's not bytes.  Therefore there is no need
to decode them.
2021-08-01 22:16:33 -04:00
luz paz 95f8884892 Fix misc. typos in comments 2021-06-29 08:46:34 +02:00
koldavi 506fd57989 Fix to_string_with_decimal_point_placed
>>> nominator='123456'
A digit is missing in the string returned from to_string_with_decimal_point_placed. The -1 error.
>>> point_place=2
>>> nominator[:-point_place - 1], nominator[-point_place:]
('123', '56')
2021-04-01 13:26:15 +02:00
Hong Xu e0e77ca39d Add Python example export_account_totals.py
This example exports acount totals of all accounts into a CSV file.

This has been asked before: https://money.stackexchange.com/questions/111786/exporting-account-totals-in-gnucash
2020-08-01 14:47:33 -07:00
c-holtermann 0434acbe10 reformat two python example scripts with black
use black python code formatter on latex_invoices.py and gncinvoice_jinja.py
2020-06-21 16:23:32 +02:00
c-holtermann ee77b713c2 update example scripts to SessionOpenMode 2020-06-21 16:23:32 +02:00
andygoblins 08af4ce9bd context manager examples 2020-02-29 17:46:01 -06:00
andygoblins f1f450cedc make Session a context manager 2020-02-29 17:46:01 -06:00
Geert Janssens df1f033f41 bindings-python - drop references to gnucash-env
We no longer ship a gnucash-env script, directly use python(3) instead
2019-11-30 13:20:08 +01:00
Andrey Legayev 34c14b44a9 Remove not needed semicolons in Python bindings 2019-11-29 18:32:50 +02:00
luz.paz 65bb60d621 Fix typos for gnuchash/ doc/ bindings/ and misc.
Typos found via `codespell -q 3 -D ~/Projects/codespell/codespell_lib/data/dictionary.txt -S *.po,./po,*.min.js,./ChangeLog*,./NEWS,./doc/README*,./AUTHORS,./libgnucash/tax/us/txf-de*,./data/accounts -L ans,cas,dragable,gae,iff,iif,mut,nd,numer,startd,stoll`
2019-09-13 20:26:03 -04:00
Geert Janssens 15a35e6a3b Housekeeping - replace plenty of http links with https
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.
2019-06-06 15:52:30 +02:00
John Ralls fc355958b8 Merge Christoph Holtermann's 'PR-python2to3-rest-api' into maint. 2019-04-14 14:27:53 -07:00
John Ralls 8823f7283f Merge Christoph Holtermann's 'PR-python2to3' into maint. 2019-04-14 14:24:16 -07:00
c-holtermann c779bcb72f GetOwner may return project instead of owner 2019-04-04 17:56:42 +02:00
c-holtermann 6925ee3115 be prepared for GetDateDue returning null 2019-04-04 17:56:31 +02:00
c-holtermann 876079f8d2 remove TS suffix 2019-04-04 17:56:24 +02:00
c-holtermann 6eae440534 GetDate return unserializable datetime object 2019-04-04 17:56:16 +02:00
c-holtermann b73be1b523 GetInvTaxTable returns unserializable object 2019-04-04 17:56:06 +02:00
c-holtermann b06801185c shebang should be specific to python version (PEP394)
preferred form is #!/usr/bin/env python3 as gnucash now only works with
python3
2019-04-04 17:48:42 +02:00
c-holtermann e7d940ac3f iteritems removed in python3 2019-04-04 17:48:10 +02:00
c-holtermann 77727ffc49 python3 does not return list of keys 2019-04-04 17:47:52 +02:00
c-holtermann 64a01f3027 python3 - 'as' needed in exceptions instead of comma 2019-04-04 17:47:34 +02:00
c-holtermann 0068475bb1 xrange has been dropped in python3 2019-04-04 17:47:14 +02:00
c-holtermann 298797a9be fix due to different invoice date handling 2019-04-04 11:53:40 +02:00
Christoph Holtermann 206ed63233 typo 2019-04-04 11:53:23 +02:00
Christoph Holtermann 247d04a544 make executable, remove double -o 2019-04-04 11:52:44 +02:00
Christoph Holtermann 1184e92687 2to3 2019-04-04 11:52:13 +02:00
Christoph Holtermann 002595f4cc add options iOP 2019-04-04 11:51:00 +02:00
Christoph Holtermann 61f7613b8d fix for python3 2019-04-04 11:49:20 +02:00