Bug 370290 - It is impossible to setup a dedicated opening balance account
Summary: It is impossible to setup a dedicated opening balance account
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.8.0
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on: 370291
Blocks:
  Show dependency treegraph
 
Reported: 2016-10-08 10:16 UTC by Ralf Habacker
Modified: 2019-08-29 15:48 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 4.8.1,5.0.0


Attachments
Related use case (58.46 KB, image/png)
2017-05-25 18:53 UTC, Ralf Habacker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Habacker 2016-10-08 10:16:21 UTC
Several account templates have an account for opening balances for example in german skr03/04 templates accounts starting with >= '9000' are designated for this purpose. 

In recent kmymoney version entering an opening balance always creates a new account named 'Opening balance' below equity root folder. It is not possible to setup a predefined opening balance account.

Reproducible: Always

Steps to Reproduce:
1. start kmymoney
2. creates a new file using german skr03 account template
3. Goto to account "1200 Bankkonto", enter opening balance and save account

Actual Results:  
There is a new account named 'Opening balance' 

Expected Results:  
If an opening balance account is predefined the opening balance transaction should use the predefined that account instead creating a new account.
Comment 1 Ralf Habacker 2016-10-09 12:13:25 UTC
Recent kmymoney sources have support for finding an opening balance account if the related account matches the regular expression  "^Opening Balances" which uses an untranslated string and works only with english/US account  templates using exactly this full account name.  With bug 370291 it has been reported that this account name is untranslated, having it translated make the search depending on the following translated accout names, which may or may not match the behavior of kmymoney account templates. 
./fr/messages/extragear-office/kmymoney.po  "Opening Balances"  "Solde d'ouverture"
./nl/messages/extragear-office/kmymoney.po  "Opening Balances"  "Openings saldo"
./da/messages/extragear-office/kmymoney.po  "Opening Balances"  "Startsaldo"
./it/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldi iniziali"
./kk/messages/extragear-office/kmymoney.po  "Opening Balances"  "Ашық балансы"
./es/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos de apertura"
./lt/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./ja/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./ms/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./bg/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./zh_CN/messages/extragear-office/kmymoney.po  "Opening Balances"  "开户"
./hu/messages/extragear-office/kmymoney.po  "Opening Balances"  "Nyitó egyenlegek"
./en_GB/messages/extragear-office/kmymoney.po  "Opening Balances"  "Opening Balances"
./gl/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos de apertura"
./ca@valencia/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos d'obertura"
./sv/messages/extragear-office/kmymoney.po  "Opening Balances"  "Ingående behållningar"
./de/messages/extragear-office/kmymoney.po  "Opening Balances"  "Eröffnungssaldo"
./ug/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./cs/messages/extragear-office/kmymoney.po  "Opening Balances"  "Počáteční zůstatek"
./fi/messages/extragear-office/kmymoney.po  "Opening Balances"  "Alkusaldo"
./el/messages/extragear-office/kmymoney.po  "Opening Balances"  "Ισολογισμοί ανοίγματος"
./ga/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./ro/messages/extragear-office/kmymoney.po  "Opening Balances"  "Solduri inițiale"
./sk/messages/extragear-office/kmymoney.po  "Opening Balances"  "Počiatočný stav"
./pt/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos de Abertura"
./ast/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./uk/messages/extragear-office/kmymoney.po  "Opening Balances"  "Відкриття балансів"
./x-test/messages/extragear-office/kmymoney.po  "Opening Balances"  "xxOpening Balancesxx"
./zh_TW/messages/extragear-office/kmymoney.po  "Opening Balances"  "開戶金額"
./bs/messages/extragear-office/kmymoney.po  "Opening Balances"  "Početno stanje"
./mr/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./tr/messages/extragear-office/kmymoney.po  "Opening Balances"  "Açılış Bakiyeleri"
./nds/messages/extragear-office/kmymoney.po  "Opening Balances"  "Anfangssaldos"
./eo/messages/extragear-office/kmymoney.po  "Opening Balances"  ""
./ca/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos d'obertura"
./eu/messages/extragear-office/kmymoney.po  "Opening Balances"  "Hasierako saldoak"
./ru/messages/extragear-office/kmymoney.po  "Opening Balances"  "Остаток на начало"
./pt_BR/messages/extragear-office/kmymoney.po  "Opening Balances"  "Saldos de abertura"
./et/messages/extragear-office/kmymoney.po  "Opening Balances"  "Algsaldod"
./pl/messages/extragear-office/kmymoney.po  "Opening Balances"  "Salda otwarcia"
./ia/messages/extragear-office/kmymoney.po  "Opening Balances"  ""

In german account templates for example that would be the term "Eröffnungssaldo", which is not used in any present account template. Search for the more common term 'saldo' returns only two from 445 present account templates.
Comment 2 Ralf Habacker 2017-05-25 18:51:38 UTC
To be able to use a predefined opening balance account it is required to flag related accounts in the template file e.g. with 

