[GNC-dev] How do I get the "sign" (or side) of the transaction from the account or transaction element in xml?

John Ralls jralls at ceridwen.us
Sun Jul 11 12:34:21 EDT 2021



> On Jul 11, 2021, at 4:50 AM, Geert Janssens <geert.gnucash at kobaltwit.be> wrote:
> 
> Op zondag 11 juli 2021 13:38:43 CEST schreef Arman Schwarz:
>> Thanks Geert,
>> 
>> I'm aware of the need to think in terms of debit/credit signs, but my
>> question was how I could know whether a positive value in the split element
>> in the XML will increase or decrease the "balance" that the user sees in
>> gnucash.
>> 
>> This depends on the side of the accounting equation the account is on, e.g.
>> positive split values increase the balance of an asset account, but
>> decrease the balance of an income account. Rather than manually maintaining
>> a mapping of account types and whether the sign is positive or negative, I
>> was hoping there'd be something in the XML or perhaps in those bindings you
>> mentioned that would do this for me.
>> 
> 
> I don't think this is stored in the xml file as the net representation in the 
> gui is a combination of account type and the user preference. The former is 
> hard-coded, the latter can be changed by the user. I don't know if we can 
> access either information via the python bindings. I don't use them myself.

Using only the XML file you can connect the split with its account via the account's guid. The account record of course carries the account type.

As  Geert explained GnuCash uses negative numbers to represent credits. This is computationally very convenient because it means that internally GnuCash doesn't need to distinguish debit-balance and credit-balance accounts: As long as the sum of all non-trading account balances is 0 the book is in balance.

For the UI it's user-choice based on the Preferences>Accounts>Reversed Balance with choices income/expense, credit, and none. There's a function, gnc_reverse_balance(Account*), that looks up the preference and the account type. It's not exposed to the python bindings, but the logic is simple and you could replicate it pretty easily. The relevant code starts at https://github.com/Gnucash/gnucash/blob/e1c153a516f0689b04efff7191639ad604a6b6b6/libgnucash/app-utils/gnc-ui-util.c#L129.

That said only the credit preference produces a UI and reports that would make sense to an accountant so were I in your place I'd ignore the preference and write a simple function to test the account type against a list of the 5 credit-balance types (EQUIT, INCOME, LIABILITY, CREDIT, and PAYABLE).

Regards,
John Ralls



More information about the gnucash-devel mailing list