bugfix
This commit is contained in:
parent
d75c8ab82f
commit
3df6c1514e
@ -101,9 +101,9 @@ where a.agreeid = b.id
|
||||
e = Exception(f'there is no agreement for {sellerid=} and {buyerid=}, {productid=} at {biz_date=} ')
|
||||
exception(f'{e=}')
|
||||
raise e
|
||||
rec = None:
|
||||
rec = None
|
||||
for r in recs:
|
||||
if r.prodtypeid = r.agree_prodtypeid:
|
||||
if r.prodtypeid == r.agree_prodtypeid:
|
||||
rec = r
|
||||
break
|
||||
if rec is None:
|
||||
@ -117,10 +117,15 @@ where a.agreeid = b.id
|
||||
raise e
|
||||
return rec
|
||||
|
||||
async def get_unit_value_price(sc, pricingtab):
|
||||
def get_unit_value_price(sc, pricingtab):
|
||||
for pt in pricingtab:
|
||||
if sc.spec_name == pt.specname and pt.spec_value == pt.specvalue:
|
||||
if pt.specvalue == '':
|
||||
pt.specvalue = None
|
||||
if sc.spec_name == pt.specname and \
|
||||
sc.spec_value == pt.specvalue:
|
||||
print(f'found {sc.spec_name=},{sc.spec_value=}')
|
||||
return pt.unit_value, pt.unit_amt
|
||||
print(f'{sc.spec_name=},{sc.spec_value=}:{pt.specname=},{pt.specvalue=}')
|
||||
return None, None
|
||||
|
||||
async def calc_prod_price(sor, productid, spec_config):
|
||||
@ -138,13 +143,13 @@ from product a, prodpricing b,
|
||||
prodpricingtab c, prodtype d,
|
||||
prodtypespec e
|
||||
where a.id=${productid}$
|
||||
and a.protypeid = d.id
|
||||
and e.protypeid = d.id
|
||||
and a.prodtypeid = d.id
|
||||
and e.prodtypeid = d.id
|
||||
and a.id = b.prodid
|
||||
and b.enable_date <= ${biz_date}$
|
||||
and b.expire_date > ${biz_date}$
|
||||
and c.prodpricingid = b.id
|
||||
and c.protypespecid = e.id
|
||||
and c.ptspecid = e.id
|
||||
"""
|
||||
recs = await sor.sqlExe(sql, {'productid':productid,
|
||||
'biz_date':biz_date})
|
||||
@ -155,11 +160,12 @@ where a.id=${productid}$
|
||||
raise e
|
||||
price = 0.0
|
||||
for sc in spec_config:
|
||||
print(f'{sc=}, {recs=}')
|
||||
uv, up = get_unit_value_price(sc, recs)
|
||||
if uv is None:
|
||||
continue
|
||||
cnt = sc.count / uv
|
||||
price = up * cnt
|
||||
price += up * cnt
|
||||
return price
|
||||
|
||||
async def get_sell_price(sor, sellerid, buyerid, productid, list_price):
|
||||
|
@ -1,19 +1,20 @@
|
||||
from testenv import runtest
|
||||
from appPublic.dictObject import DictObject
|
||||
from platformbiz.pricing import calc_prod_price
|
||||
|
||||
async def test(sor):
|
||||
prodid = 'a--akNeu1Ia-NOZAJAadf'
|
||||
spec_config = [
|
||||
{
|
||||
DictObject(**{
|
||||
"spec_name":"input_tokens",
|
||||
"count":12832
|
||||
},
|
||||
{
|
||||
}),
|
||||
DictObject(**{
|
||||
"spec_name":"output_tokens",
|
||||
"count":786323
|
||||
}
|
||||
})
|
||||
]
|
||||
price = calc_prod_price(sor, prodid, spec_config)
|
||||
price = await calc_prod_price(sor, prodid, spec_config)
|
||||
print(f'{prodid=}, {spec_config=}, {price=}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -9,7 +9,7 @@ from platformbiz.init import load_platformbiz
|
||||
async def main(asyncfunc):
|
||||
home = os.environ['HOME']
|
||||
p = f'{home}/py/sage'
|
||||
config = getCofig(p, {'workdir':p})
|
||||
config = getConfig(p, {'workdir':p})
|
||||
db = DBPools(config.databases)
|
||||
load_appbase()
|
||||
load_accounting()
|
||||
|
Loading…
Reference in New Issue
Block a user