bugfix
This commit is contained in:
parent
a7afc0f834
commit
896c87c4f0
@ -9,6 +9,7 @@ def load_pricing():
|
|||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
env.get_pricing_program = get_pricing_program
|
env.get_pricing_program = get_pricing_program
|
||||||
env.write_pricing_patten = PricingProgram.write_pricing_patten
|
env.write_pricing_patten = PricingProgram.write_pricing_patten
|
||||||
|
env.write_pricing_data = PricingProgram.write_pricing_data
|
||||||
env.pricing_program_charging = PricingProgram.charging
|
env.pricing_program_charging = PricingProgram.charging
|
||||||
env.buffered_charging = PricingProgram.buffered_charging
|
env.buffered_charging = PricingProgram.buffered_charging
|
||||||
env.load_pricing_data = PricingProgram.load_pricing_data
|
env.load_pricing_data = PricingProgram.load_pricing_data
|
||||||
|
|||||||
@ -250,6 +250,24 @@ class PricingProgram:
|
|||||||
fpath = write_pattern_xlsx(r.name, fields)
|
fpath = write_pattern_xlsx(r.name, fields)
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def write_pricing_data(request, pptid):
|
||||||
|
async with get_sor_context(request._run_ns, 'pricing') as sor:
|
||||||
|
env = request._run_ns
|
||||||
|
recs = await sor.R('pricing_program_timing', {'id': pptid})
|
||||||
|
if not recs:
|
||||||
|
debug(f'id={ppid} pricing_program not found')
|
||||||
|
r = recs[0]
|
||||||
|
recs = await sor.R('pricing_program', {'id': r.ppid})
|
||||||
|
x = DictObject(** yaml.safe_load(r.pricing_data))
|
||||||
|
fields = x
|
||||||
|
if x.get('fields'):
|
||||||
|
fields = x['fields']
|
||||||
|
data = x.get('pricings')
|
||||||
|
|
||||||
|
fpath = write_pattern_xlsx(recs[0].name, fields, data=data)
|
||||||
|
return fpath
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pp_db2app(pp):
|
def pp_db2app(pp):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -28,7 +28,7 @@ def write_pattern_xlsx(name: str, fields: dict, data=None) -> str:
|
|||||||
headers = []
|
headers = []
|
||||||
c = 1
|
c = 1
|
||||||
opt_id = 0
|
opt_id = 0
|
||||||
for name, f in fields.items():
|
for n, f in fields.items():
|
||||||
if f.type == 'factor':
|
if f.type == 'factor':
|
||||||
continue
|
continue
|
||||||
ws_data.cell(row=1, column=c, value=f.label or f.name)
|
ws_data.cell(row=1, column=c, value=f.label or f.name)
|
||||||
@ -45,7 +45,7 @@ def write_pattern_xlsx(name: str, fields: dict, data=None) -> str:
|
|||||||
if data is None:
|
if data is None:
|
||||||
fp = fs._name2path(f'{name}_定价模版.xlsx')
|
fp = fs._name2path(f'{name}_定价模版.xlsx')
|
||||||
else:
|
else:
|
||||||
write_data(ws_data, fields, data)
|
write_data(ws_data, r, c, n, data)
|
||||||
fp = fs._name2path(f'{name}_定价.xlsx')
|
fp = fs._name2path(f'{name}_定价.xlsx')
|
||||||
|
|
||||||
wb.save(fp)
|
wb.save(fp)
|
||||||
|
|||||||
@ -1,23 +1,4 @@
|
|||||||
pptid = params_kw.id
|
pptid = params_kw.id
|
||||||
env = request._run_ns
|
debug(f'download_pricing_pattern.dspy{params_kw=}')
|
||||||
orgid = await get_userorgid()
|
fp = await write_pricing_patten(request, pptid)
|
||||||
async with get_sor_context(env, 'pricing') as sor:
|
return await file_response(request, fp, download=True)
|
||||||
recs = await sor.R('pricing_program_timing', {'id': pptid})
|
|
||||||
if len(recs) == 0:
|
|
||||||
return UiError(title='下载定价信息', message=f'{pptid} 在pricing_program_timing中没找到')
|
|
||||||
ppt = recs[0]
|
|
||||||
recs = await sor.R('pricing_program', {'id': ppt.ppid})
|
|
||||||
if len(recs) == 0:
|
|
||||||
return UiError(title='下载定价信息', message=f'{ppt.ppid} 在pricing_program中没找到')
|
|
||||||
pp = recs[0]
|
|
||||||
if pp.ownerid != orgid:
|
|
||||||
return UiError(title='下载定价信息', message=f'{userorgid} != {pp.ownerid}非本机构定价')
|
|
||||||
data = json.loads(ppt.prcing_data)
|
|
||||||
fields = data.get('fields')
|
|
||||||
if fields is None:
|
|
||||||
return UiError(title='下载定价信息', message=f'{pptid} 定价字段数据为空')
|
|
||||||
pricing_data = data.get('pricings')
|
|
||||||
if pricing_data is None:
|
|
||||||
return UiError(title='下载定价信息', message=f'{pptid} 定价数据为空')
|
|
||||||
fpath = write_pattern_xlsx(name, fields, data=pricing_data)
|
|
||||||
return await file_response(request, fpath, download=True)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user