-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,835 additions
and
827 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__pycache__/ | ||
__pycache__/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 34 additions & 34 deletions
68
duck_farm_backend/management/management/commands/populate_expenses.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import random | ||
from datetime import datetime, timedelta | ||
from django.core.management.base import BaseCommand | ||
from management.models import Expense, Dealer | ||
|
||
class Command(BaseCommand): | ||
help = 'Generate expense data and save directly to the database' | ||
|
||
def handle(self, *args, **kwargs): | ||
start_date = datetime.strptime("20-06-2023", "%d-%m-%Y") | ||
end_date = datetime.strptime("20-06-2024", "%d-%m-%Y") | ||
|
||
# Get all dealer IDs to randomly select from | ||
dealer_ids = list(Dealer.objects.values_list('id', flat=True)) | ||
|
||
current_date = start_date | ||
while current_date <= end_date: | ||
# Generate expense data | ||
exp_type = random.choice([etype[0] for etype in Expense.EXPENSE_TYPES]) | ||
expense_amount = random.uniform(100, 2500) | ||
|
||
expense = Expense( | ||
date=current_date.date(), | ||
amount=round(expense_amount, 2), | ||
description="Randomly generated expense", | ||
exp_type=exp_type, | ||
dealer_id=random.choice(dealer_ids) # Randomly select dealer ID | ||
) | ||
expense.save() | ||
|
||
# Move to the next day | ||
current_date += timedelta(days=1) | ||
|
||
self.stdout.write(self.style.SUCCESS('Successfully generated and saved expense data to the database')) | ||
import random | ||
from datetime import datetime, timedelta | ||
from django.core.management.base import BaseCommand | ||
from management.models import Expense, Dealer | ||
|
||
class Command(BaseCommand): | ||
help = 'Generate expense data and save directly to the database' | ||
|
||
def handle(self, *args, **kwargs): | ||
start_date = datetime.strptime("20-06-2023", "%d-%m-%Y") | ||
end_date = datetime.strptime("20-06-2024", "%d-%m-%Y") | ||
|
||
# Get all dealer IDs to randomly select from | ||
dealer_ids = list(Dealer.objects.values_list('id', flat=True)) | ||
|
||
current_date = start_date | ||
while current_date <= end_date: | ||
# Generate expense data | ||
exp_type = random.choice([etype[0] for etype in Expense.EXPENSE_TYPES]) | ||
expense_amount = random.uniform(100, 2500) | ||
|
||
expense = Expense( | ||
date=current_date.date(), | ||
amount=round(expense_amount, 2), | ||
description="Randomly generated expense", | ||
exp_type=exp_type, | ||
dealer_id=random.choice(dealer_ids) # Randomly select dealer ID | ||
) | ||
expense.save() | ||
|
||
# Move to the next day | ||
current_date += timedelta(days=1) | ||
|
||
self.stdout.write(self.style.SUCCESS('Successfully generated and saved expense data to the database')) |
50 changes: 50 additions & 0 deletions
50
duck_farm_backend/management/management/commands/send_daily_email.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# management/commands/send_daily_email.py | ||
import os | ||
import logging | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.core.mail import send_mail | ||
from django.contrib.auth.models import User # Adjust this import to match your User model location | ||
|
||
# Determine the log file path | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'send_daily_email.log') | ||
|
||
# Set up logging | ||
logger = logging.getLogger(__name__) | ||
handler = logging.FileHandler(LOG_FILE_PATH) | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Sends a daily email reminder to the user "prabhat" to fill in egg collection data.' | ||
|
||
def handle(self, *args, **kwargs): | ||
try: | ||
# Get the user by hardcoded username "prabhat" | ||
username = "prabhat" | ||
user = User.objects.get(username=username) | ||
|
||
subject = 'Daily Reminder: Fill in Egg Collection Data' | ||
message = f'Dear {user.first_name},\n\nThis is a friendly reminder to fill in the egg collection data for today.\n\nBest regards,\nYour Application Team' | ||
|
||
send_mail( | ||
subject, | ||
message, | ||
'prabhatsuman0612@gmail.com', # Replace with your verified sender email | ||
[user.email], | ||
fail_silently=False, | ||
) | ||
|
||
logger.info(f"Successfully sent email reminder to {user.email}") | ||
self.stdout.write(self.style.SUCCESS(f"Successfully sent email reminder to {user.email}")) | ||
|
||
except User.DoesNotExist: | ||
error_message = f'User with username "{username}" does not exist' | ||
logger.error(error_message) | ||
raise CommandError(error_message) | ||
except Exception as e: | ||
logger.error(f'An error occurred: {str(e)}', exc_info=True) | ||
raise CommandError(f'An error occurred: {str(e)}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2024-06-24 19:21:19,931 - management.management.commands.send_daily_email - INFO - Successfully sent email reminder to mr.prabhatsuman@gmail.com | ||
2024-06-24 19:22:17,343 - management.management.commands.send_daily_email - INFO - Successfully sent email reminder to mr.prabhatsuman@gmail.com | ||
2024-06-24 19:23:17,775 - management.management.commands.send_daily_email - INFO - Successfully sent email reminder to mr.prabhatsuman@gmail.com |
21 changes: 21 additions & 0 deletions
21
duck_farm_backend/management/migrations/0010_currentfeed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 5.0.6 on 2024-06-28 09:37 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('management', '0009_sales'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CurrentFeed', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('quantity', models.PositiveIntegerField()), | ||
], | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
duck_farm_backend/management/migrations/0011_alter_currentfeed_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.6 on 2024-06-28 10:09 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('management', '0010_currentfeed'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='currentfeed', | ||
name='name', | ||
field=models.CharField(max_length=100, unique=True), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
duck_farm_backend/management/migrations/0012_alter_currentfeed_quantity.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.6 on 2024-06-28 10:13 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('management', '0011_alter_currentfeed_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='currentfeed', | ||
name='quantity', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.