crmbackend/seller_models/models.py
2026-08-16 16:03:49 +05:30

78 lines
2.8 KiB
Python

from django.db import models
class SupplierProfile(models.Model):
user_id = models.IntegerField(unique=True)
phone = models.CharField(max_length=20, blank=True, null=True)
gstin = models.CharField(max_length=15, blank=True, null=True)
is_gstin_verified = models.BooleanField(default=False)
status = models.CharField(max_length=50, default='pending_approval')
submitted_at = models.DateTimeField(blank=True, null=True)
store_name = models.CharField(max_length=255, blank=True, null=True)
aadhar_file = models.CharField(max_length=255, blank=True, null=True)
pan_file = models.CharField(max_length=255, blank=True, null=True)
aadhar_s3_key = models.CharField(max_length=255, blank=True, null=True)
pan_s3_key = models.CharField(max_length=255, blank=True, null=True)
class Meta:
managed = False
db_table = 'api_supplierprofile'
@property
def name(self):
return self.store_name or f"Supplier #{self.id}"
@property
def email(self):
from django.db import connections
try:
with connections['seller_db'].cursor() as cursor:
cursor.execute("SELECT email FROM auth_user WHERE id = %s", [self.user_id])
row = cursor.fetchone()
return row[0] if row else ""
except Exception:
return ""
class Product(models.Model):
supplier = models.ForeignKey(SupplierProfile, on_delete=models.DO_NOTHING, db_column='supplier_id')
title = models.CharField(max_length=255)
category = models.CharField(max_length=100, blank=True, null=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.IntegerField(default=0)
sku = models.CharField(max_length=100, blank=True, null=True)
image = models.TextField(blank=True, null=True)
status = models.CharField(max_length=50, default='pending')
is_active = models.BooleanField(default=True)
class Meta:
managed = False
db_table = 'api_product'
@property
def name(self):
return self.title
class Wallet(models.Model):
supplier_id = models.IntegerField(unique=True)
outstanding = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
withdrawn = models.DecimalField(max_digits=12, decimal_places=2, default=0.00)
class Meta:
managed = False
db_table = 'api_wallet'
@property
def balance(self):
return self.outstanding
class WalletTransaction(models.Model):
wallet = models.ForeignKey(Wallet, on_delete=models.DO_NOTHING)
amount = models.DecimalField(max_digits=12, decimal_places=2)
status = models.CharField(max_length=50)
class Meta:
managed = False
db_table = 'api_wallettransaction'
@property
def tx_type(self):
return "withdrawal"