fix: ensure dspy returns 302 redirect instead of DataViewer widget
PopupWindow can't render DataViewer returned from dspy. Now dspy creates contract/agreement if needed, then 302→CRUD page.
This commit is contained in:
parent
a3176e4f34
commit
a930847317
@ -1,4 +1,4 @@
|
||||
"""Check/create distribution_agreement for sub_reseller_id, then show CRUD page."""
|
||||
"""Check/create distribution_agreement for sub_reseller_id, then redirect to CRUD page."""
|
||||
sub_reseller_id = params_kw.get('sub_reseller_id')
|
||||
if not sub_reseller_id:
|
||||
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': 'Missing sub_reseller_id', 'timeout': 3}}
|
||||
@ -9,48 +9,31 @@ if not userorgid:
|
||||
|
||||
dbname = get_module_dbname('supplychain')
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
# Check existing
|
||||
recs = await sor.sqlExe(
|
||||
'SELECT id FROM distribution_agreements WHERE sub_reseller_id = ${sid}$ AND resellerid = ${rid}$ AND status = ${st}$',
|
||||
{'sid': sub_reseller_id, 'rid': userorgid, 'st': '1'}
|
||||
)
|
||||
if not recs:
|
||||
# Get sub_reseller name
|
||||
sub = await sor.sqlExe(
|
||||
'SELECT sub_reseller_name FROM sub_resellers WHERE id = ${sid}$',
|
||||
{'sid': sub_reseller_id}
|
||||
)
|
||||
sub_name = sub[0].sub_reseller_name if sub else sub_reseller_id
|
||||
|
||||
# Generate agreement_code
|
||||
prefix = f"DA-{datetime.datetime.now().strftime('%Y%m%d')}"
|
||||
cnt_recs = await sor.sqlExe(
|
||||
'SELECT COUNT(*) as cnt FROM distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$',
|
||||
{'rid': userorgid, 'p': prefix + '%'}
|
||||
)
|
||||
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||
agreement_code = f"{prefix}-{seq:04d}"
|
||||
|
||||
now = timestampstr()
|
||||
agreement_id = getID()
|
||||
await sor.C('distribution_agreements', {
|
||||
'id': agreement_id,
|
||||
'resellerid': userorgid,
|
||||
'sub_reseller_id': sub_reseller_id,
|
||||
'agreement_code': agreement_code,
|
||||
'agreement_name': f'{sub_name}分销协议',
|
||||
'start_date': curDateString(),
|
||||
'status': '1',
|
||||
'default_discount': '1.0000',
|
||||
'created_by': userorgid,
|
||||
'created_at': now,
|
||||
'updated_at': now,
|
||||
'id': getID(), 'resellerid': userorgid, 'sub_reseller_id': sub_reseller_id,
|
||||
'agreement_code': f"{prefix}-{seq:04d}", 'agreement_name': f'{sub_name}分销协议',
|
||||
'start_date': curDateString(), 'status': '1', 'default_discount': '1.0000',
|
||||
'created_by': userorgid, 'created_at': now, 'updated_at': now,
|
||||
})
|
||||
|
||||
# Return CRUD page embedded in popup
|
||||
return {
|
||||
'widgettype': 'DataViewer',
|
||||
'options': {
|
||||
'url': f'/supplychain/distribution_agreements_list?sub_reseller_id={sub_reseller_id}&_webbricks_=1'
|
||||
}
|
||||
}
|
||||
# Redirect to CRUD page
|
||||
request._response_status = 302
|
||||
request._response_headers['Location'] = f'/supplychain/distribution_agreements_list?sub_reseller_id={sub_reseller_id}&_webbricks_=1'
|
||||
return ''
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
"""Check/create supply_contract for supplier_id, then show CRUD page."""
|
||||
"""Check/create supply_contract for supplier_id, then redirect to CRUD page."""
|
||||
supplier_id = params_kw.get('supplier_id')
|
||||
if not supplier_id:
|
||||
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': 'Missing supplier_id', 'timeout': 3}}
|
||||
@ -27,22 +27,13 @@ async with DBPools().sqlorContext(dbname) as sor:
|
||||
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||
now = timestampstr()
|
||||
await sor.C('supply_contracts', {
|
||||
'id': getID(),
|
||||
'resellerid': userorgid,
|
||||
'supplier_id': supplier_id,
|
||||
'contract_code': f"{prefix}-{seq:04d}",
|
||||
'contract_name': f'{sup_name}供销协议',
|
||||
'start_date': curDateString(),
|
||||
'status': '1',
|
||||
'default_discount': '1.0000',
|
||||
'created_by': userorgid,
|
||||
'created_at': now,
|
||||
'updated_at': now,
|
||||
'id': getID(), 'resellerid': userorgid, 'supplier_id': supplier_id,
|
||||
'contract_code': f"{prefix}-{seq:04d}", 'contract_name': f'{sup_name}供销协议',
|
||||
'start_date': curDateString(), 'status': '1', 'default_discount': '1.0000',
|
||||
'created_by': userorgid, 'created_at': now, 'updated_at': now,
|
||||
})
|
||||
|
||||
return {
|
||||
'widgettype': 'DataViewer',
|
||||
'options': {
|
||||
'url': f'/supplychain/supply_contracts_list?supplier_id={supplier_id}&_webbricks_=1'
|
||||
}
|
||||
}
|
||||
# Redirect to CRUD page
|
||||
request._response_status = 302
|
||||
request._response_headers['Location'] = f'/supplychain/supply_contracts_list?supplier_id={supplier_id}&_webbricks_=1'
|
||||
return ''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user