合约管理简化为选品种+填月份,系统自动拼接合约代码

This commit is contained in:
2026-07-24 22:52:50 +08:00
parent 2854eb97bb
commit 57f792fbe5
2 changed files with 13 additions and 22 deletions
+10 -4
View File
@@ -76,15 +76,21 @@ def create_product(
def create_contract(
request: Request,
product_id: int = Form(...),
code: str = Form(...),
name: str = Form(...),
month: str = Form(...),
db: Session = Depends(get_db),
):
existing = db.query(Contract).filter(Contract.code == code.upper()).first()
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
return RedirectResponse("/admin/?tab=contract", status_code=303)
code = (product.code + month).upper()
name = month.upper()
existing = db.query(Contract).filter(Contract.code == code).first()
if not existing:
c = Contract(
product_id=product_id,
code=code.upper(),
code=code,
name=name,
is_active=True,
)