From 2e3755e2626e7b2e756ec3cbe909e4d3c124ccff Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 25 Mar 2026 11:46:49 +0800 Subject: [PATCH] bugfix --- pricing/pricing.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pricing/pricing.py b/pricing/pricing.py index 9f92c0d..b28e7fb 100644 --- a/pricing/pricing.py +++ b/pricing/pricing.py @@ -184,7 +184,13 @@ class PricingProgram: e = f'pricing_program({pptid}) can not find pricing_program' exception(f) pp = pps[0] - fields = yaml.safe_load(pp.pricing_spec) + pp_spec = yaml.safe_load(pp.pricing_spec) + formula = None + if pp_spec.get('fields'): + fields = pp_spec.get('fields') + pricing_formula = pp_spec.get('formula') + else: + fields = pp_spec newpricings = [] for p in pricings: np = {} @@ -195,6 +201,7 @@ class PricingProgram: newpricings.append(np) d = { 'fields': fields, + 'formula': formula, 'pricings': newpricings } debug(f'{d=}') @@ -328,6 +335,7 @@ where a.id = b.ppid if not d.pricing: exception(f'{d} has not "pricing"') raise Exception(f'定价定义中没有pricing数据') + formula = d.formula ret_items = [] for i, p in enumerate(d.pricings): p_ok = True @@ -360,7 +368,17 @@ where a.id = b.ppid exception(e) raise Exception(e) np = p.copy() - np.amount = p.price * float(times) / float(unit) + times = float(times) + unit = float(unit) + if formula: + ns = { + 'price': p.price, + 'times': times, + 'unit': unit + } + np.amount = eval(formula, ns) + else: + np.amount = p.price * float(times) / float(unit) ret_items.append(np) if len(ret_items) == 0: e = f'{config_data=}{yamlstr=}没有找到合适的定价'