38086-vm/core/models.py
2026-02-02 07:39:49 +00:00

78 lines
3.3 KiB
Python

from django.db import models
from django.utils.translation import gettext_lazy as _
class Category(models.Model):
name_en = models.CharField(_("Name (English)"), max_length=100)
name_ar = models.CharField(_("Name (Arabic)"), max_length=100)
slug = models.SlugField(unique=True)
class Meta:
verbose_name_plural = _("Categories")
def __str__(self):
return f"{self.name_en} / {self.name_ar}"
class Product(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="products")
name_en = models.CharField(_("Name (English)"), max_length=200)
name_ar = models.CharField(_("Name (Arabic)"), max_length=200)
sku = models.CharField(_("SKU"), max_length=50, unique=True)
description = models.TextField(_("Description"), blank=True)
price = models.DecimalField(_("Price"), max_digits=10, decimal_places=2)
stock_quantity = models.PositiveIntegerField(_("Stock Quantity"), default=0)
image = models.URLField(_("Product Image"), blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.name_en} ({self.sku})"
class Customer(models.Model):
name = models.CharField(_("Name"), max_length=200)
phone = models.CharField(_("Phone"), max_length=20, blank=True)
email = models.EmailField(_("Email"), blank=True)
address = models.TextField(_("Address"), blank=True)
def __str__(self):
return self.name
class Supplier(models.Model):
name = models.CharField(_("Name"), max_length=200)
contact_person = models.CharField(_("Contact Person"), max_length=200, blank=True)
phone = models.CharField(_("Phone"), max_length=20, blank=True)
def __str__(self):
return self.name
class Sale(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True, blank=True)
total_amount = models.DecimalField(max_digits=12, decimal_places=2)
discount = models.DecimalField(max_digits=12, decimal_places=2, default=0)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"Sale #{self.id} - {self.total_amount}"
class SaleItem(models.Model):
sale = models.ForeignKey(Sale, on_delete=models.CASCADE, related_name="items")
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField()
unit_price = models.DecimalField(max_digits=10, decimal_places=2)
line_total = models.DecimalField(max_digits=12, decimal_places=2)
class Purchase(models.Model):
supplier = models.ForeignKey(Supplier, on_delete=models.SET_NULL, null=True)
total_amount = models.DecimalField(max_digits=12, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
class SystemSetting(models.Model):
business_name = models.CharField(_("Business Name"), max_length=200, default="Meezan Accounting")
address = models.TextField(_("Address"), blank=True)
phone = models.CharField(_("Phone"), max_length=20, blank=True)
email = models.EmailField(_("Email"), blank=True)
currency_symbol = models.CharField(_("Currency Symbol"), max_length=10, default="$")
tax_rate = models.DecimalField(_("Tax Rate (%)"), max_digits=5, decimal_places=2, default=0)
logo_url = models.URLField(_("Logo URL"), blank=True, null=True)
def __str__(self):
return self.business_name