fix(pl): reject unknown plan product ids on upsert with 422.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
857067ec80
commit
2e5b05f477
3 files changed
+74
-5
No files matched your search
@@ -130,6 +130,7 @@ from app.services.pl_plan_service import (
|
||||
assert_contract_selectable_for_plan,
|
||||
apply_plan_product_fields,
|
||||
build_plan_product,
|
||||
resolve_plan_product_id_for_upsert,
|
||||
calc_plan_total_amount,
|
||||
clear_draft_transport_for_plan,
|
||||
clear_hazard_cert_ready,
|
||||
@@ -1645,7 +1646,10 @@ def update_plan(
|
||||
if payload.products is not None:
|
||||
existing_all = (
|
||||
db.query(PlPlanProduct)
|
||||
.filter(PlPlanProduct.plan_id == id)
|
||||
.filter(
|
||||
PlPlanProduct.plan_id == id,
|
||||
PlPlanProduct.tenant_no == tenant_no,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
existing_all_by_id = {row.id: row for row in existing_all}
|
||||
@@ -1685,8 +1689,11 @@ def update_plan(
|
||||
"legal_use_cert_url": legal_use_cert,
|
||||
}
|
||||
)
|
||||
row_id = (prod.id or "").strip() or None
|
||||
existing = existing_all_by_id.get(row_id) if row_id else None
|
||||
row_id, existing = resolve_plan_product_id_for_upsert(
|
||||
plan_id=id,
|
||||
payload_id=prod.id,
|
||||
existing_by_id=existing_all_by_id,
|
||||
)
|
||||
if existing is not None:
|
||||
apply_plan_product_fields(
|
||||
existing,
|
||||
@@ -1706,6 +1713,7 @@ def update_plan(
|
||||
order_num=idx,
|
||||
user_id=user.id,
|
||||
dept_id=user.dept_id,
|
||||
product_row_id=row_id,
|
||||
)
|
||||
db.add(pp)
|
||||
kept_ids.add(pp.id)
|
||||
|
||||
Reference in new issue
Block a user