その判断で進めました。在庫管理を先に固めるように切り替えて、手元の実装もそちらを優先して直しています。

今回入れたのは、在庫履歴の編集・削除対応と、種子資材を資材マスタ側で品種に直接結び付ける流れです。backend/apps/materials/views.py と backend/apps/materials/serializers.py で stock-transactions の更新を許可しつつ、計画や実績に紐づく履歴はロック扱いにしました。画面側は frontend/src/app/materials/page.tsx、frontend/src/app/materials/_components/StockOverview.tsx、frontend/src/app/materials/_components/StockTransactionForm.tsx を更新して、手動登録の入出庫履歴をあとから編集・削除できるようにしています。

あわせて frontend/src/app/materials/masters/page.tsx と frontend/src/app/materials/_components/MaterialForm.tsx で、種子 タブから品種を直接選んで紐付ける形にしました。重複を避けるため、作付け計画側の品種管理モーダル frontend/src/app/allocation/page.tsx から種子資材の紐付け UI は外しています。Issue #2 にもこの方針でコメント追記済みです。

確認できたのは python3 -m py_compile までで、フロントのビルドは frontend/node_modules が無いためまだ回していません。次はブラウザで在庫管理の操作感を確認してから、田植え計画側の細部を詰めるのがよさそうです。
This commit is contained in:
akira
2026-04-05 11:43:03 +09:00
parent a38472e4a0
commit 491f05eee8
9 changed files with 249 additions and 178 deletions

View File

@@ -9,6 +9,7 @@ export type MaterialTab = 'fertilizer' | 'pesticide' | 'seed' | 'misc';
export interface MaterialFormState {
name: string;
material_type: Material['material_type'];
seed_variety_id: string;
maker: string;
stock_unit: Material['stock_unit'];
is_active: boolean;
@@ -33,6 +34,7 @@ interface MaterialFormProps {
tab: MaterialTab;
form: MaterialFormState;
saving: boolean;
seedVarietyOptions?: { id: number; label: string }[];
onBaseFieldChange: (
field: keyof Omit<MaterialFormState, 'fertilizer_profile' | 'pesticide_profile'>,
value: string | boolean
@@ -56,6 +58,7 @@ export default function MaterialForm({
tab,
form,
saving,
seedVarietyOptions = [],
onBaseFieldChange,
onFertilizerFieldChange,
onPesticideFieldChange,
@@ -245,9 +248,18 @@ export default function MaterialForm({
</td>
<td className="px-2 py-2">
{tab === 'seed' ? (
<div className="rounded-md border border-green-200 bg-green-100 px-2 py-1 text-sm text-green-800">
</div>
<select
className={inputClassName}
value={form.seed_variety_id}
onChange={(e) => onBaseFieldChange('seed_variety_id', e.target.value)}
>
<option value=""></option>
{seedVarietyOptions.map((option) => (
<option key={option.id} value={option.id}>
{option.label}
</option>
))}
</select>
) : (
<select
className={inputClassName}