feat: 供销合同和分销协议补回附件管理功能

- xls2ui 重新生成 index.ui,包含合同附件 toolbar 按钮和 popup bind
- 添加 contract_attach.svg 图标
- 更新 CRUD dspy 文件
This commit is contained in:
yumoqing 2026-07-14 12:06:49 +08:00
parent bc46774401
commit 14d03375b2
9 changed files with 86 additions and 165 deletions

View File

@ -24,21 +24,6 @@ if not userorgid:
} }
ns['resellerid'] = userorgid ns['resellerid'] = userorgid
# Auto-generate agreement_code if not provided
if not ns.get('agreement_code'):
from datetime import datetime as _dt
_prefix = f"DA-{_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 distribution_agreements WHERE resellerid = ${rid}$ AND agreement_code LIKE ${p}$",
{"rid": userorgid, "p": _prefix + "%"}
)
_seq = (_recs[0].cnt if _recs else 0) + 1
ns['agreement_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:
@ -46,6 +31,7 @@ async with db.sqlorContext(dbname) as sor:
return { return {
"widgettype":"Message", "widgettype":"Message",
"options":{ "options":{
"user_data":ns,
"cwidth":16, "cwidth":16,
"cheight":9, "cheight":9,
"title":"Add Success", "title":"Add Success",
@ -63,4 +49,4 @@ return {
"timeout":3, "timeout":3,
"message":"failed" "message":"failed"
} }
} }

View File

@ -21,8 +21,6 @@ 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 agreement items first
await sor.D('distribution_agreement_items', {'agreement_id': ns['id']})
r = await sor.D('distribution_agreements', ns) r = await sor.D('distribution_agreements', ns)
debug('delete success'); debug('delete success');
return { return {

View File

@ -33,12 +33,8 @@ from (select * from distribution_agreements where 1=1 [[filterstr]]) a left join
orgname as resellerid_text from organization where 1 = 1) c on a.resellerid = c.resellerid''' orgname as resellerid_text from organization where 1 = 1) c on a.resellerid = c.resellerid'''
filterjson = params_kw.get('data_filter') filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str): if not filterjson:
try: fields = [ f['name'] for f in [
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{ {
"name": "id", "name": "id",
"title": "主键ID", "title": "主键ID",
@ -128,22 +124,8 @@ fields_str=r'''[
"title": "更新时间", "title": "更新时间",
"type": "datetime" "type": "datetime"
} }
]''' ] ]
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns) filterjson = default_filterjson(fields, ns)
# 确保 logined 过滤条件始终生效
if filterjson:
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
filterjson = {'AND': [filterjson] if filterjson else []}
filterjson['AND'].append({'field': 'resellerid', 'op': '=', 'var': '__logined_orgid__'})
ns['__logined_orgid__'] = userorgid
filterdic = ns.copy() filterdic = ns.copy()
filterdic['filterstr'] = '' filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$' filterdic['userorgid'] = '${userorgid}$'

View File

@ -1,12 +1,10 @@
{ {
"widgettype":"VBox",
"options":{"width":"100%"},
"subwidgets":[{
"id":"distribution_agreements_tbl", "id":"distribution_agreements_tbl",
"widgettype":"Tabular", "widgettype":"Tabular",
"options":{ "options":{
"width":"100%", "width":"100%",
"height":"100%",
"title":"分销协议表", "title":"分销协议表",
@ -21,6 +19,12 @@
"name": "distribution_agreement_items", "name": "distribution_agreement_items",
"icon": "{{entire_url('/imgs/distribution_agreement_items.svg')}}", "icon": "{{entire_url('/imgs/distribution_agreement_items.svg')}}",
"label": "产品分销折扣" "label": "产品分销折扣"
},
{
"selected_row": true,
"name": "contract_attach",
"icon": "{{entire_url('/imgs/contract_attach.svg')}}",
"label": "合同附件"
} }
] ]
}, },
@ -30,18 +34,18 @@
"editable":{ "editable":{
"new_data_url":"{{entire_url('/supplychain/api/distribution_agreements_create.dspy')}}", "new_data_url":"{{entire_url('add_distribution_agreements.dspy')}}",
"delete_data_url":"{{entire_url('/supplychain/api/distribution_agreements_delete.dspy')}}", "delete_data_url":"{{entire_url('delete_distribution_agreements.dspy')}}",
"update_data_url":"{{entire_url('/supplychain/api/distribution_agreements_update.dspy')}}" "update_data_url":"{{entire_url('update_distribution_agreements.dspy')}}"
}, },
"data_url":"{{entire_url('/supplychain/distribution_agreements_list/get_distribution_agreements.dspy')}}", "data_url":"{{entire_url('./get_distribution_agreements.dspy')}}",
"data_method":"GET", "data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
@ -275,42 +279,6 @@
"data_filter":{
"AND": [
{
"field": "agreement_name",
"op": "LIKE",
"var": "agreement_name"
},
{
"field": "agreement_code",
"op": "LIKE",
"var": "agreement_code"
},
{
"field": "sub_reseller_id",
"op": "=",
"var": "sub_reseller_id"
},
{
"field": "status",
"op": "=",
"var": "status"
}
]
},
"filter_labels":{
"agreement_name": "协议名称",
"agreement_code": "协议编号",
"sub_reseller_id": "二级分销商",
"status": "状态"
},
"page_rows":160, "page_rows":160,
"cache_limit":5 "cache_limit":5
} }
@ -340,8 +308,33 @@
"params": {}, "params": {},
"url": "{{entire_url('/supplychain/agreement_discount_setting.ui')}}" "url": "{{entire_url('/supplychain/agreement_discount_setting.ui')}}"
} }
},
{
"wid": "self",
"event": "contract_attach",
"actiontype": "urlwidget",
"target": "PopupWindow",
"popup_options": {
"title": "合同附件",
"icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=contract_attach",
"resizable": true,
"height": "70%",
"width": "70%"
},
"params_mapping": {
"mapping": {
"id": "contract_id",
"referer_widget": "referer_widget",
"contract_id": "id"
},
"need_other": false
},
"options": {
"method": "POST",
"params": {},
"url": "{{entire_url('/supplychain/api/contract_attach.ui')}}?contract_type=distribution"
}
} }
] ]
}]
} }

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/>
</svg>

