def test_transfer_status(self): t = WalletTransaction.add(account=self.wallet_account, bankcard=self.bankcard, transaction_id=uuid.uuid4().hex, amount=Decimal('1024.12'), type_=WalletTransaction.Type.purchase) assert t.status is WalletTransaction.Status.raw t = WalletTransaction.get(t.id_) assert t.status is WalletTransaction.Status.raw WalletTransaction.sum_amount(WalletTransaction.Type.purchase) == \ Decimal('0') t.transfer_status(WalletTransaction.Status.success) assert t.status is WalletTransaction.Status.success t = WalletTransaction.get(t.id_) assert t.status is WalletTransaction.Status.success WalletTransaction.sum_amount(WalletTransaction.Type.purchase) == \ Decimal('1024.12') t.transfer_status(WalletTransaction.Status.failure) assert t.status is WalletTransaction.Status.failure t = WalletTransaction.get(t.id_) assert t.status is WalletTransaction.Status.failure WalletTransaction.sum_amount(WalletTransaction.Type.purchase) == \ Decimal('0')
def audit_by_account(client, wallet_account, date_from, date_to): assert isinstance(wallet_account, WalletAccount) args = (wallet_account, date_from, date_to) remote_records = fetch_remote_records(client, *args) local_records = WalletTransaction._get_by_account_and_date(*args) for local in local_records: remote = remote_records.pop(local.transaction_id, None) WalletAudit.compare_and_add(wallet_account=wallet_account, local_transaction=local, remote_transaction=remote) # 弥补本地可能存在而没有获取到的情况 for k, _ in remote_records.items(): local_record = WalletTransaction.get_by_transaction_id(k) if local_record: remote_record = remote_records.pop(k) WalletAudit.compare_and_add(wallet_account=wallet_account, local_transaction=local_record, remote_transaction=remote_record) for remote in remote_records.values(): WalletAudit.compare_and_add(wallet_account=wallet_account, remote_transaction=remote)
def transactions(): start = request.args.get('start', type=int, default=0) limit = request.args.get('limit', type=int, default=5) ids = WalletTransaction.get_ids_by_account(g.wallet_account.id_) transactions = WalletTransaction.get_multi(ids[start:start + limit]) data = { 'collection': [{ 'type': ('deposit' if t.type_ is WalletTransaction.Type.purchase else 'withdraw'), 'bankcard': { 'bank': { 'name': t.bankcard.bank.name }, 'display_card_number': t.bankcard.display_card_number }, 'amount': unicode(round_half_up(t.amount, 2)), 'creation_date': unicode(t.creation_time.date()), 'value_date': unicode(t.value_date) if t.value_date else None } for t in transactions if t.status is WalletTransaction.Status.success], 'start': start, 'total': len(ids), } return jsonify(r=True, data=data)
def index(): dashboard = PublicDashboard.today() profile = UserDashboard.today(g.wallet_account) transaction_ids = WalletTransaction.get_ids_by_account( g.wallet_account.id_) transactions = WalletTransaction.get_multi(transaction_ids[:5]) return render_template('wallet/mine.html', dashboard=dashboard, profile=profile, transactions=transactions, total_transaction=len(transaction_ids))
def test_get_by_bankcard_id(self): t = WalletTransaction.add(account=self.wallet_account, bankcard=self.bankcard, transaction_id=uuid.uuid4().hex, amount=Decimal('1024.22'), type_=WalletTransaction.Type.purchase) ids = WalletTransaction.get_ids_by_bankcard(self.bankcard.id_) assert ids == [] t.transfer_status(WalletTransaction.Status.success) ids = WalletTransaction.get_ids_by_bankcard(self.bankcard.id_) assert ids == [t.id_]
def transactions(): """用户历史交易记录. :reqheader Authorization: OAuth 2.0 Bearer Token :status 200: 返回 :class:`.TransactionSchema` :query offset: 可选参数, 开始条数,按交易列表请求数限制返回结果. :query count: 可选参数, 每页数量,按交易列表请求数限制返回结果. """ transaction_schema = TransactionSchema(strict=True, many=True) offset = request.args.get('offset', type=int, default=0) count = request.args.get('count', type=int, default=20) ids = WalletTransaction.get_ids_by_account(g.wallet_account.id_) transactions = WalletTransaction.get_multi(ids[offset:offset + count]) transaction_data = transaction_schema.dump(transactions).data return jsonify(success=True, data=transaction_data)
def test_new_transaction(self): t = WalletTransaction.add(account=self.wallet_account, bankcard=self.bankcard, transaction_id=uuid.uuid4().hex, amount=Decimal('1024.12'), type_=WalletTransaction.Type.purchase) assert t.owner == self.account assert t.wallet_account == self.wallet_account assert t.type_ is WalletTransaction.Type.purchase assert t.status is WalletTransaction.Status.raw assert t.bankcard == self.bankcard WalletAccount.get.assert_called_once_with('1010') self.bankcard_class.get.assert_called_once_with(42) WalletTransaction.sum_amount(WalletTransaction.Type.purchase) == \ Decimal('0')
def home(): user_count = get_user_count() investment_sum_amount = get_savings_amount() + \ WalletTransaction.sum_amount(WalletTransaction.Type.purchase) if g.user: return redirect('/mine/') return render_template('index/index.html', user_count=user_count, investment_sum_amount=investment_sum_amount)
def generate_fake_transactions(): user = Account.get_by_alias('*****@*****.**') if not user: return with patch('core.models.profile.bankcard.DEBUG', True): b1 = BankCard.add( user_id=user.id_, mobile_phone='13800138000', card_number='6222000000000009', bank_id='4', # 建设银行 city_id='110100', # 朝阳 province_id='110000', # 北京 local_bank_name='西夏支行', is_default=True) b2 = BankCard.add( user_id=user.id_, mobile_phone='13800138000', card_number='6222000000010008', bank_id='10002', # 中信银行 city_id='110100', # 朝阳 province_id='110000', # 北京 local_bank_name='天龙寺支行', is_default=True) bcolors.run(repr(b1), key='wallet') bcolors.run(repr(b2), key='wallet') wallet_account = WalletAccount.get_or_add(user, zhongshan) t1 = WalletTransaction.add( wallet_account, b1, decimal.Decimal('40'), WalletTransaction.Type.purchase, uuid.uuid4().hex, WalletTransaction.Status.failure) t2 = WalletTransaction.add( wallet_account, b1, decimal.Decimal('42'), WalletTransaction.Type.purchase, uuid.uuid4().hex, WalletTransaction.Status.success) t3 = WalletTransaction.add( wallet_account, b2, decimal.Decimal('10'), WalletTransaction.Type.redeeming, uuid.uuid4().hex, WalletTransaction.Status.success) bcolors.run(repr(t1), key='wallet') bcolors.run(repr(t2), key='wallet') bcolors.run(repr(t3), key='wallet')
def mine(): # 攒钱助手 savings_manager = SavingsManager(g.user.id_) savings_products = ZhiwangProduct.get_all() vendor = Vendor.get_by_name(Provider.sxb) sxb_products = Product.get_products_by_vendor_id(vendor.id_) xm_products = XMFixedDuedayProduct.get_all() # 零钱包 wallet_dashboard = PublicDashboard.today() wallet_account = WalletAccount.get_by_local_account(g.user, zhongshan) if wallet_account: wallet_profile = UserDashboard.today(wallet_account) wallet_has_transaction = bool( WalletTransaction.get_ids_by_account(wallet_account.id_)) else: wallet_profile = None wallet_has_transaction = False # 规划书 report = Report.get_latest_by_plan_id(g.plan.id) if g.plan else None if not (report and report.status >= REPORT_STATUS.interdata): return render_template('/mine/center_unplanned.html', **locals()) if int(report.formula_ver) < int(FORMULA_VER): regen_log(report, 'start regenerate inter data') cal_intermediate_data(report, force=True, log=regen_log) report.update_formula_ver(FORMULA_VER) regen_log(report, 'success regenerate inter data FV:%s' % report.formula_ver) inter_data = report.inter_data locals().update(inter_data) cur_path = 'center' return render_template('/mine/center.html', **locals())
def local_type(self): if self.local_transaction_type: return WalletTransaction.Type(self.local_transaction_type)
def local_status(self): return WalletTransaction.Status(self._local_status)