Ejemplo n.º 1
0
def generateBill(started_at=None, ended_at=None, last=None, current=None):
    '''生成账单'''
    if isinstance(started_at, str):
        started_at = datetime.datetime.strptime(started_at,
                                                '%Y-%m-%d %H:%M:%S')
    if isinstance(ended_at, str):
        ended_at = datetime.datetime.strptime(ended_at, '%Y-%m-%d %H:%M:%S')
    accountDao = AccountDao()
    consumptionDao = ConsumptionDao()
    #    rows = accountDao.list(condition={"status":"normal"})
    rows = accountDao.list()
    billDao = BillDao()
    for row in rows:
        account_id = row.account_id
        if billDao.checkBill(account_id, started_at, ended_at):
            continue
        result = consumptionDao.getAmountTotal_new(account_id, started_at,
                                                   ended_at)
        if result:
            result = totalAmount_bill(result)
            bill = Bill()
            bill.account_id = account_id
            bill.started_at = started_at
            bill.ended_at = ended_at
            bill.no = generation()
            bill.bill_items = []
            bill.amount = 0
            bill.gift_amount = 0
            bill.standard_amount = 0
            for bill_item_data in result:
                billItem = BillItem()
                getObjFromJson(billItem, bill_item_data)
                if bill_item_data['amount_total'] is None:
                    bill_item_data['amount_total'] = 0
                if bill_item_data['standard_total'] is None:
                    bill_item_data['standard_total'] = 0
                if bill_item_data['gift_total'] is None:
                    bill_item_data['gift_total'] = 0
                bill.amount += float(bill_item_data['amount_total'])
                bill.standard_amount += float(bill_item_data['standard_total'])
                bill.gift_amount += float(bill_item_data['gift_total'])
                billItem.amount = round(float(bill_item_data['amount_total']),
                                        2)
                billItem.standard_amount = round(
                    float(bill_item_data['standard_total']), 2)
                billItem.gift_amount = round(
                    float(bill_item_data['gift_total']), 2)
                bill.bill_items.append(billItem)
            bill.amount = round(bill.amount, 2)
            bill.type = 'cloud'
            billDao.bill = bill
            billDao.add()
Ejemplo n.º 2
0
def lowcashReminder_3():
    accountDao = AccountDao()
    for account in accountDao.list({'status': 'normal'}):
        try:
            if accountDao.lowcashReminder_3(account.account_id):
                account.cash_balance = account.cash_balance if account.cash_balance else 0
                account.gift_balance = account.gift_balance if account.gift_balance else 0
                account.credit_line = account.credit_line if account.credit_line else 0
                content = None
                if account.type == 'normal':
                    content = '账户:' + account.username + '余额不足使用3天,请催款。目前账户现金余额:' + str(
                        account.cash_balance) + ',赠送余额:' + str(
                            account.gift_balance)
                else:
                    content = '账户:' + account.username + '余额不足使用3天,请催款。目前账户现金余额:' + str(
                        account.cash_balance) + ',赠送余额:' + str(
                            account.gift_balance) + ',信用额度:' + str(
                                account.credit_line) + ',可用额度:' + str(
                                    account.credit_line if account.
                                    cash_balance > 0 else account.credit_line +
                                    account.cash_balance) + "。"
                payment_workorder = {
                    'workordertype': 6,
                    'workorder_no': generation(),
                    'apply_by': 'billing',
                    'apply_source': 'billing',
                    'status': 'apply',
                    'theme': '账户:' + account.username + '余额不足使用3天,请催款',
                    'content': content
                }
                workOrderDao = WorkOrderDao()

                if workOrderDao.checkPaymentWorkOrder(
                        6, 'billing', 'billing', 'apply',
                        '账户:' + account.username + '余额不足使用3天,请催款',
                        datetime.datetime.utcnow() -
                        datetime.timedelta(days=3)):
                    workOrderDao.create(payment_workorder)
        except Exception as e:
            LOG.error(str(e))
            LOG.error(traceback.format_exc())