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')
|
sub_reseller_id = params_kw.get('sub_reseller_id')
|
||||||
if not sub_reseller_id:
|
if not sub_reseller_id:
|
||||||
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': 'Missing sub_reseller_id', 'timeout': 3}}
|
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')
|
dbname = get_module_dbname('supplychain')
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
# Check existing
|
|
||||||
recs = await sor.sqlExe(
|
recs = await sor.sqlExe(
|
||||||
'SELECT id FROM distribution_agreements WHERE sub_reseller_id = ${sid}$ AND resellerid = ${rid}$ AND status = ${st}$',
|
'SELECT id FROM distribution_agreements WHERE sub_reseller_id = ${sid}$ AND resellerid = ${rid}$ AND status = ${st}$',
|
||||||
{'sid': sub_reseller_id, 'rid': userorgid, 'st': '1'}
|
{'sid': sub_reseller_id, 'rid': userorgid, 'st': '1'}
|
||||||
)
|
)
|
||||||
if not recs:
|
if not recs:
|
||||||
# Get sub_reseller name
|
|
||||||
sub = await sor.sqlExe(
|
sub = await sor.sqlExe(
|
||||||
'SELECT sub_reseller_name FROM sub_resellers WHERE id = ${sid}$',
|
'SELECT sub_reseller_name FROM sub_resellers WHERE id = ${sid}$',
|
||||||
{'sid': sub_reseller_id}
|
{'sid': sub_reseller_id}
|
||||||
)
|
)
|
||||||
sub_name = sub[0].sub_reseller_name if sub else 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')}"
|
prefix = f"DA-{datetime.datetime.now().strftime('%Y%m%d')}"
|
||||||
cnt_recs = await sor.sqlExe(
|
cnt_recs = await sor.sqlExe(
|
||||||
'SELECT COUNT(*) as cnt FROM distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$',
|
'SELECT COUNT(*) as cnt FROM distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$',
|
||||||
{'rid': userorgid, 'p': prefix + '%'}
|
{'rid': userorgid, 'p': prefix + '%'}
|
||||||
)
|
)
|
||||||
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||||
agreement_code = f"{prefix}-{seq:04d}"
|
|
||||||
|
|
||||||
now = timestampstr()
|
now = timestampstr()
|
||||||
agreement_id = getID()
|
|
||||||
await sor.C('distribution_agreements', {
|
await sor.C('distribution_agreements', {
|
||||||
'id': agreement_id,
|
'id': getID(), 'resellerid': userorgid, 'sub_reseller_id': sub_reseller_id,
|
||||||
'resellerid': userorgid,
|
'agreement_code': f"{prefix}-{seq:04d}", 'agreement_name': f'{sub_name}分销协议',
|
||||||
'sub_reseller_id': sub_reseller_id,
|
'start_date': curDateString(), 'status': '1', 'default_discount': '1.0000',
|
||||||
'agreement_code': agreement_code,
|
'created_by': userorgid, 'created_at': now, 'updated_at': now,
|
||||||
'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
|
# Redirect to CRUD page
|
||||||
return {
|
request._response_status = 302
|
||||||
'widgettype': 'DataViewer',
|
request._response_headers['Location'] = f'/supplychain/distribution_agreements_list?sub_reseller_id={sub_reseller_id}&_webbricks_=1'
|
||||||
'options': {
|
return ''
|
||||||
'url': f'/supplychain/distribution_agreements_list?sub_reseller_id={sub_reseller_id}&_webbricks_=1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -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')
|
supplier_id = params_kw.get('supplier_id')
|
||||||
if not supplier_id:
|
if not supplier_id:
|
||||||
return {'widgettype': 'Error', 'options': {'title': 'Error', 'message': 'Missing supplier_id', 'timeout': 3}}
|
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
|
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||||
now = timestampstr()
|
now = timestampstr()
|
||||||
await sor.C('supply_contracts', {
|
await sor.C('supply_contracts', {
|
||||||
'id': getID(),
|
'id': getID(), 'resellerid': userorgid, 'supplier_id': supplier_id,
|
||||||
'resellerid': userorgid,
|
'contract_code': f"{prefix}-{seq:04d}", 'contract_name': f'{sup_name}供销协议',
|
||||||
'supplier_id': supplier_id,
|
'start_date': curDateString(), 'status': '1', 'default_discount': '1.0000',
|
||||||
'contract_code': f"{prefix}-{seq:04d}",
|
'created_by': userorgid, 'created_at': now, 'updated_at': now,
|
||||||
'contract_name': f'{sup_name}供销协议',
|
|
||||||
'start_date': curDateString(),
|
|
||||||
'status': '1',
|
|
||||||
'default_discount': '1.0000',
|
|
||||||
'created_by': userorgid,
|
|
||||||
'created_at': now,
|
|
||||||
'updated_at': now,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
# Redirect to CRUD page
|
||||||
'widgettype': 'DataViewer',
|
request._response_status = 302
|
||||||
'options': {
|
request._response_headers['Location'] = f'/supplychain/supply_contracts_list?supplier_id={supplier_id}&_webbricks_=1'
|
||||||
'url': f'/supplychain/supply_contracts_list?supplier_id={supplier_id}&_webbricks_=1'
|
return ''
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user