E-1 完了サマリー

実施内容
#	変更内容	ファイル
1	OfficialChusankanField に 11 フィールド追加(17列化)	models.py
2	中山間インポート: 17 列すべて読み込み対応	views.py
3	共済インポート: 面積カラム名不一致バグ修正 + a→m2 変換(×100)	views.py
4	シリアライザに 11 フィールド追加	serializers.py
5	共済 PDF: A4 縦、表形式、@page 設定、ページ番号、中国語除去	kyosai_template.html
6	中山間 PDF: A4 横、表形式、@page 設定、ページ番号、中国語除去	chusankan_template.html
7	PDF 生成ロジック: フラットテーブル、null 安全、prefetch_related	reports/views.py
8	既存データ再インポート(共済面積修正 + 中山間 17 列埋め)	—
9	Playwright E2E テスト 11 件全 PASS	verify-fixes.spec.ts
追加発見・修正したバグ
共済 ODS の 本地面積 (m2) カラム名にスペースが含まれ、インポート時に面積が全件 0 になっていた
面積の単位がアール(a)であることが判明。m2 への変換 (×100) を追加
PDF は http://localhost:3000/reports からダウンロードして確認できます。
This commit is contained in:
Akira
2026-02-17 15:27:14 +09:00
parent 85362d40c9
commit d70b5ee551
13 changed files with 584 additions and 192 deletions

View File

@@ -32,21 +32,33 @@ def import_kyosai_master(request):
try:
df = pd.read_excel(ods_file, engine='odf')
df.columns = df.columns.str.strip()
# ODS カラム名 "本地面積 (m2)" のスペース有無に対応
area_col = None
for col in df.columns:
if '本地面積' in col:
area_col = col
break
created_count = 0
updated_count = 0
for _, row in df.iterrows():
k_num = str(row.get('耕地番号', '')).strip() if pd.notna(row.get('耕地番号')) else ''
s_num = str(row.get('分筆番号', '')).strip() if pd.notna(row.get('分筆番号')) else ''
if not k_num:
continue
area_val = 0
if area_col and pd.notna(row.get(area_col)):
# ODS の値はアール(a)単位。m2 に変換 (1a = 100m2)
area_val = int(float(row.get(area_col)) * 100)
defaults = {
'address': str(row.get('地名 地番', '')).strip() if pd.notna(row.get('地名 地番')) else '',
'kanji_name': str(row.get('漢字地名', '')).strip() if pd.notna(row.get('漢字地名')) else '',
'area': int(float(row.get('本地面積(m2)', 0))) if pd.notna(row.get('本地面積(m2)')) else 0,
'area': area_val,
}
obj, created = OfficialKyosaiField.objects.update_or_create(
@@ -169,37 +181,50 @@ def import_chusankan_master(request):
ods_file = request.FILES['file']
def safe_str(val, default=''):
return str(val).strip() if pd.notna(val) else default
def safe_int(val, default=None):
if pd.isna(val):
return default
try:
return int(float(val))
except (ValueError, TypeError):
return default
try:
df = pd.read_excel(ods_file, engine='odf')
df.columns = df.columns.str.strip()
created_count = 0
updated_count = 0
for _, row in df.iterrows():
raw_id = row.get('ID')
c_id = str(raw_id).strip() if pd.notna(raw_id) else ''
if not c_id:
continue
if not any(char.isdigit() for char in c_id):
continue
try:
payment_amount_val = row.get('交付金額')
if pd.notna(payment_amount_val):
payment_amount = int(payment_amount_val)
else:
payment_amount = None
except (ValueError, TypeError):
payment_amount = None
defaults = {
'oaza': str(row.get('大字', '')).strip() if pd.notna(row.get('大字')) else '',
'aza': str(row.get('', '')).strip() if pd.notna(row.get('')) else '',
'chiban': str(row.get('地番', '')).strip() if pd.notna(row.get('地番')) else '',
'area': int(float(row.get('農地面積', 0))) if pd.notna(row.get('農地面積')) else 0,
'payment_amount': payment_amount,
'chusankan_flag': safe_str(row.get('中山間')) or None,
'oaza': safe_str(row.get('')),
'aza': safe_str(row.get('')),
'chiban': safe_str(row.get('地番')),
'branch_num': safe_str(row.get('枝番')) or None,
'land_type': safe_str(row.get('地目')) or None,
'area': safe_int(row.get('農地面積'), 0),
'planting_area': safe_int(row.get('植栽面積')),
'original_crop': safe_str(row.get('作付け品目')) or None,
'manager': safe_str(row.get('協定管理者')) or None,
'owner': safe_str(row.get('所有者')) or None,
'slope': safe_str(row.get('傾斜度')) or None,
'base_amount': safe_int(row.get('基本金額')),
'steep_slope_addition': safe_int(row.get('超急傾斜加算額')),
'smart_agri_addition': safe_int(row.get('スマート農業加算額')),
'payment_amount': safe_int(row.get('交付金額')),
}
obj, created = OfficialChusankanField.objects.update_or_create(