CSV取込機能を実装し、Expenseモデルと関連するStore・ExpenseCategoryモデルを追加。CSVパーサーを作成し、出光CSVに対応。明細編集画面のAJAX保存機能を実装し、取込結果を表示する機能を追加。作業ログをdiary.mdに追記。

This commit is contained in:
president
2025-12-19 15:51:14 +09:00
parent 5fc2a31f50
commit 89caf3438a
11 changed files with 489 additions and 7 deletions

View File

@@ -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}'