from datetime import datetime from appPublic.uniqueID import getID from appPublic.timeUtils import curDateString, timestampstr from appPublic.argsConvert import ArgsConvert from appPublic.log import debug, exception from appbase.businessdate import get_business_date from ahserver.serverenv import ServerEnv from sqlor.dbpools import DBPools from .accounting_config import get_accounting_config, PFBiz, Accounting from .const import * from .accountingnode import get_accounting_nodes from .excep import * from .getaccount import getAccountByName class SaleInfo: def __init__(self, customerid, resellerid, amount): self.customerid = customerid self.resellerid = resellerid self.amount = amount self.base_action = 'PAY' class CostInfo: def __init__(self, providerid, resellerid, amount): self.providerid = providerid self.resellerid = resellerid self.amount = amount class ConsumeBiz(PFBiz): def __init__(self, od): self.db = DBPools() self.action = od.action self.orderid = od['orderid'] self.curdate = od.biz_date self.timestamp = od.timestamp self.action = od['action'] self.billid = getID() self.customerid = od['customerid'] self.resellerid = od['resellerid'] self.productid = od['productid'] self.providerid = od['providerid'] self.summary = f'{self.action}|{self.customerid}|{self.resellerid}|{self.productid}' self.variable = od.variable async def get_orgid_by_trans_role(self, sor, leg, role): if role == 'owner': return '0' if role == 'customer': return self.customerid if role == 'reseller': return self.resellerid if role == 'provider': return self.providerid if role is None or role == 'null': return None e = Exception(f'unknown role({role})') exception(f'Exception:{e}') raise e async def consume_accounting(sor, orderid, order_details): ods = [] billid = getID() env = ServerEnv() curdate = await env.get_business_date(sor) for od in order_details: od['billid'] = billid od['orderid'] = orderid od['curdate'] = curdate ods.append(ConsumeBiz(od)) ao = Accounting(ods) od = order_details[0] bill = { 'id':billid, 'customerid':od.customerid, 'resellerid':od.resellerid, 'orderid':od.orderid, 'business_op':od.action, 'amount':od.transamt, 'bill_date':od.curdate, 'bill_timestamp':od.timestamp } await sor.C('bill', bill.copy()) await ao.do_accounting(sor)