1. Home
  2. infinity_hub
  3. সেটআপ
  4. ✅ Part 2: Investment Logic

✅ Part 2: Investment Logic

চল এবার শুরু করি ✅ Part 2: Investment Logic – এখানে আমরা একটি পূর্ণ ইনভেস্টমেন্ট ফিচার বানাবো যেখানে থাকবে:


🎯 লক্ষ্য

  1. InvestmentPackage – যেকোনো ইনভেস্টমেন্ট প্যাকেজ ডিফাইন করতে
  2. UserInvestment – ইউজার কোন প্যাকেজে কত ইনভেস্ট করেছে
  3. ROITransaction – প্রতিদিনের ROI হিসেব
  4. ROI Generator – অটোমেটেড ROI প্রসেস (signal or management command দিয়ে)

📁 investment/models.py

from django.db import models
from django.contrib.auth.models import User
from decimal import Decimal
from django.utils import timezone


class InvestmentPackage(models.Model):
    name = models.CharField(max_length=100)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    roi_percent = models.DecimalField(max_digits=5, decimal_places=2)  # daily %

    def __str__(self):
        return f"{self.name} - ${self.amount}"


class UserInvestment(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    package = models.ForeignKey(InvestmentPackage, on_delete=models.CASCADE)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    start_date = models.DateField(auto_now_add=True)
    active = models.BooleanField(default=True)

    def __str__(self):
        return f"{self.user.username} - ${self.amount} - {self.package.name}"


class ROITransaction(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    investment = models.ForeignKey(UserInvestment, on_delete=models.CASCADE)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    created_at = models.DateField(auto_now_add=True)

    def __str__(self):
        return f"{self.user.username} - ROI: ${self.amount} on {self.created_at}"

📁 investment/admin.py

from django.contrib import admin
from unfold.admin import ModelAdmin
from .models import InvestmentPackage, UserInvestment, ROITransaction

@admin.register(InvestmentPackage)
class InvestmentPackageAdmin(ModelAdmin):
    list_display = ['name', 'amount', 'roi_percent']


@admin.register(UserInvestment)
class UserInvestmentAdmin(ModelAdmin):
    list_display = ['user', 'package', 'amount', 'start_date', 'active']
    list_filter = ['active']


@admin.register(ROITransaction)
class ROITransactionAdmin(ModelAdmin):
    list_display = ['user', 'investment', 'amount', 'created_at']
    list_filter = ['created_at']

🛠 ROI Generator Function (Demo Purpose)

📁 investment/utils.py

from .models import UserInvestment, ROITransaction
from decimal import Decimal
from django.utils import timezone

def generate_daily_roi():
    today = timezone.now().date()
    investments = UserInvestment.objects.filter(active=True)

    for inv in investments:
        roi_amount = (inv.amount * inv.package.roi_percent) / Decimal(100)
        ROITransaction.objects.create(
            user=inv.user,
            investment=inv,
            amount=roi_amount,
            created_at=today
        )

তুমি চাইলে এই ফাংশনকে একটি custom command অথবা CRON দিয়ে প্রতিদিন সকালে চালাতে পারো।


🔄 Migrate & Test

python manage.py makemigrations investment
python manage.py migrate

Admin থেকে InvestmentPackage বানিয়ে UserInvestment দিয়ে ইউজারদের ইনভেস্ট করাও।


🧪 Example Flow:

  1. Package: Starter - $100 – ROI: 2%
  2. User: alice invests $100
  3. Daily ROI: $2 saved in ROITransaction

✅ Part 2 শেষ।

তুমি কি Part 3: Referral & Affiliate System শুরু করতে চাও? এতে থাকবে:

  • Referral tree tracking
  • 10-level commission
  • ReferralIncome model

How can we help?