After

Width:  |  Height:  |  Size: 294 B

View File

@ -24,21 +24,6 @@ if not userorgid:
} }
ns['resellerid'] = userorgid ns['resellerid'] = userorgid
# Auto-generate contract_code if not provided
if not ns.get('contract_code'):
_today = curDateString().replace('-', '')
_prefix = f"SC-{_today}"
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:
@ -46,6 +31,7 @@ async with db.sqlorContext(dbname) as sor:
return { return {
"widgettype":"Message", "widgettype":"Message",
"options":{ "options":{
"user_data":ns,
"cwidth":16, "cwidth":16,
"cheight":9, "cheight":9,
"title":"Add Success", "title":"Add Success",

View File

@ -21,8 +21,6 @@ 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 {

View File

@ -33,12 +33,8 @@ from (select * from supply_contracts where 1=1 [[filterstr]]) a left join (selec
orgname as resellerid_text from organization where 1 = 1) c on a.resellerid = c.resellerid''' orgname as resellerid_text from organization where 1 = 1) c on a.resellerid = c.resellerid'''
filterjson = params_kw.get('data_filter') filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str): if not filterjson:
try: fields = [ f['name'] for f in [
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{ {
"name": "id", "name": "id",
"title": "主键ID", "title": "主键ID",
@ -128,22 +124,8 @@ fields_str=r'''[
"title": "更新时间", "title": "更新时间",
"type": "datetime" "type": "datetime"
} }
]''' ] ]
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns) filterjson = default_filterjson(fields, ns)
# 确保 logined 过滤条件始终生效
if filterjson:
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
filterjson = {'AND': [filterjson] if filterjson else []}
filterjson['AND'].append({'field': 'resellerid', 'op': '=', 'var': '__logined_orgid__'})
ns['__logined_orgid__'] = userorgid
filterdic = ns.copy() filterdic = ns.copy()
filterdic['filterstr'] = '' filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$' filterdic['userorgid'] = '${userorgid}$'

View File

@ -1,12 +1,10 @@
{ {
"widgettype":"VBox",
"options":{"width":"100%"},
"subwidgets":[{
"id":"supply_contracts_tbl", "id":"supply_contracts_tbl",
"widgettype":"Tabular", "widgettype":"Tabular",
"options":{ "options":{
"width":"100%", "width":"100%",
"height":"100%",
"title":"供销合同表", "title":"供销合同表",
@ -21,6 +19,12 @@
"name": "supply_contract_items", "name": "supply_contract_items",
"icon": "{{entire_url('/imgs/supply_contract_items.svg')}}", "icon": "{{entire_url('/imgs/supply_contract_items.svg')}}",
"label": "产品折扣明细" "label": "产品折扣明细"
},
{
"selected_row": true,
"name": "contract_attach",
"icon": "{{entire_url('/imgs/contract_attach.svg')}}",
"label": "合同附件"
} }
] ]
}, },
@ -30,18 +34,18 @@
"editable":{ "editable":{
"new_data_url":"{{entire_url('/supplychain/api/supply_contracts_create.dspy')}}", "new_data_url":"{{entire_url('add_supply_contracts.dspy')}}",
"delete_data_url":"{{entire_url('/supplychain/api/supply_contracts_delete.dspy')}}", "delete_data_url":"{{entire_url('delete_supply_contracts.dspy')}}",
"update_data_url":"{{entire_url('/supplychain/api/supply_contracts_update.dspy')}}" "update_data_url":"{{entire_url('update_supply_contracts.dspy')}}"
}, },
"data_url":"{{entire_url('/supplychain/supply_contracts_list/get_supply_contracts.dspy')}}", "data_url":"{{entire_url('./get_supply_contracts.dspy')}}",
"data_method":"GET", "data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
@ -275,42 +279,6 @@
"data_filter":{
"AND": [
{
"field": "contract_name",
"op": "LIKE",
"var": "contract_name"
},
{
"field": "contract_code",
"op": "LIKE",
"var": "contract_code"
},
{
"field": "supplier_id",
"op": "=",
"var": "supplier_id"
},
{
"field": "status",
"op": "=",
"var": "status"
}
]
},
"filter_labels":{
"contract_name": "合同名称",
"contract_code": "合同编号",
"supplier_id": "供应商",
"status": "状态"
},
"page_rows":160, "page_rows":160,
"cache_limit":5 "cache_limit":5
} }
@ -340,8 +308,33 @@
"params": {}, "params": {},
"url": "{{entire_url('/supplychain/contract_discount_setting.ui')}}" "url": "{{entire_url('/supplychain/contract_discount_setting.ui')}}"
} }
},
{
"wid": "self",
"event": "contract_attach",
"actiontype": "urlwidget",
"target": "PopupWindow",
"popup_options": {
"title": "合同附件",
"icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=contract_attach",
"resizable": true,
"height": "70%",
"width": "70%"
},
"params_mapping": {
"mapping": {
"id": "contract_id",
"referer_widget": "referer_widget",
"contract_id": "id"
},
"need_other": false
},
"options": {
"method": "POST",
"params": {},
"url": "{{entire_url('/supplychain/api/contract_attach.ui')}}?contract_type=supply"
}
} }
] ]
}]
} }