<account type="16" name="Eröffnungssaldo">
   <flag name="opening-balance" value="1"/>
</account>

and in the kmy file e.g. with 

  <ACCOUNT currency="EUR" description="" parentaccount="AStd::Equity" opened="2016-01-01" number="" lastmodified="2017-05-25" type="16" id="A000002" lastreconciled="" institution="" name="Eröffnungssaldo">
   <KEYVALUEPAIRS>
    <PAIR key="OpeningBalanceAccount" value="Yes"/>
   </KEYVALUEPAIRS>
Comment 3 Ralf Habacker 2017-05-25 18:53:24 UTC
Created attachment 105711 [details]
Related use case

The appended screenshot shows the uses cases I think they are related - did I forgot something ?
Comment 4 Thomas Baumgart 2017-05-26 16:16:03 UTC
Would you want to have more than one opening balance account per security? The original idea and the design was to have just one account.

So we have to make sure that only one such account can be created (one that carries the proposed KVP entry). Using the account editor the name can be changed if one does not like it. We need also make sure, that the flag cannot be altered once there is at least a single transaction assigned to that account.

If you want to have more than one account it gets a bit tricky. But I think, the account can be changed by modifying the transaction in the ledger. Not sure though. Needs to be checked.
Comment 5 Ralf Habacker 2017-06-07 06:47:51 UTC
Git commit e01a94f28c771f76f8a9b1490c0e478edb23328f by Ralf Habacker.
Committed on 07/06/2017 at 06:46.
Pushed by habacker into branch '4.8'.

Add support to use a dedicated opening balance account.

With recent implementation kmymoney is not able to use a
dedicated account for opening balances. Instead it (creates)
and uses an opening balance account with the translated name
of "Opening Balances" which may be language specific.

To specify an opening balance account to be used on adding new
accounts one way of operation is to set the "opening balance
account" flag in the account editor for equity accounts.

This is enabled if no other account contains this flag. Also
changing the state of the flag is only possible if no transactions
are assigned to the account having this flag.

Another way to use this support is to flag an opening balance
account in a kmymoney account template file.

On creating a new kmymoney file the "opening balance account"
flag is imported from a template account flag if specified
in the following form:

<account type="16" name="9000 Saldovortragskonten">
   <flag name="OpeningBalanceAccount"/>
</account>

The template admin needs to make sure that only one template account
has this flag set.

Exporting the current kmymoney file to an account template exports
this flag too.

If there is at least one dedicate opening balance account in a kmymoney
file the name will be used as template for adding additional currency
related opening balance accounts in the same hierachy level as the
referenced opening balance account. On the search all accounts having
a currency postfix '(XXX)' are ignored.
REVIEW:130143

M  +10   -0    kmymoney/converter/mymoneytemplate.cpp
M  +50   -0    kmymoney/dialogs/knewaccountdlg.cpp
M  +2    -0    kmymoney/dialogs/knewaccountdlg.h
M  +76   -18   kmymoney/dialogs/knewaccountdlgdecl.ui
M  +7    -7    kmymoney/kmymoney.cpp
M  +34   -6    kmymoney/mymoney/mymoneyfile.cpp
M  +1    -1    kmymoney/mymoney/storage/mymoneystorageanon.cpp
M  +1    -0    kmymoney/reports/objectinfotable.cpp
M  +4    -1    kmymoney/reports/reportstestcommon.cpp
M  +1    -1    kmymoney/reports/reportstestcommon.h
M  +3    -1    kmymoney/templates/de_DE/skr03.kmt
M  +3    -1    kmymoney/templates/de_DE/skr04.kmt

https://commits.kde.org/kmymoney/e01a94f28c771f76f8a9b1490c0e478edb23328f
Comment 6 Ralf Habacker 2017-06-07 19:19:03 UTC
(In reply to Ralf Habacker from comment #5)
> Exporting the current kmymoney file to an account template exports
> this flag too.

>If there is at least one dedicate opening balance account in a kmymoney
>file the name will be used as template for adding additional currency
>related opening balance accounts in the same hierachy level as the
>referenced opening balance account.

It turned out that on writing additional opening balance accounts with different currencies it is required to write out the currency too and on importing such templates the currency need to be imported if present. Otherwise there would be two opening balance accounts for the same currency.
I'm going to commit a related patch.
Comment 7 Ralf Habacker 2017-06-07 19:28:05 UTC
Git commit f235a5b236d339e6caf6c64211effbc3e8d49b44 by Ralf Habacker.
Committed on 07/06/2017 at 19:27.
Pushed by habacker into branch '4.8'.

Fix bug having multiple opening balance accounts on template import.

Exported opening balance accounts needs a 'currency' attribute to avoid
multiple opening balance accounts with the same currency on template
importing which happens if the kmymoney file have opening balance
accounts for more than one currency.

M  +4    -0    kmymoney/converter/mymoneytemplate.cpp

https://commits.kde.org/kmymoney/f235a5b236d339e6caf6c64211effbc3e8d49b44