fix: fix column name + ensure dspy now returns CRUD page after create
- sub_resellers column is sub_reseller_name (not sub_dist_name) - After ensure, return UrlWidget loading CRUD list filtered by id - Popup size increased for CRUD page viewing
This commit is contained in:
parent
7fa70b9a24
commit
0c718cf461
@ -1,4 +1,4 @@
|
|||||||
"""Check if a distribution_agreement exists for sub_reseller_id. If not, create one."""
|
"""Check/create distribution_agreement for sub_reseller_id, then show 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}}
|
||||||
@ -11,59 +11,48 @@ dbname = get_module_dbname('supplychain')
|
|||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
# Check existing
|
# Check existing
|
||||||
recs = await sor.sqlExe(
|
recs = await sor.sqlExe(
|
||||||
'SELECT id, agreement_code, agreement_name 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 recs:
|
if not recs:
|
||||||
r = recs[0]
|
# Get sub_reseller name
|
||||||
return {
|
sub = await sor.sqlExe(
|
||||||
'widgettype': 'Message',
|
'SELECT sub_reseller_name FROM sub_resellers WHERE id = ${sid}$',
|
||||||
'options': {
|
{'sid': sub_reseller_id}
|
||||||
'title': '协议已存在',
|
)
|
||||||
'message': f'分销协议 {r.agreement_code} {r.agreement_name} 已存在',
|
sub_name = sub[0].sub_reseller_name if sub else sub_reseller_id
|
||||||
'type': 'success',
|
|
||||||
'timeout': 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get sub_reseller info for name
|
# Generate agreement_code
|
||||||
sub = await sor.sqlExe(
|
prefix = f"DA-{datetime.datetime.now().strftime('%Y%m%d')}"
|
||||||
'SELECT sub_dist_name FROM sub_resellers WHERE id = ${sid}$',
|
cnt_recs = await sor.sqlExe(
|
||||||
{'sid': sub_reseller_id}
|
'SELECT COUNT(*) as cnt FROM distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$',
|
||||||
)
|
{'rid': userorgid, 'p': prefix + '%'}
|
||||||
sub_name = sub[0].sub_dist_name if sub else sub_reseller_id
|
)
|
||||||
|
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||||
|
agreement_code = f"{prefix}-{seq:04d}"
|
||||||
|
|
||||||
# Generate agreement_code
|
now = timestampstr()
|
||||||
prefix = f"DA-{datetime.datetime.now().strftime('%Y%m%d')}"
|
agreement_id = getID()
|
||||||
cnt_recs = await sor.sqlExe(
|
await sor.C('distribution_agreements', {
|
||||||
'SELECT COUNT(*) as cnt FROM distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$',
|
'id': agreement_id,
|
||||||
{'rid': userorgid, 'p': prefix + '%'}
|
'resellerid': userorgid,
|
||||||
)
|
'sub_reseller_id': sub_reseller_id,
|
||||||
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
'agreement_code': agreement_code,
|
||||||
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,
|
||||||
|
})
|
||||||
|
|
||||||
now = timestampstr()
|
# Return CRUD page embedded in popup
|
||||||
agreement_id = getID()
|
return {
|
||||||
await sor.C('distribution_agreements', {
|
'widgettype': 'UrlWidget',
|
||||||
'id': agreement_id,
|
'options': {
|
||||||
'resellerid': userorgid,
|
'url': f'../distribution_agreements_list?sub_reseller_id={sub_reseller_id}',
|
||||||
'sub_reseller_id': sub_reseller_id,
|
'width': '100%',
|
||||||
'agreement_code': agreement_code,
|
'height': '100%'
|
||||||
'agreement_name': f'{sub_name}分销协议',
|
|
||||||
'start_date': curDateString(),
|
|
||||||
'status': '1',
|
|
||||||
'default_discount': '1.0000',
|
|
||||||
'created_by': userorgid,
|
|
||||||
'created_at': now,
|
|
||||||
'updated_at': now,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
'widgettype': 'Message',
|
|
||||||
'options': {
|
|
||||||
'title': '创建成功',
|
|
||||||
'message': f'已为{sub_name}创建分销协议 {agreement_code}',
|
|
||||||
'type': 'success',
|
|
||||||
'timeout': 5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
"""Check if a supply_contract exists for supplier_id. If not, create one."""
|
"""Check/create supply_contract for supplier_id, then show 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}}
|
||||||
@ -11,59 +11,48 @@ dbname = get_module_dbname('supplychain')
|
|||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
# Check existing
|
# Check existing
|
||||||
recs = await sor.sqlExe(
|
recs = await sor.sqlExe(
|
||||||
'SELECT id, contract_code, contract_name FROM supply_contracts WHERE supplier_id = ${sid}$ AND resellerid = ${rid}$ AND status = ${st}$',
|
'SELECT id FROM supply_contracts WHERE supplier_id = ${sid}$ AND resellerid = ${rid}$ AND status = ${st}$',
|
||||||
{'sid': supplier_id, 'rid': userorgid, 'st': '1'}
|
{'sid': supplier_id, 'rid': userorgid, 'st': '1'}
|
||||||
)
|
)
|
||||||
if recs:
|
if not recs:
|
||||||
r = recs[0]
|
# Get supplier name
|
||||||
return {
|
sub = await sor.sqlExe(
|
||||||
'widgettype': 'Message',
|
'SELECT supplier_name FROM suppliers WHERE id = ${sid}$',
|
||||||
'options': {
|
{'sid': supplier_id}
|
||||||
'title': '协议已存在',
|
)
|
||||||
'message': f'供销协议 {r.contract_code} {r.contract_name} 已存在',
|
sup_name = sub[0].supplier_name if sub else supplier_id
|
||||||
'type': 'success',
|
|
||||||
'timeout': 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get supplier name
|
# Generate contract_code
|
||||||
sub = await sor.sqlExe(
|
prefix = f"SC-{datetime.datetime.now().strftime('%Y%m%d')}"
|
||||||
'SELECT supplier_name FROM suppliers WHERE id = ${sid}$',
|
cnt_recs = await sor.sqlExe(
|
||||||
{'sid': supplier_id}
|
'SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$',
|
||||||
)
|
{'rid': userorgid, 'p': prefix + '%'}
|
||||||
sup_name = sub[0].supplier_name if sub else supplier_id
|
)
|
||||||
|
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
||||||
|
contract_code = f"{prefix}-{seq:04d}"
|
||||||
|
|
||||||
# Generate contract_code
|
now = timestampstr()
|
||||||
prefix = f"SC-{datetime.datetime.now().strftime('%Y%m%d')}"
|
contract_id = getID()
|
||||||
cnt_recs = await sor.sqlExe(
|
await sor.C('supply_contracts', {
|
||||||
'SELECT COUNT(*) as cnt FROM supply_contracts WHERE resellerid = ${rid}$ AND contract_code LIKE ${p}$',
|
'id': contract_id,
|
||||||
{'rid': userorgid, 'p': prefix + '%'}
|
'resellerid': userorgid,
|
||||||
)
|
'supplier_id': supplier_id,
|
||||||
seq = (cnt_recs[0].cnt if cnt_recs else 0) + 1
|
'contract_code': contract_code,
|
||||||
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,
|
||||||
|
})
|
||||||
|
|
||||||
now = timestampstr()
|
# Return CRUD page embedded in popup
|
||||||
contract_id = getID()
|
return {
|
||||||
await sor.C('supply_contracts', {
|
'widgettype': 'UrlWidget',
|
||||||
'id': contract_id,
|
'options': {
|
||||||
'resellerid': userorgid,
|
'url': f'../supply_contracts_list?supplier_id={supplier_id}',
|
||||||
'supplier_id': supplier_id,
|
'width': '100%',
|
||||||
'contract_code': contract_code,
|
'height': '100%'
|
||||||
'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': 'Message',
|
|
||||||
'options': {
|
|
||||||
'title': '创建成功',
|
|
||||||
'message': f'已为{sup_name}创建供销协议 {contract_code}',
|
|
||||||
'type': 'success',
|
|
||||||
'timeout': 5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -325,8 +325,8 @@
|
|||||||
"target": "PopupWindow",
|
"target": "PopupWindow",
|
||||||
"popup_options": {
|
"popup_options": {
|
||||||
"title": "分销协议",
|
"title": "分销协议",
|
||||||
"height": "200px",
|
"height": "80%",
|
||||||
"width": "400px"
|
"width": "85%"
|
||||||
},
|
},
|
||||||
"params_mapping": {
|
"params_mapping": {
|
||||||
"mapping": {"id": "sub_reseller_id"},
|
"mapping": {"id": "sub_reseller_id"},
|
||||||
|
|||||||
@ -457,8 +457,8 @@
|
|||||||
"target": "PopupWindow",
|
"target": "PopupWindow",
|
||||||
"popup_options": {
|
"popup_options": {
|
||||||
"title": "供销协议",
|
"title": "供销协议",
|
||||||
"height": "200px",
|
"height": "80%",
|
||||||
"width": "400px"
|
"width": "85%"
|
||||||
},
|
},
|
||||||
"params_mapping": {
|
"params_mapping": {
|
||||||
"mapping": {"id": "supplier_id"},
|
"mapping": {"id": "supplier_id"},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user