合约管理简化为选品种+填月份,系统自动拼接合约代码
This commit is contained in:
@@ -76,15 +76,21 @@ def create_product(
|
|||||||
def create_contract(
|
def create_contract(
|
||||||
request: Request,
|
request: Request,
|
||||||
product_id: int = Form(...),
|
product_id: int = Form(...),
|
||||||
code: str = Form(...),
|
month: str = Form(...),
|
||||||
name: str = Form(...),
|
|
||||||
db: Session = Depends(get_db),
|
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:
|
if not existing:
|
||||||
c = Contract(
|
c = Contract(
|
||||||
product_id=product_id,
|
product_id=product_id,
|
||||||
code=code.upper(),
|
code=code,
|
||||||
name=name,
|
name=name,
|
||||||
is_active=True,
|
is_active=True,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -139,20 +139,16 @@
|
|||||||
<form method="post" action="/admin/contract" style="display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap;">
|
<form method="post" action="/admin/contract" style="display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap;">
|
||||||
<div class="form-group" style="margin-bottom:0;flex:1;min-width:140px;">
|
<div class="form-group" style="margin-bottom:0;flex:1;min-width:140px;">
|
||||||
<label>品种</label>
|
<label>品种</label>
|
||||||
<select name="product_id" id="contract-product" required onchange="onProductChange()">
|
<select name="product_id" required>
|
||||||
<option value="">-- 选择品种 --</option>
|
<option value="">-- 选择品种 --</option>
|
||||||
{% for p in products %}
|
{% for p in products %}
|
||||||
<option value="{{ p.id }}" data-code="{{ p.code }}">{{ p.code }} · {{ p.name }}</option>
|
<option value="{{ p.id }}">{{ p.code }} · {{ p.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group" style="margin-bottom:0;flex:1;min-width:140px;">
|
<div class="form-group" style="margin-bottom:0;flex:1;min-width:140px;">
|
||||||
<label>合约代码 <span style="font-weight:400;color:var(--sub);font-size:0.75rem;">品种代码加月份</span></label>
|
|
||||||
<input type="text" name="code" id="contract-code" required placeholder="先选品种" maxlength="10" style="text-transform:uppercase;">
|
|
||||||
</div>
|
|
||||||
<div class="form-group" style="margin-bottom:0;flex:1;min-width:100px;">
|
|
||||||
<label>月份 <span style="font-weight:400;color:var(--sub);font-size:0.75rem;">如 2609</span></label>
|
<label>月份 <span style="font-weight:400;color:var(--sub);font-size:0.75rem;">如 2609</span></label>
|
||||||
<input type="text" name="name" required placeholder="2609" maxlength="4" style="text-transform:uppercase;">
|
<input type="text" name="month" required placeholder="2609" maxlength="4" style="text-transform:uppercase;">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">添加</button>
|
<button type="submit" class="btn btn-primary">添加</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -216,16 +212,5 @@ function toggleProduct(header) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onProductChange() {
|
|
||||||
var sel = document.getElementById('contract-product');
|
|
||||||
var opt = sel.options[sel.selectedIndex];
|
|
||||||
var code = opt.dataset.code || '';
|
|
||||||
var input = document.getElementById('contract-code');
|
|
||||||
if (code) {
|
|
||||||
input.placeholder = code + '2609';
|
|
||||||
} else {
|
|
||||||
input.placeholder = '先选品种';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user