48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from django.db import models
|
|
|
|
|
|
class Store(models.Model):
|
|
name = models.CharField(max_length=200, unique=True)
|
|
is_active = models.BooleanField(default=True)
|
|
|
|
def __str__(self) -> str:
|
|
return self.name
|
|
|
|
|
|
class ExpenseCategory(models.Model):
|
|
name = models.CharField(max_length=200, unique=True)
|
|
is_active = models.BooleanField(default=True)
|
|
|
|
def __str__(self) -> str:
|
|
return self.name
|
|
|
|
|
|
class Expense(models.Model):
|
|
SOURCE_CHOICES = [
|
|
('idemitsu', 'Idemitsu'),
|
|
]
|
|
|
|
use_date = models.DateField()
|
|
description = models.CharField(max_length=255)
|
|
amount = models.IntegerField()
|
|
store = models.ForeignKey(Store, null=True, blank=True, on_delete=models.SET_NULL)
|
|
expense_category = models.ForeignKey(
|
|
ExpenseCategory, null=True, blank=True, on_delete=models.SET_NULL
|
|
)
|
|
is_business = models.BooleanField(null=True, blank=True)
|
|
note = models.TextField(blank=True)
|
|
source = models.CharField(max_length=50, choices=SOURCE_CHOICES)
|
|
source_hash = models.CharField(max_length=64)
|
|
ai_score = models.FloatField(null=True, blank=True)
|
|
human_confirmed = models.BooleanField(default=False)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(fields=['source', 'source_hash'], name='uniq_source_hash'),
|
|
]
|
|
|
|
def __str__(self) -> str:
|
|
return f'{self.use_date} {self.description} {self.amount}'
|