accounting/accounting/settle.py
2024-07-31 16:16:21 +08:00

57 lines
1.6 KiB
Python

from .const import *
from .accountingnode import get_accounting_nodes
from .excep import *
from .getaccount import getAccountByName
from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools
from appPublic.timeUtils import curDateString
from appPublic.argsConvert import ArgsConvert
from .accounting_config import get_accounting_config, AccountingOrgs
from datetime import datetime
def get_subjectid(salemode):
d = {
'0':'acc009',
'1':'acc010',
'2':'acc011'
}
return d.get(salemode)
class SettleAccounting:
def __init__(self, settle_log):
self.accounting_orgid = settle_log['accounting_orgid']
self.settle_log = settle_log
self.providerid = settle_log['providerid']
self.orderid = None
self.sale_mode = settle_log['sale_mode']
self.curdate = settle_log['settle_date']
self.transamount = settle_log['settle_amt']
self.timestamp = datetime.now()
self.productid = None
self.action = settle_log['business_op']
self.summary = self.action
self.settleid = getID()
self.billid = getID()
self.bill = {
'id':self.billid,
'business_op':self.action,
'amount':self.transamount,
'bill_date':self.curdate,
'bill_timestamp':self.timestamp
}
async def accounting(self, sor):
ao = AccountingOrgs(self, self.accounting_orgid, None)
await self.write_settle_log(sor)
await self.write_bill(sor)
await ao.do_accounting(sor)
return True
async def write_settle_log(self, sor):
ns = self.settle_log.copy()
ns['id'] = self.settleid
await sor.C('settle_log', ns)
async def write_bill(self, sor):
await sor.C('bill', self.bill.copy())