Skip to content

Commit 995f581

Browse files
committed
Fix opening balance
We used to add the "opening balance" without ID, resulting in having only a single transaction for all accounts. Setting an opening balance for a new account removed the existing "opening balance" transaction from the previous account... Now we add the opening transaction with an ID and only remove+add the opening balance for non-new accounts (there may already be an opening balance that got edited).
1 parent d4ae55f commit 995f581

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/AccountSettingsWindow.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ AccountSettingsWindow::AccountSettingsWindow(Account* account)
4747
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
4848
AddShortcut('Q', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
4949

50-
bool foundOpeningTransaction = false;
50+
fOpeningTransactionExists = false;
5151

5252
if (fAccount == NULL)
5353
SetTitle(B_TRANSLATE("New account"));
5454
else
55-
foundOpeningTransaction = _GetOpeningTransaction();
55+
fOpeningTransactionExists = _GetOpeningTransaction();
5656

5757
fAccountName = new AutoTextControl("accname", B_TRANSLATE("Name:"),
5858
(fAccount ? fAccount->Name() : NULL), new BMessage(M_DATA_CHANGED));
@@ -73,7 +73,7 @@ AccountSettingsWindow::AccountSettingsWindow(Account* account)
7373
BSize size(height - 2, height);
7474
fNegativeButton->SetExplicitSize(size);
7575

76-
if (foundOpeningTransaction) {
76+
if (fOpeningTransactionExists) {
7777
fOpeningDate->SetDate(fOpeningTransaction.Date());
7878
fOpeningDate->Validate();
7979
BString tempstr;
@@ -184,7 +184,9 @@ AccountSettingsWindow::MessageReceived(BMessage* msg)
184184
Locale customLocale;
185185
fPrefView->GetSettings(customLocale);
186186

187+
bool newAccount = false;
187188
if (!fAccount) {
189+
newAccount = true;
188190
gDatabase.AddAccount(fAccountName->Text(), ACCOUNT_BANK, "Open",
189191
fUseDefault->Value() == B_CONTROL_ON ? NULL : &customLocale);
190192
fAccount = gDatabase.AccountByName(fAccountName->Text());
@@ -199,17 +201,17 @@ AccountSettingsWindow::MessageReceived(BMessage* msg)
199201
fAccount->UseDefaultLocale(true);
200202
}
201203

202-
// Opening balance date and amount not empty, create opening trnsaction.
204+
// Opening balance date and amount not empty, create opening transaction.
203205
if (strlen(fOpeningAmount->Text()) > 0 && strlen(fOpeningDate->Text()) > 0) {
204206
const char* type = fNegativeButton->Value() == B_CONTROL_OFF ? "DEP" : "ATM";
205207
fOpeningTransaction.Set(fAccount, fOpeningDate->Text(), type, NULL,
206208
fOpeningAmount->Text(), B_TRANSLATE_CONTEXT("Opening balance", "CommonTerms"),
207209
NULL, fOpeningTransaction.Status());
208210
try {
209-
gDatabase.RemoveTransaction(fOpeningTransaction.GetID());
211+
if (fOpeningTransactionExists)
212+
gDatabase.RemoveTransaction(fOpeningTransaction.GetID());
210213

211-
// This adds the transaction data without generating a new transaction id
212-
gDatabase.AddTransaction(fOpeningTransaction, false);
214+
gDatabase.AddTransaction(fOpeningTransaction);
213215
} catch (CppSQLite3Exception& e) {
214216
debugger(e.errorMessage());
215217
}

src/AccountSettingsWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class AccountSettingsWindow : public BWindow {
3434
bool _GetOpeningTransaction();
3535
void _UpdateStates();
3636

37+
bool fOpeningTransactionExists;
3738
AutoTextControl* fAccountName;
3839
DateBox* fOpeningDate;
3940
CurrencyBox* fOpeningAmount;

0 commit comments

Comments
 (0)