fix: 供销协议CRUD自动生成合同编号+级联删除明细
- add_supply_contracts.dspy: 自动生成contract_code(SC-YYYYMMDD-NNNN) - add_supply_contracts.dspy: 自动填充created_by/created_at/updated_at - delete_supply_contracts.dspy: 删除协议时级联删除产品折扣明细
This commit is contained in:
parent
bfc50f2364
commit
669c491f93
@ -24,6 +24,21 @@ if not userorgid:
|
|||||||
}
|
}
|
||||||
ns['resellerid'] = userorgid
|
ns['resellerid'] = userorgid
|
||||||
|
|
||||||
|
# Auto-generate contract_code if not provided
|
||||||
|
if not ns.get('contract_code'):
|
||||||
|
from datetime import datetime as _dt
|
||||||
|
_prefix = f"SC-{_dt.now().strftime('%Y%m%d')}"
|
||||||
|
async with DBPools().sqlorContext(get_module_dbname('supplychain')) as _sor:
|
||||||
|
_recs = await _sor.sqlExe(
|
||||||
|
"SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$",
|
||||||
|
{"rid": userorgid, "p": _prefix + "%"}
|
||||||
|
)
|
||||||
|
_seq = (_recs[0].cnt if _recs else 0) + 1
|
||||||
|
ns['contract_code'] = f"{_prefix}-{_seq:04d}"
|
||||||
|
ns['created_by'] = userorgid
|
||||||
|
ns['created_at'] = timestampstr()
|
||||||
|
ns['updated_at'] = timestampstr()
|
||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
dbname = get_module_dbname('supplychain')
|
dbname = get_module_dbname('supplychain')
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
|||||||
@ -21,6 +21,8 @@ ns['resellerid'] = userorgid
|
|||||||
db = DBPools()
|
db = DBPools()
|
||||||
dbname = get_module_dbname('supplychain')
|
dbname = get_module_dbname('supplychain')
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
# Cascade delete contract items first
|
||||||
|
await sor.D('supply_contract_items', {'contract_id': params_kw['id'], 'resellerid': userorgid})
|
||||||
r = await sor.D('supply_contracts', ns)
|
r = await sor.D('supply_contracts', ns)
|
||||||
debug('delete success');
|
debug('delete success');
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user