From 7df8e530a490b9f4e1bea54fc0cbcb9ad7aa781e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 12 Jun 2026 14:41:58 +0800 Subject: [PATCH] remove: pricing_item CRUD and related functions (not used) --- pricing/__init__.py | 3 - pricing/init.py | 7 - pricing/pricing.py | 65 ------ scripts/load_path.py | 10 - wwwroot/pi_get_all_specs.dspy | 1 - wwwroot/pricing_item/add_pricing_item.dspy | 40 ---- wwwroot/pricing_item/delete_pricing_item.dspy | 33 --- wwwroot/pricing_item/get_pricing_item.dspy | 118 ----------- .../pricing_item/get_spec_fields_by_psid.dspy | 6 - wwwroot/pricing_item/index.ui | 198 ------------------ wwwroot/pricing_item/update_pricing_item.dspy | 45 ---- 11 files changed, 526 deletions(-) delete mode 100644 wwwroot/pi_get_all_specs.dspy delete mode 100644 wwwroot/pricing_item/add_pricing_item.dspy delete mode 100644 wwwroot/pricing_item/delete_pricing_item.dspy delete mode 100644 wwwroot/pricing_item/get_pricing_item.dspy delete mode 100644 wwwroot/pricing_item/get_spec_fields_by_psid.dspy delete mode 100644 wwwroot/pricing_item/index.ui delete mode 100644 wwwroot/pricing_item/update_pricing_item.dspy diff --git a/pricing/__init__.py b/pricing/__init__.py index 52a6053..70fa323 100644 --- a/pricing/__init__.py +++ b/pricing/__init__.py @@ -3,7 +3,4 @@ from pricing.pricing import ( test_pricing, generate_formula_from_factors, get_pricing_display, - get_pricing_specs_by_pptid, - sor_get_spec_fields, - get_all_spec_fields_by_pptid, ) diff --git a/pricing/init.py b/pricing/init.py index eecff5a..bbfe0f5 100644 --- a/pricing/init.py +++ b/pricing/init.py @@ -5,9 +5,6 @@ from pricing.pricing import ( test_pricing, generate_formula_from_factors, get_pricing_display, - get_pricing_specs_by_pptid, - sor_get_spec_fields, - get_all_spec_fields_by_pptid, ) from ahserver.serverenv import ServerEnv @@ -40,9 +37,6 @@ def load_pricing(): env.test_pricing = test_pricing env.generate_formula_from_factors = generate_formula_from_factors env.get_pricing_display = get_pricing_display - env.get_pricing_specs_by_pptid = get_pricing_specs_by_pptid - env.sor_get_spec_fields = sor_get_spec_fields - env.get_all_spec_fields_by_pptid = get_all_spec_fields_by_pptid # Bind hot_reload event — only when running in ahserver (event_dispatcher available) if getattr(env, 'event_dispatcher', None) is not None: env.event_dispatcher.bind('hot_reload', PricingProgram.on_hot_reload) @@ -53,4 +47,3 @@ def load_pricing(): debug(f'Pricing event listeners bound for database: {dbname}') else: debug('Pricing event listeners skipped: no database configured for pricing module') - diff --git a/pricing/pricing.py b/pricing/pricing.py index a2209dd..df5da92 100644 --- a/pricing/pricing.py +++ b/pricing/pricing.py @@ -982,71 +982,6 @@ async def test_pricing(pptid, data): amount += p.amount return amount -async def get_pricing_specs_by_pptid(pptid): - """Get all pricing_spec records associated with a pricing_program_timing.""" - if not pptid: - return [] - env = ServerEnv() - async with get_sor_context(env, 'pricing') as sor: - recs = await sor.sqlExe( - "SELECT DISTINCT s.* FROM pricing_spec s " - "INNER JOIN pricing_item pi ON pi.psid = s.id " - "WHERE pi.pptid = ${pptid}$", - {'pptid': pptid} - ) - return list(recs) - - -async def sor_get_spec_fields(sor, item_id): - """Get spec field names for a pricing_item by looking up its psid.""" - if not item_id: - return [] - recs = await sor.R('pricing_item', {'id': item_id}) - if not recs or not recs[0].psid: - return [] - spec_recs = await sor.R('pricing_spec', {'id': recs[0].psid}) - if not spec_recs or not spec_recs[0].spec_names: - return [] - try: - spec_data = json.loads(spec_recs[0].spec_names) - if isinstance(spec_data, list): - return [f['name'] for f in spec_data if isinstance(f, dict) and 'name' in f] - except (json.JSONDecodeError, TypeError, KeyError): - pass - return [] - - -async def get_all_spec_fields_by_pptid(request, pptid): - """Template function: returns JSON string of dynamic field definitions - from pricing_spec.spec_names for all specs linked to the given pptid. - Used in index.ui to inject extra fields into the fields array.""" - if not pptid: - return '' - env = ServerEnv() - async with get_sor_context(env, 'pricing') as sor: - specs = await sor.sqlExe( - "SELECT DISTINCT s.spec_names FROM pricing_spec s " - "INNER JOIN pricing_item pi ON pi.psid = s.id " - "WHERE pi.pptid = ${pptid}$ AND s.spec_names IS NOT NULL AND s.spec_names != ''", - {'pptid': pptid} - ) - all_fields = [] - seen = set() - for spec in specs: - try: - fields = json.loads(spec.spec_names) - if isinstance(fields, list): - for f in fields: - if isinstance(f, dict) and 'name' in f and f['name'] not in seen: - seen.add(f['name']) - all_fields.append(f) - except (json.JSONDecodeError, TypeError): - continue - if not all_fields: - return '' - return ',\n'.join(json.dumps(f, ensure_ascii=False) for f in all_fields) - - if __name__ == '__main__': MyLogger('Pricing', levelname='info') yamlstr = """fields: diff --git a/scripts/load_path.py b/scripts/load_path.py index bc6ec2f..76d746b 100644 --- a/scripts/load_path.py +++ b/scripts/load_path.py @@ -59,7 +59,6 @@ PATHS_LOGINED = [ f"/{MOD}/download_pricing_pattern.dspy", f"/{MOD}/get_all_pricing_programs.dspy", f"/{MOD}/get_platform_providers.dspy", - f"/{MOD}/pi_get_all_specs.dspy", f"/{MOD}/test_pricing_program.dspy", f"/{MOD}/upload_pricing_data.dspy", @@ -81,15 +80,6 @@ PATHS_LOGINED = [ f"/{MOD}/pricing_program_timing/add_pricing_program_timing.dspy", f"/{MOD}/pricing_program_timing/update_pricing_program_timing.dspy", f"/{MOD}/pricing_program_timing/delete_pricing_program_timing.dspy", - - # CRUD: pricing_item (git-tracked) - f"/{MOD}/pricing_item", - f"/{MOD}/pricing_item/index.ui", - f"/{MOD}/pricing_item/get_pricing_item.dspy", - f"/{MOD}/pricing_item/get_spec_fields_by_psid.dspy", - f"/{MOD}/pricing_item/add_pricing_item.dspy", - f"/{MOD}/pricing_item/update_pricing_item.dspy", - f"/{MOD}/pricing_item/delete_pricing_item.dspy", ] # ============================================================ diff --git a/wwwroot/pi_get_all_specs.dspy b/wwwroot/pi_get_all_specs.dspy deleted file mode 100644 index 093fea7..0000000 --- a/wwwroot/pi_get_all_specs.dspy +++ /dev/null @@ -1 +0,0 @@ -return await get_pricing_specs_by_pptid(params_kw.pptid) diff --git a/wwwroot/pricing_item/add_pricing_item.dspy b/wwwroot/pricing_item/add_pricing_item.dspy deleted file mode 100644 index 0a0df04..0000000 --- a/wwwroot/pricing_item/add_pricing_item.dspy +++ /dev/null @@ -1,40 +0,0 @@ - -ns = params_kw.copy() -for k,v in ns.items(): - if v == 'NaN' or v == 'null': - ns[k] = None -id = params_kw.id -if not id or len(id) > 32: - id = uuid() -ns['id'] = id - -db = DBPools() -dbname = get_module_dbname('pricing') -async with db.sqlorContext(dbname) as sor: - fs = await sor_get_spec_fields(sor, ns.id) - if len(fs): - ns1 = {k:ns[k] for k in fs} - ns.spec_value = json.dumps(ns1) - r = await sor.C('pricing_item', ns.copy()) - return { - "widgettype":"Message", - "options":{ - "user_data":ns, - "cwidth":16, - "cheight":9, - "title":"Add Success", - "timeout":3, - "message":"ok" - } - } - -return { - "widgettype":"Error", - "options":{ - "title":"Add Error", - "cwidth":16, - "cheight":9, - "timeout":3, - "message":"failed" - } -} diff --git a/wwwroot/pricing_item/delete_pricing_item.dspy b/wwwroot/pricing_item/delete_pricing_item.dspy deleted file mode 100644 index 063cc4e..0000000 --- a/wwwroot/pricing_item/delete_pricing_item.dspy +++ /dev/null @@ -1,33 +0,0 @@ - -ns = { - 'id':params_kw['id'], -} - - -db = DBPools() -dbname = get_module_dbname('pricing') -async with db.sqlorContext(dbname) as sor: - r = await sor.D('pricing_item', ns) - debug('delete success'); - return { - "widgettype":"Message", - "options":{ - "title":"Delete Success", - "timeout":3, - "cwidth":16, - "cheight":9, - "message":"ok" - } - } - -debug('Delete failed'); -return { - "widgettype":"Error", - "options":{ - "title":"Delete Error", - "timeout":3, - "cwidth":16, - "cheight":9, - "message":"failed" - } -} \ No newline at end of file diff --git a/wwwroot/pricing_item/get_pricing_item.dspy b/wwwroot/pricing_item/get_pricing_item.dspy deleted file mode 100644 index 8471e1b..0000000 --- a/wwwroot/pricing_item/get_pricing_item.dspy +++ /dev/null @@ -1,118 +0,0 @@ - -ns = params_kw.copy() - - -debug(f'get_pricing_item.dspy:{ns=}') -if not ns.get('page'): - ns['page'] = 1 -if not ns.get('sort'): - - - ns['sort'] = 'name' - - - -sql = '''select a.*, b.pptid_text, c.psid_text, d.subppid_text -from (select * from pricing_item where 1=1 [[filterstr]]) a left join (select id as pptid, - id as pptid_text from pricing_program_timing where 1 = 1) b on a.pptid = b.pptid left join (select id as psid, - name as psid_text from pricing_spec where 1 = 1) c on a.psid = c.psid left join (select id as subppid, - name as subppid_text from pricing_program where 1 = 1) d on a.subppid = d.subppid''' - -filterjson = params_kw.get('data_filter') -if not filterjson: - fields = [ f['name'] for f in [ - { - "name": "id", - "title": "id", - "type": "str", - "length": 32 - }, - { - "name": "name", - "title": "定价项名", - "type": "str", - "length": 256 - }, - { - "name": "description", - "title": "描述", - "type": "text" - }, - { - "name": "pptid", - "title": "项目id", - "type": "str", - "length": 32 - }, - { - "name": "psid", - "title": "定价规格id", - "type": "str", - "length": 32 - }, - { - "name": "subppid", - "title": "子项目id", - "type": "str", - "length": 32, - "nullable": "yes" - }, - { - "name": "spec_value", - "title": "规格值", - "type": "text" - }, - { - "name": "pricing_unit", - "title": "定价单位", - "type": "float", - "length": 18, - "dec": 5 - }, - { - "name": "pricing_amount", - "title": "定价金额", - "type": "float", - "length": 18, - "dec": 5 - }, - { - "name": "cost_amount", - "title": "成本金额", - "type": "float", - "length": 18, - "dec": 5 - } -] ] - filterjson = default_filterjson(fields, ns) -filterdic = ns.copy() -filterdic['filterstr'] = '' -filterdic['userorgid'] = '${userorgid}$' -filterdic['userid'] = '${userid}$' -if filterjson: - dbf = DBFilter(filterjson) - conds = dbf.gen(ns) - if conds: - ns.update(dbf.consts) - conds = f' and {conds}' - filterdic['filterstr'] = conds -ac = ArgsConvert('[[', ']]') -vars = ac.findAllVariables(sql) -NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } -filterdic.update(NameSpace) -sql = ac.convert(sql, filterdic) - -debug(f'{sql=}') -db = DBPools() -dbname = get_module_dbname('pricing') -async with db.sqlorContext(dbname) as sor: - r = await sor.sqlPaging(sql, ns) - for d in r['rows']: - if d.spec_value: - ad = json.loads(d.spec_value) - d.update(ad) - return r -return { - "total":0, - "rows":[] -} diff --git a/wwwroot/pricing_item/get_spec_fields_by_psid.dspy b/wwwroot/pricing_item/get_spec_fields_by_psid.dspy deleted file mode 100644 index d3b904b..0000000 --- a/wwwroot/pricing_item/get_spec_fields_by_psid.dspy +++ /dev/null @@ -1,6 +0,0 @@ -id = params_kw.id -async with get_sor_context(request._run_ns, 'pricing') as sor: - recs = await sor.R('pricing_spec', {'id': id}) - if len(recs): - return recs.spec_names -return [] diff --git a/wwwroot/pricing_item/index.ui b/wwwroot/pricing_item/index.ui deleted file mode 100644 index 9ef422a..0000000 --- a/wwwroot/pricing_item/index.ui +++ /dev/null @@ -1,198 +0,0 @@ -{ - "widgettype": "VBox", - "options": { - "css": "filler", "height": "100%", - "width": "100%" - }, - "subwidgets": [ -{ - "id":"pricing_item_tbl", - "widgettype":"Tabular", - "options":{ - "width":"100%", - "height":"100%", - - - "title":"项目定价项", - - - - - "css":"card", - - - "editable":{ - - "new_data_url":"{{entire_url('add_pricing_item.dspy')}}", - - - "delete_data_url":"{{entire_url('delete_pricing_item.dspy')}}", - - - "update_data_url":"{{entire_url('update_pricing_item.dspy')}}" - - }, - - - "data_url":"{{entire_url('./get_pricing_item.dspy')}}", - - "data_method":"GET", - "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, - "row_options":{ - "browserfields": { - "exclouded": [ - "id", - "pptid" - ], - "alters": { - "psid": { - "dataurl": "{{entire_url('../pi_get_all_specs.dspy')}}", - "textField": "name", - "valueField": "id", - "params": { - "pptid": "{{params_kw.pptid}}" - } - } - } -}, - "editexclouded":[ - "id", - "pptid" -], - - "fields":[ - { - "name": "id", - "title": "id", - "type": "str", - "length": 32, - "cwidth": 18, - "uitype": "str", - "datatype": "str", - "label": "id" - }, - { - "name": "name", - "title": "定价项名", - "type": "str", - "length": 256, - "cwidth": 18, - "uitype": "str", - "datatype": "str", - "label": "定价项名" - }, - { - "name": "description", - "title": "描述", - "type": "text", - "length": 0, - "uitype": "text", - "datatype": "text", - "label": "描述" - }, - { - "name": "pptid", - "title": "项目id", - "type": "str", - "length": 32, - "label": "项目id", - "uitype": "code", - "valueField": "pptid", - "textField": "pptid_text", - "params": { - "dbname": "{{get_module_dbname('pricing')}}", - "table": "pricing_program_timing", - "tblvalue": "id", - "tbltext": "id", - "valueField": "pptid", - "textField": "pptid_text" - }, - "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" - }, - { - "name": "psid", - "title": "定价规格id", - "type": "str", - "length": 32, - "label": "定价规格id", - "uitype": "code", - "valueField": "id", - "textField": "name", - "params": { - "pptid": "{{params_kw.pptid}}" - }, - "dataurl": "{{entire_url('../pi_get_all_specs.dspy')}}" - }, - { - "name": "subppid", - "title": "子项目id", - "type": "str", - "length": 32, - "nullable": "yes", - "label": "子项目id", - "uitype": "code", - "valueField": "subppid", - "textField": "subppid_text", - "params": { - "dbname": "{{get_module_dbname('pricing')}}", - "table": "pricing_program", - "tblvalue": "id", - "tbltext": "name", - "valueField": "subppid", - "textField": "subppid_text" - }, - "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" - }, - { - "name": "pricing_unit", - "title": "定价单位", - "type": "float", - "length": 18, - "dec": 5, - "cwidth": 18, - "uitype": "float", - "datatype": "float", - "label": "定价单位" - }, - { - "name": "pricing_amount", - "title": "定价金额", - "type": "float", - "length": 18, - "dec": 5, - "cwidth": 18, - "uitype": "float", - "datatype": "float", - "label": "定价金额" - }, - { - "name": "cost_amount", - "title": "成本金额", - "type": "float", - "length": 18, - "dec": 5, - "cwidth": 18, - "uitype": "float", - "datatype": "float", - "label": "成本金额" - } - {{get_all_spec_fields_by_pptid(request, params_kw.pptid)}} -] - }, - "page_rows":160, - "cache_limit":5 - } - - ,"binds":[ - { - "wid":"psid", - "event":"changed", - "actiontype":"script", - "target":"self", - "script":"this.hide_field(params.psid);" - } - ] - -} - ] -} diff --git a/wwwroot/pricing_item/update_pricing_item.dspy b/wwwroot/pricing_item/update_pricing_item.dspy deleted file mode 100644 index 4399d93..0000000 --- a/wwwroot/pricing_item/update_pricing_item.dspy +++ /dev/null @@ -1,45 +0,0 @@ - -ns = params_kw.copy() -for k,v in ns.items(): - if v == 'NaN' or v == 'null': - ns[k] = None - - - - -db = DBPools() -dbname = get_module_dbname('pricing') -async with db.sqlorContext(dbname) as sor: - ori = await sor.R('pricing_item', {'id': ns.id}) - ori_sv = {} - if ori.spec_value: - ori_sv = json.loads(ori.spec_value) - fs = await sor_get_spec_fields(sor, ns.id) - if len(fs): - new_sv = {k:ns[k] for k in fs} - if new_sv: - ori_sv.update(new_sv) - ns.spec_value = json.dumps(ori_sv, indent=4) - r = await sor.U('pricing_item', ns.copy()) - debug('update success, {ns=}'); - return { - "widgettype":"Message", - "options":{ - "title":"Update Success", - "cwidth":16, - "cheight":9, - "timeout":3, - "message":"ok" - } - } - -return { - "widgettype":"Error", - "options":{ - "title":"Update Error", - "cwidth":16, - "cheight":9, - "timeout":3, - "message":"failed" - } -}