データベースルールにowner_typeとis_canceledを追加し、is_businessを廃止。Expenseモデルと関連するマイグレーションを実施。明細編集UIをowner_type選択に更新し、取り消し済みの経費を一覧から除外。作業ログをdiary.mdに追記。
This commit is contained in:
56
expenses/migrations/0002_owner_type_cancel.py
Normal file
56
expenses/migrations/0002_owner_type_cancel.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# Generated by Django 4.2.27 on 2025-12-20 00:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def map_is_business_to_owner_type(apps, schema_editor):
|
||||
Expense = apps.get_model('expenses', 'Expense')
|
||||
for expense in Expense.objects.all():
|
||||
if expense.is_business is True:
|
||||
expense.owner_type = 'company'
|
||||
elif expense.is_business is False:
|
||||
expense.owner_type = 'personal'
|
||||
else:
|
||||
expense.owner_type = 'pending'
|
||||
expense.save(update_fields=['owner_type'])
|
||||
|
||||
|
||||
def reverse_owner_type_to_is_business(apps, schema_editor):
|
||||
Expense = apps.get_model('expenses', 'Expense')
|
||||
for expense in Expense.objects.all():
|
||||
if expense.owner_type == 'company':
|
||||
expense.is_business = True
|
||||
elif expense.owner_type == 'personal':
|
||||
expense.is_business = False
|
||||
else:
|
||||
expense.is_business = None
|
||||
expense.save(update_fields=['is_business'])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('expenses', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='expense',
|
||||
name='owner_type',
|
||||
field=models.CharField(
|
||||
choices=[('company', 'Company'), ('personal', 'Personal'), ('pending', 'Pending')],
|
||||
default='pending',
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='expense',
|
||||
name='is_canceled',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.RunPython(map_is_business_to_owner_type, reverse_owner_type_to_is_business),
|
||||
migrations.RemoveField(
|
||||
model_name='expense',
|
||||
name='is_business',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user