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

MONTA-T-39 #68

Merged
merged 10 commits into from
Feb 7, 2023
4 changes: 4 additions & 0 deletions backend/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

app.autodiscover_tasks()

app.conf.task_routes = {
"core.tasks.delete_audit_log_records": {"queue": "audit_log"},
}


@app.task(bind=True)
def debug_task(self):
Expand Down
9 changes: 6 additions & 3 deletions backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"nested_inline",
"drf_spectacular",
"auditlog",
"djmoney",
# Monta Apps
"backend",
"core",
Expand Down Expand Up @@ -132,7 +133,8 @@

# Internationalization
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
TIME_ZONE = "US/Eastern"
# TIME_ZONE = "UTC" if DEBUG else TIME_ZONE
USE_I18N = True
USE_TZ = True

Expand Down Expand Up @@ -292,9 +294,10 @@

# Celery Configurations
CELERY_BROKER_URL = "redis://127.0.0.1:6379/2"
CELERY_RESULT_BACKEND = "redis://127.0.0.1:6379/2"
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "celery"

CELERY_RESULT_EXTENDED = True
CELERY_TASK_TRACK_STARTED = True
# Field Encryption
FIELD_ENCRYPTION_KEY = env("FIELD_ENCRYPTION_KEY")

Expand Down

Large diffs are not rendered by default.

60 changes: 33 additions & 27 deletions billing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django_lifecycle import BEFORE_DELETE, BEFORE_SAVE, LifecycleModelMixin, hook
from djmoney.models.fields import MoneyField

from utils.models import ChoiceField, GenericModel, StatusChoices

Expand Down Expand Up @@ -605,32 +606,35 @@ class BillTypeChoices(models.TextChoices):
blank=True,
help_text=_("Consignee Reference Number"),
)
other_charge_total = models.DecimalField(
other_charge_total = MoneyField(
_("Other Charge Total"),
max_digits=10,
decimal_places=2,
default=0.00,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Other charge total for Order"),
blank=True,
null=True,
help_text=_("Other charge total for Order"),
default_currency="USD",
)
freight_charge_amount = models.DecimalField(
freight_charge_amount = MoneyField(
_("Freight Charge Amount"),
max_digits=10,
decimal_places=2,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Freight Charge Amount"),
blank=True,
null=True,
default_currency="USD",
)
total_amount = models.DecimalField(
total_amount = MoneyField(
_("Total Amount"),
max_digits=10,
decimal_places=2,
default=0.00,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Total amount for Order"),
blank=True,
null=True,
help_text=_("Total amount for Order"),
default_currency="USD",
)
is_summary = models.BooleanField(
_("Is Summary"),
Expand Down Expand Up @@ -963,33 +967,35 @@ class BillingHistory(LifecycleModelMixin, GenericModel):
blank=True,
help_text=_("Consignee Reference Number"),
)

other_charge_total = models.DecimalField(
other_charge_total = MoneyField(
_("Other Charge Total"),
max_digits=10,
decimal_places=2,
default=0.00,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Other charge total for Order"),
blank=True,
null=True,
help_text=_("Other charge total for Order"),
default_currency="USD",
)
freight_charge_amount = models.DecimalField(
freight_charge_amount = MoneyField(
_("Freight Charge Amount"),
max_digits=10,
decimal_places=2,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Freight Charge Amount"),
blank=True,
null=True,
default_currency="USD",
)
total_amount = models.DecimalField(
total_amount = MoneyField(
_("Total Amount"),
max_digits=10,
decimal_places=2,
default=0.00,
max_digits=19,
decimal_places=4,
default=0,
help_text=_("Total amount for Order"),
blank=True,
null=True,
help_text=_("Total amount for Order"),
default_currency="USD",
)
is_summary = models.BooleanField(
_("Is Summary"),
Expand Down
54 changes: 54 additions & 0 deletions core/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
COPYRIGHT 2022 MONTA

This file is part of Monta.

Monta is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Monta is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Monta. If not, see <https://www.gnu.org/licenses/>.
"""
import datetime

from celery import shared_task
from django.core.management import call_command
from django.utils import timezone


def get_cutoff_date() -> datetime.datetime:
"""Get the cutoff date for deleting audit log records.

Returns:
str: The cutoff date for deleting audit log records.
"""

return timezone.now() - timezone.timedelta(days=30)


@shared_task
def delete_audit_log_records() -> str:
"""Delete audit log records older than 30 days.

This task uses the Django management command `auditlogflush` to delete
audit log records older than 30 days. The cutoff date is calculated by
subtracting 30 days from the current date, and the `strftime` method is used
to format the date in a usable format for the command.

Returns:
str: The message "Audit log records deleted." upon successful completion of the task.
"""

cutoff_date = get_cutoff_date()
formatted_date = cutoff_date.strftime("%Y-%m-%d")

call_command("auditlogflush", "-b", formatted_date, "-y")

return f"Successfully deleted audit log records. older than {formatted_date}."
Binary file modified dispatch/migrations/__pycache__/0001_initial.cpython-311.pyc
Binary file not shown.
Loading