feat: 删除pricing_spec/discount字段; 新增timing拉链逻辑(expired_date自动管理)

This commit is contained in:
yumoqing 2026-07-05 13:51:43 +08:00
parent 5138ec338d
commit ecb4c770c4
6 changed files with 32 additions and 50 deletions

View File

@ -8,17 +8,7 @@
"sortby": "name",
"logined_userorgid": "ownerid",
"browserfields": {
"exclouded": ["id", "ownerid", "pricing_spec" ],
"alters": {
"discount": {
"rules": [
{"type": "required", "message": "折扣不能为空"},
{"type": "number", "message": "折扣必须是数字"},
{"type": "min", "value": 0, "message": "折扣不能小于0"},
{"type": "max", "value": 1, "message": "折扣不能大于1"}
]
}
}
"exclouded": ["id", "ownerid"]
},
"data_filter": {
"AND": [

View File

@ -3,7 +3,8 @@
"title": "定价项目时序",
"params": {
"editable": {
"get_data_url": "{{entire_url('get_pricing_program_timing.dspy')}}"
"get_data_url": "{{entire_url('get_pricing_program_timing.dspy')}}",
"new_data_url": "{{entire_url('../api/add_pricing_program_timing.dspy')}}"
},
"sortby": "enabled_date desc",
"browserfields": {

View File

@ -40,22 +40,10 @@
"type": "str",
"length": 32
},
{
"name": "discount",
"title": "供应商折扣",
"type": "float",
"length": 18,
"dec": 2
},
{
"name": "description",
"title": "描述",
"type": "text"
},
{
"name": "pricing_spec",
"title": "规格明细",
"type": "text"
}
],
"codes": [

View File

@ -3,4 +3,5 @@ from pricing.pricing import (
test_pricing,
generate_formula_from_factors,
get_pricing_display,
add_pricing_program_timing,
)

View File

@ -224,7 +224,7 @@ class PricingProgram:
e = f'pricing_program({pptid}) can not find pricing_program'
exception(f)
pp = pps[0]
pp_spec = yaml.safe_load(pp.pricing_spec)
pp_spec = {} # pricing_spec removed
formula = None
if pp_spec.get('fields'):
fields = pp_spec.get('fields')
@ -266,7 +266,7 @@ class PricingProgram:
if not recs:
debug(f'id={ppid} pricing_program not found')
r = recs[0]
x = DictObject(** yaml.safe_load(r.pricing_spec))
x = DictObject() # pricing_spec removed
fields = x
if x.get('fields'):
fields = x['fields']
@ -292,24 +292,6 @@ class PricingProgram:
fpath = write_pattern_xlsx(recs[0].name, fields, data=data)
return fpath
@staticmethod
def pp_db2app(pp):
try:
pp.pricing_spec = yaml.safe_load(pp.pricing_spec)
except Exception as e:
e = f'{pp.pricing_spec}:yaml数据格式错误'
exception(e)
raise Exception(e)
@staticmethod
def pp_app2db(pp):
try:
pp.pricing_spec = yaml.dump(pp.pricing_spec, allow_unicode=True)
except Exception as e:
e = f'{pp.pricing_spec}:导出到yaml失败'
exception(e)
raise Exception(e)
@staticmethod
def ppt_db2app(ppt):
try:
@ -455,7 +437,7 @@ class PricingProgram:
env = ServerEnv()
async with get_sor_context(env, 'pricing') as sor:
sql = """select a.name, a.ownerid, a.providerid,
pricing_belong, discount, b.pricing_data
pricing_belong, b.pricing_data
from pricing_program a, pricing_program_timing b
where a.id = b.ppid
and a.id = ${ppid}$
@ -489,9 +471,8 @@ class PricingProgram:
prices = PricingProgram.get_pricing_from_ymalstr(data,
r.pricing_data)
amt = 0.0
discount = max(0.0, min(1.0, r.discount)) if r.discount is not None else 1.0
for p in prices:
p.cost = p.amount * discount
p.cost = p.amount # discount removed
return prices
async def charging(sor, ppid, data):
@ -506,7 +487,7 @@ class PricingProgram:
env = ServerEnv()
biz_date = await env.get_business_date(sor)
sql = """select a.name, a.ownerid, a.providerid,
pricing_belong, discount, b.pricing_data
pricing_belong, b.pricing_data
from pricing_program a, pricing_program_timing b
where a.id = b.ppid
and a.id = ${ppid}$
@ -523,9 +504,8 @@ order by b.enabled_date desc"""
r.pricing_data)
debug(f'{r.prices=}')
amt = 0.0
discount = max(0.0, min(1.0, r.discount)) if r.discount is not None else 1.0
for p in r.prices:
p.cost = p.amount * discount
p.cost = p.amount # discount removed
return r.prices
@staticmethod
@ -1030,3 +1010,22 @@ pricings:
p = PricingProgram.get_pricing_from_ymalstr(config_data, yamlstr)
print(f'{p=}')
async def add_pricing_program_timing(env, sor, ns):
"""拉链逻辑:新增定价时序时自动处理 expired_date"""
ppid = ns.get('ppid')
enabled_date = ns.get('enabled_date')
ns['expired_date'] = '9999-12-31'
if ppid and enabled_date:
prev = await sor.R('pricing_program_timing', {'ppid': ppid, 'expired_date': '9999-12-31'})
if prev:
await sor.U('pricing_program_timing', {'id': prev[0].id, 'expired_date': enabled_date})
def load_pricing():
from ahserver.serverenv import ServerEnv
env = ServerEnv()
env.add_pricing_program_timing = add_pricing_program_timing
env.get_pricing_program_timeing = get_pricing_program_timeing
env.test_pricing = test_pricing

View File

@ -0,0 +1,3 @@
# 新增定价项目时序,自动处理拉链逻辑
await add_pricing_program_timing(request._run_ns, sor, params_kw)
return {'status': 'success'}