diff --git a/app/apps/common/utils/django.py b/app/apps/common/utils/django.py index 02800f5..5bda1ae 100644 --- a/app/apps/common/utils/django.py +++ b/app/apps/common/utils/django.py @@ -35,7 +35,7 @@ def django_to_python_datetime(django_format): def django_to_airdatepicker_datetime(django_format): format_map = { # Time - "h": "h", # Hour (12-hour) + "h": "hh", # Hour (12-hour) "H": "H", # Hour (24-hour) "i": "m", # Minutes "A": "AA", # AM/PM uppercase @@ -76,7 +76,7 @@ def django_to_airdatepicker_datetime(django_format): def django_to_airdatepicker_datetime_separated(django_format): format_map = { # Time formats - "h": "hH", # Hour (12-hour) + "h": "hh", # Hour (12-hour) "H": "HH", # Hour (24-hour) "i": "mm", # Minutes "A": "AA", # AM/PM uppercase diff --git a/app/apps/common/widgets/datepicker.py b/app/apps/common/widgets/datepicker.py index 9b54840..1ddd871 100644 --- a/app/apps/common/widgets/datepicker.py +++ b/app/apps/common/widgets/datepicker.py @@ -148,9 +148,14 @@ class AirDateTimePickerInput(widgets.DateTimeInput): def format_value(self, value): """Format the value for display in the widget.""" - if value: + if value and isinstance(value, (datetime.date, datetime.datetime)): self.attrs["data-value"] = datetime.datetime.strftime( - value, "%Y-%m-%d %H:%M:00" + value, "%Y-%m-%dT%H:%M:00" + ) + elif value and isinstance(value, str): + value = datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:00") + self.attrs["data-value"] = datetime.datetime.strftime( + value, "%Y-%m-%dT%H:%M:00" ) if value is None: @@ -195,6 +200,7 @@ class AirMonthYearPickerInput(AirDatePickerInput): # Add data attributes for AirDatepicker configuration attrs["data-now-button-txt"] = _("Today") + attrs["data-date-format"] = "MMMM yyyy" return attrs diff --git a/app/apps/currencies/models.py b/app/apps/currencies/models.py index 536185a..e840843 100644 --- a/app/apps/currencies/models.py +++ b/app/apps/currencies/models.py @@ -72,7 +72,9 @@ class ExchangeRate(models.Model): def clean(self): super().clean() - if self.from_currency == self.to_currency: - raise ValidationError( - {"to_currency": _("From and To currencies cannot be the same.")} - ) + # Check if the attributes exist before comparing them + if hasattr(self, "from_currency") and hasattr(self, "to_currency"): + if self.from_currency == self.to_currency: + raise ValidationError( + {"to_currency": _("From and To currencies cannot be the same.")} + ) diff --git a/app/templates/cotton/ui/transactions_action_bar.html b/app/templates/cotton/ui/transactions_action_bar.html index eb53f8e..4eeebde 100644 --- a/app/templates/cotton/ui/transactions_action_bar.html +++ b/app/templates/cotton/ui/transactions_action_bar.html @@ -2,12 +2,16 @@
diff --git a/frontend/src/application/datepicker.js b/frontend/src/application/datepicker.js index df0ab94..07ff16c 100644 --- a/frontend/src/application/datepicker.js +++ b/frontend/src/application/datepicker.js @@ -163,8 +163,8 @@ window.MonthYearPicker = function createDynamicDatePicker(element) { let opts = {...baseOpts, ...positionConfig}; if (element.dataset.value) { - opts["selectedDates"] = [element.dataset.value]; - opts["startDate"] = [element.dataset.value]; + opts["selectedDates"] = [new Date(element.dataset.value + "T00:00:00")]; + opts["startDate"] = [new Date(element.dataset.value + "T00:00:00")]; } return new AirDatepicker(element, opts); };