diff --git a/accounting/accounting_config.py b/accounting/accounting_config.py index 610e3d3..901cb0d 100644 --- a/accounting/accounting_config.py +++ b/accounting/accounting_config.py @@ -41,20 +41,9 @@ class Accounting: if isinstance(caller, list): self.callers = caller caller = self.callers[0] - self.caller = caller - self.curdate = caller.curdate - self.realtimesettled = False - self.timestamp = caller.timestamp - self.billid = caller.billid - self.action = caller.action - self.summary = f'{self.caller.orderid}:{self.caller.billid}' - self.providerid = caller.providerid - self.productid = caller.productid - self.resellerid = caller.resellerid - self.customerid = caller.customerid - self.own_salemode = None - self.reseller_salemode = None - self.variable = caller.variable + else: + self.callers = [caller] + self.caller = caller async def setup_all_accounting_legs(self): self.accounting_legs = [] @@ -85,8 +74,9 @@ class Accounting: self.accounting_legs = legs async def setup_accounting_legs(self): + sor = self.sor action = self.action.split('_')[0] - acfg = get_accounting_config(self.sor) + acfg = await get_accounting_config(self.sor) legs = [r.copy() for r in acfg if r.action == action ] debug(f'{legs=}') @@ -159,7 +149,7 @@ class Accounting: async def do_accounting(self, sor): self.sor = sor - await self.setup_accounting_legs() + await self.setup_all_accounting_legs() debug(f'do_accounting() ...{self.accounting_legs=}') self.check_accounting_balance(self.accounting_legs) for leg in self.accounting_legs: diff --git a/accounting/consume.py b/accounting/consume.py index 8c17b14..bd52b61 100644 --- a/accounting/consume.py +++ b/accounting/consume.py @@ -42,9 +42,12 @@ class ConsumeBiz(PFBiz): 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) bill = { @@ -54,7 +57,7 @@ async def consume_accounting(sor, orderid, order_details): 'orderid':self.orderid, 'business_op':self.action, 'amount':log['transamt'], - 'bill_date':self.curdate, + 'bill_date':curdate, 'bill_timestamp':self.timestamp } await sor.C('bill', bill.copy()) diff --git a/accounting/getaccount.py b/accounting/getaccount.py index a77cae2..14b4d7e 100644 --- a/accounting/getaccount.py +++ b/accounting/getaccount.py @@ -4,14 +4,16 @@ from ahserver.serverenv import ServerEnv, get_serverenv from .const import * from accounting.accountingnode import get_parent_orgid -async def get_account(sor, accounting_orgid, orgid, subjectid, org1id=None): +async def get_account(sor, accounting_orgid, orgid, subjectid, org1id=None, update=False): ss = "a.org1id is NULL" if org1id: ss = "a.org1id = ${org1id}$" + if update: + ss += " for update" sql = """select a.*, -case when c.balance is null then 0.00 else c.balance end as balance +case when b.balance is null then 0.00 else b.balance end as balance from account a left join acc_balance b on a.id = b.accountid where