bugfix
This commit is contained in:
parent
4214f4e2de
commit
d884132d77
Binary file not shown.
@ -1,15 +1,8 @@
|
|||||||
from pricing.pricing import (
|
from pricing.pricing import (
|
||||||
pricing_program_charging,
|
PricingProgram
|
||||||
get_pricing_specs_by_pptid,
|
)
|
||||||
get_all_spec_fields_by_pptid,
|
|
||||||
sor_get_spec_fields,
|
|
||||||
get_spec_names_fields)
|
|
||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
|
|
||||||
def load_pricing():
|
def load_pricing():
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
env.pricing_program_charging = pricing_program_charging
|
env.calculate_prices = PricingProgram.pricing
|
||||||
env.get_pricing_specs_by_pptid = get_pricing_specs_by_pptid
|
|
||||||
env.get_spec_names_fields = get_spec_names_fields
|
|
||||||
env.get_all_spec_fields_by_pptid = get_all_spec_fields_by_pptid
|
|
||||||
env.sor_get_spec_fields = sor_get_spec_fields
|
|
||||||
|
|||||||
@ -139,26 +139,8 @@ def check_value(field, spec_value, data_value):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
class PricingProgram:
|
class PricingProgram:
|
||||||
def parse_pricing_spec(self, yamlstr):
|
@staticmethod
|
||||||
d = yaml.safe_load(yamlstr)
|
def pp_db2app(pp):
|
||||||
assert isinstance(d, list)
|
|
||||||
return d
|
|
||||||
async def add_pricing_program(self, sor,
|
|
||||||
name, ownerid,
|
|
||||||
description, pricing_spec, id=None):
|
|
||||||
env = ServerEnv()
|
|
||||||
if not id:
|
|
||||||
id = env.uuid()
|
|
||||||
yamlstr = yaml.dump(pricing_spec)
|
|
||||||
await sor.C('pricing_program', {
|
|
||||||
'id': id,
|
|
||||||
'name': name,
|
|
||||||
'ownerid': ownerid,
|
|
||||||
'description': description,
|
|
||||||
'pricing_spec': ymalstr
|
|
||||||
})
|
|
||||||
|
|
||||||
async def pp_db2app(self, pp):
|
|
||||||
try:
|
try:
|
||||||
pp.pricing_spec = yaml.safe_load(pp.pricing_spec)
|
pp.pricing_spec = yaml.safe_load(pp.pricing_spec)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -166,14 +148,17 @@ class PricingProgram:
|
|||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
async def pp_app2db(self, pp):
|
@staticmethod
|
||||||
|
def pp_app2db(pp):
|
||||||
try:
|
try:
|
||||||
pp.pricing_spec = yaml.dump(pp.pricing_spec)
|
pp.pricing_spec = yaml.dump(pp.pricing_spec)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
e = f'{pp.pricing_spec}:导出到yaml失败'
|
e = f'{pp.pricing_spec}:导出到yaml失败'
|
||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
async def ppt_db2app(self, ppt):
|
|
||||||
|
@staticmethod
|
||||||
|
def ppt_db2app(ppt):
|
||||||
try:
|
try:
|
||||||
ppt.pricing_data = yaml.safe_load(ppt.pricing_data)
|
ppt.pricing_data = yaml.safe_load(ppt.pricing_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -181,7 +166,8 @@ class PricingProgram:
|
|||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
async def ppt_app2db(self, ppt):
|
@staticmethod
|
||||||
|
def ppt_app2db(ppt):
|
||||||
try:
|
try:
|
||||||
ppt.pricing_data = yaml.dump(ppt.pricing_data)
|
ppt.pricing_data = yaml.dump(ppt.pricing_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -189,7 +175,37 @@ class PricingProgram:
|
|||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
||||||
def pricing(self, config_data, yamlstr):
|
@staticmethod
|
||||||
|
async def pricing(ppid, data):
|
||||||
|
env = ServerEnv()
|
||||||
|
async with get_sor_context(env, 'pricing') as sor:
|
||||||
|
biz_date = await get_business_date(sor)
|
||||||
|
sql = """select a.name, a.ownerid, a.providerid,
|
||||||
|
pricing_belong, discount, b.pricing_data
|
||||||
|
from pricing_program a, pricing_program_timing b
|
||||||
|
where a.id = b.ppid
|
||||||
|
and a.id = ${ppid}$
|
||||||
|
and b.enabled_date <= ${biz_date}$
|
||||||
|
and b.expired_date > ${biz_date}$
|
||||||
|
order by b.enabled_date desc"""
|
||||||
|
recs = await sor.sqlExe(sql, {
|
||||||
|
'ppid': ppid,
|
||||||
|
'biz_date': biz_date
|
||||||
|
})
|
||||||
|
if recs:
|
||||||
|
r = recs[0]
|
||||||
|
r.prices = PricingProgram.get_pricing_from_ymalstr(data, r.pricing_date)
|
||||||
|
debug(f'{r.prices=}')
|
||||||
|
amt = 0.0
|
||||||
|
for p in r.prices:
|
||||||
|
amt += p.amount
|
||||||
|
if r.pricing_belong == 'provider'
|
||||||
|
return amt, amt * r.discount # 售价, 成本
|
||||||
|
return amt, 0
|
||||||
|
return r
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_pricing_from_ymalstr(config_data, yamlstr):
|
||||||
"""
|
"""
|
||||||
yamlstr是从
|
yamlstr是从
|
||||||
d = None
|
d = None
|
||||||
|
|||||||
@ -7,14 +7,14 @@
|
|||||||
"items":[
|
"items":[
|
||||||
{
|
{
|
||||||
"name": "pricing_type",
|
"name": "pricing_type",
|
||||||
"icon": "{{entire_url('/pricing/imgs/pricing_type.svg')}}",
|
"icon": "{{entire_url('/pricing/imgs/pricing_program_timing.svg')}}",
|
||||||
"label": "定价类型",
|
"label": "项目定价",
|
||||||
"url": "{{entire_url('/pricing/pricing_type')}}"
|
"url": "{{entire_url('/pricing/pricing_program_timing')}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pricing_program",
|
"name": "pricing_program",
|
||||||
"icon": "{{entire_url('/pricing/imgs/pricing_program.svg')}}",
|
"icon": "{{entire_url('/pricing/imgs/pricing_program.svg')}}",
|
||||||
"label": "定价项目",
|
"label": "定价项目管理",
|
||||||
"url": "{{entire_url('/pricing/pricing_program')}}"
|
"url": "{{entire_url('/pricing/pricing_program')}}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user