CSV取込機能を実装し、Expenseモデルと関連するStore・ExpenseCategoryモデルを追加。CSVパーサーを作成し、出光CSVに対応。明細編集画面のAJAX保存機能を実装し、取込結果を表示する機能を追加。作業ログをdiary.mdに追記。
This commit is contained in:
@@ -1,3 +1,47 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
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}'
|
||||
|
||||
Reference in New Issue
Block a user