Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent ids #758

Merged
merged 9 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions NickvisionMoney.GNOME/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ public Program(string[] args)
_mainWindow = null;
_mainWindowController = new MainWindowController(args);
_mainWindowController.AppInfo.Changelog =
@"* Disallowed whitespace-only group and account names
* Fixed an issue where exported PDF values were incorrect
* Fixed an issue where some system cultures were not read properly
* Fixed an issue where scrolling the sidebar with the mouse over the calendar would scroll the calendar instead
* Fixed an issue where leading or trailing spaces in group/account names aren't discarded
* Updated to GNOME 45 runtime with latest libadwaita design
* Updated to .NET 8.0
@"* Fixed an issue where the generated ids of new transactions were incorrect.
* Fixed an issue that causes sort to behave inconsistently.
JoseBritto marked this conversation as resolved.
Show resolved Hide resolved
* Fixed calendar not showing marks for transactions after pressing the ""Today"" button.
* Updated and added translations (Thanks to everyone on Weblate)!";
_application.OnActivate += OnActivate;
if (File.Exists(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + "/org.nickvision.money.gresource"))
Expand Down
1 change: 1 addition & 0 deletions NickvisionMoney.GNOME/Views/AccountView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ private void OnSelectCurrentMonth(Gtk.Button sender, EventArgs e)
private void OnResetCalendarFilter(Gtk.Button sender, EventArgs e)
{
gtk_calendar_select_day(_calendar.Handle, ref g_date_time_new_now_local());
OnCalendarMonthYearChanged(null, e);
_rangeExpander.SetEnableExpansion(false);
}

Expand Down
32 changes: 22 additions & 10 deletions NickvisionMoney.Shared/Controllers/AccountViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,38 @@ private int SortTransactions(uint a, uint b)
else if (SortTransactionsBy == SortBy.Date)
{
compareTo = _account.Transactions[a].Date.CompareTo(_account.Transactions[b].Date);
compareTo = compareTo == 0 ? a.CompareTo(b) : compareTo;
}
else if (SortTransactionsBy == SortBy.Amount)
{
var aAmount = _account.Transactions[a].Amount * (_account.Transactions[a].Type == TransactionType.Income ? 1m : -1m);
var bAmount = _account.Transactions[b].Amount * (_account.Transactions[b].Type == TransactionType.Income ? 1m : -1m);
compareTo = aAmount.CompareTo(bAmount);
compareTo = aAmount.CompareTo(bAmount);
if (compareTo == 0)
{
compareTo = _account.Transactions[a].Date.CompareTo(_account.Transactions[b].Date);
compareTo = compareTo == 0 ? a.CompareTo(b) : compareTo;
}
}
if (!SortFirstToLast)
{
compareTo *= -1;
}
return compareTo;

int GetCompareToByDate()
{
var result = _account.Transactions[a].Date.CompareTo(_account.Transactions[b].Date);
return result == 0 ? a.CompareTo(b) : result; // If dates are equal, sort by id
}

int GetCompareToByAmount()
{
var aAmount = _account.Transactions[a].Amount * (_account.Transactions[a].Type == TransactionType.Income ? 1m : -1m);
var bAmount = _account.Transactions[b].Amount * (_account.Transactions[b].Type == TransactionType.Income ? 1m : -1m);
var result = aAmount.CompareTo(bAmount);
return result == 0 ? GetCompareToByDate() : result; // If amounts are equal, sort by date
}
JoseBritto marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down Expand Up @@ -628,15 +648,7 @@ public async Task AddTransactionAsync(Transaction transaction)
if (res.Successful)
{
var transactions = _account.Transactions.Keys.ToList();
transactions.Sort((a, b) =>
{
var compareTo = SortTransactionsBy == SortBy.Date ? _account.Transactions[a].Date.CompareTo(_account.Transactions[b].Date) : a.CompareTo(b);
if (!SortFirstToLast)
{
compareTo *= -1;
}
return compareTo;
});
transactions.Sort(SortTransactions);
for (var i = 0; i < transactions.Count; i++)
{
if (transactions[i] == transaction.Id)
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.Shared/Controllers/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public MainWindowController(string[] args)
Directory.Delete($"{UserDirectories.Config}{Path.DirectorySeparatorChar}Nickvision{Path.DirectorySeparatorChar}{AppInfo.Name}", true);
}
Aura.Active.SetConfig<Configuration>("config");
AppInfo.Version = "2023.11.0";
AppInfo.Version = "2023.12.0-next";
AppInfo.ShortName = _("Denaro");
AppInfo.Description = _("Manage your personal finances");
AppInfo.SourceRepo = new Uri("https://github.com/NickvisionApps/Denaro");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@
<mediatype>application/x-nmoney</mediatype>
</provides>
<releases>
<release version="2023.11.0" date="2023-11-17">
<release version="2023.12.0-next" date="2023-12-01">
<description translatable="no">
<p>- Disallowed whitespace-only group and account names</p>
<p>- Fixed an issue where exported PDF values were incorrect</p>
<p>- Fixed an issue where some system cultures were not read properly</p>
<p>- Fixed an issue where scrolling the sidebar with the mouse over the calendar would scroll the calendar instead</p>
<p>- Fixed an issue where leading or trailing spaces in group/account names aren't discarded</p>
<p>- Updated to GNOME 45 runtime with latest libadwaita design</p>
<p>- Updated to .NET 8.0</p>
<p>- Fixed an issue where the generated ids of new transactions were incorrect.</p>
<p>- Fixed an issue that causes sort to behave inconsistently.</p>
JoseBritto marked this conversation as resolved.
Show resolved Hide resolved
<p>- Fixed calendar not showing marks for transactions after pressing the "Today" button.</p>
<p>- Updated translations (Thanks to everyone on Weblate)!</p>
</description>
</release>
Expand Down
9 changes: 8 additions & 1 deletion NickvisionMoney.Shared/Models/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,14 @@ public async Task<bool> DeleteTransactionAsync(uint id)
Transactions.Remove(id);
if (id + 1 == NextAvailableTransactionId)
{
NextAvailableTransactionId--;
if(Transactions.Count == 0)
JoseBritto marked this conversation as resolved.
Show resolved Hide resolved
{
NextAvailableTransactionId = 1;
}
else
{
NextAvailableTransactionId = Transactions.Max(x => x.Key) + 1;
JoseBritto marked this conversation as resolved.
Show resolved Hide resolved
}
}
BackupAccountToCSV();
return true;
Expand Down