mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-24 01:28:42 +02:00
feat: default account for new transactions
This commit is contained in:
@@ -5,6 +5,7 @@ from apps.common.fields.forms.dynamic_select import (
|
|||||||
DynamicModelChoiceField,
|
DynamicModelChoiceField,
|
||||||
DynamicModelMultipleChoiceField,
|
DynamicModelMultipleChoiceField,
|
||||||
)
|
)
|
||||||
|
from apps.common.middleware.thread_local import get_current_user
|
||||||
from apps.common.widgets.crispy.daisyui import Switch
|
from apps.common.widgets.crispy.daisyui import Switch
|
||||||
from apps.common.widgets.crispy.submit import NoClassSubmit
|
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||||
from apps.common.widgets.datepicker import AirDatePickerInput, AirMonthYearPickerInput
|
from apps.common.widgets.datepicker import AirDatePickerInput, AirMonthYearPickerInput
|
||||||
@@ -116,6 +117,9 @@ class TransactionForm(forms.ModelForm):
|
|||||||
self.fields["account"].queryset = Account.objects.filter(
|
self.fields["account"].queryset = Account.objects.filter(
|
||||||
is_archived=False,
|
is_archived=False,
|
||||||
)
|
)
|
||||||
|
user_settings = get_current_user().settings
|
||||||
|
if user_settings.default_account:
|
||||||
|
self.fields["account"].initial = user_settings.default_account
|
||||||
|
|
||||||
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
||||||
active=True
|
active=True
|
||||||
@@ -768,6 +772,9 @@ class InstallmentPlanForm(forms.ModelForm):
|
|||||||
).distinct()
|
).distinct()
|
||||||
else:
|
else:
|
||||||
self.fields["account"].queryset = Account.objects.filter(is_archived=False)
|
self.fields["account"].queryset = Account.objects.filter(is_archived=False)
|
||||||
|
user_settings = get_current_user().settings
|
||||||
|
if user_settings.default_account:
|
||||||
|
self.fields["account"].initial = user_settings.default_account
|
||||||
|
|
||||||
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
||||||
active=True
|
active=True
|
||||||
@@ -1010,6 +1017,10 @@ class RecurringTransactionForm(forms.ModelForm):
|
|||||||
).distinct()
|
).distinct()
|
||||||
else:
|
else:
|
||||||
self.fields["account"].queryset = Account.objects.filter(is_archived=False)
|
self.fields["account"].queryset = Account.objects.filter(is_archived=False)
|
||||||
|
|
||||||
|
user_settings = get_current_user().settings
|
||||||
|
if user_settings.default_account:
|
||||||
|
self.fields["account"].initial = user_settings.default_account
|
||||||
|
|
||||||
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
self.fields["category"].queryset = TransactionCategory.objects.filter(
|
||||||
active=True
|
active=True
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from apps.common.middleware.thread_local import get_current_user
|
from apps.common.middleware.thread_local import get_current_user
|
||||||
from apps.common.widgets.crispy.submit import NoClassSubmit
|
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||||
|
from apps.common.widgets.tom_select import TomSelect
|
||||||
from apps.users.models import UserSettings
|
from apps.users.models import UserSettings
|
||||||
|
from apps.accounts.models import Account
|
||||||
from crispy_forms.bootstrap import (
|
from crispy_forms.bootstrap import (
|
||||||
FormActions,
|
FormActions,
|
||||||
)
|
)
|
||||||
@@ -116,6 +118,15 @@ class UserSettingsForm(forms.ModelForm):
|
|||||||
label=_("Number Format"),
|
label=_("Number Format"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_account = forms.ModelChoiceField(
|
||||||
|
queryset=Account.objects.filter(
|
||||||
|
is_archived=False,
|
||||||
|
),
|
||||||
|
label=_("Default Account"),
|
||||||
|
widget=TomSelect(clear_button=False, group_by="group"),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserSettings
|
model = UserSettings
|
||||||
fields = [
|
fields = [
|
||||||
@@ -126,11 +137,19 @@ class UserSettingsForm(forms.ModelForm):
|
|||||||
"datetime_format",
|
"datetime_format",
|
||||||
"number_format",
|
"number_format",
|
||||||
"volume",
|
"volume",
|
||||||
|
"default_account",
|
||||||
]
|
]
|
||||||
|
widgets = {
|
||||||
|
"default_account": TomSelect(clear_button=False, group_by="group"),
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.fields["default_account"].queryset = Account.objects.filter(
|
||||||
|
is_archived=False,
|
||||||
|
)
|
||||||
|
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
self.helper.form_tag = False
|
self.helper.form_tag = False
|
||||||
self.helper.form_method = "post"
|
self.helper.form_method = "post"
|
||||||
@@ -141,6 +160,7 @@ class UserSettingsForm(forms.ModelForm):
|
|||||||
"date_format",
|
"date_format",
|
||||||
"datetime_format",
|
"datetime_format",
|
||||||
"number_format",
|
"number_format",
|
||||||
|
"default_account",
|
||||||
HTML('<hr class="hr my-3" />'),
|
HTML('<hr class="hr my-3" />'),
|
||||||
"start_page",
|
"start_page",
|
||||||
HTML('<hr class="hr my-3" />'),
|
HTML('<hr class="hr my-3" />'),
|
||||||
@@ -157,6 +177,10 @@ class UserSettingsForm(forms.ModelForm):
|
|||||||
"translation_link": '<a href="https://translations.herculino.com" target="_blank">translations.herculino.com</a>'
|
"translation_link": '<a href="https://translations.herculino.com" target="_blank">translations.herculino.com</a>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.fields["default_account"].help_text = _(
|
||||||
|
"Selects the account by default when creating new transactions"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UserUpdateForm(forms.ModelForm):
|
class UserUpdateForm(forms.ModelForm):
|
||||||
new_password1 = forms.CharField(
|
new_password1 = forms.CharField(
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 5.2.9 on 2026-02-15 21:35
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0016_account_untracked_by'),
|
||||||
|
('users', '0023_alter_usersettings_timezone'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='usersettings',
|
||||||
|
name='default_account',
|
||||||
|
field=models.ForeignKey(blank=True, default=0, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.account', verbose_name='Default account'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -510,6 +510,12 @@ class UserSettings(models.Model):
|
|||||||
default=StartPage.MONTHLY,
|
default=StartPage.MONTHLY,
|
||||||
verbose_name=_("Start page"),
|
verbose_name=_("Start page"),
|
||||||
)
|
)
|
||||||
|
default_account = models.ForeignKey(
|
||||||
|
"accounts.Account", on_delete=models.SET_NULL,
|
||||||
|
verbose_name=_("Default account"),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.user.email}'s settings"
|
return f"{self.user.email}'s settings"
|
||||||
|
|||||||
Reference in New Issue
Block a user