def _set_token_count(agreement, token_count_float=None, precision=2): # type: (InvestmentAgreement) -> None stats = get_global_stats(agreement.token) logging.info('Setting token count for agreement %s', agreement.to_dict()) if agreement.status == InvestmentAgreement.STATUS_CREATED: if agreement.currency == 'USD': agreement.token_count = long( (agreement.amount / stats.value) * pow(10, precision)) else: currency_stats = filter(lambda s: s.currency == agreement.currency, stats.currencies)[0] if not currency_stats: raise HttpBadRequestException( 'Could not find currency conversion for currency %s' % agreement.currency) agreement.token_count = long( (agreement.amount / currency_stats.value) * pow(10, precision)) # token_count can be overwritten when marking the investment as paid for BTC elif agreement.status == InvestmentAgreement.STATUS_SIGNED: if agreement.currency == 'BTC': if not token_count_float: raise HttpBadRequestException( 'token_count_float must be provided when setting token count for BTC' ) # The course of BTC changes how much tokens are granted if agreement.token_count: logging.debug( 'Overwriting token_count for investment agreement %s from %s to %s', agreement.id, agreement.token_count, token_count_float) agreement.token_count = long(token_count_float * pow(10, precision)) agreement.token_precision = precision
def _get_conversion_rates(): result = [] stats = get_global_stats(TOKEN_ITFT) for currency in stats.currencies: result.append({ 'name': _get_currency_name(currency.currency), 'symbol': currency.currency, 'value': currency.value }) return result
def create_token_agreement_pdf(full_name, address, amount, currency_full, currency_short, token, payment_info, has_verified_utility_bill): # don't forget to update intercom tags when adding new contracts / tokens def fmt(x, currency): if currency == 'BTC': return '{:.8f}'.format(x) return '{:.2f}'.format(x) amount_formatted = fmt(amount, currency_short) stats = get_global_stats(token) conversion = {currency.currency: fmt(round_currency_amount(currency.currency, currency.value / stats.value), currency.currency) for currency in stats.currencies} template_variables = { 'logo_path': 'assets/logo.jpg', 'effective_date': _get_effective_date(), 'full_name': full_name, 'address': address.replace('\n', ', '), 'amount': amount_formatted, 'currency_full': currency_full, 'price': stats.value, 'price_words': inflect.engine().number_to_words(stats.value).title(), 'currency_short': currency_short, 'conversion': conversion } if token == TOKEN_ITFT: html_file = 'token_itft.html' context = {'bank_account': get_bank_account_info(currency_short, payment_info or [], has_verified_utility_bill)} context.update(template_variables) md = JINJA_ENVIRONMENT.get_template('token_itft.md').render(context) markdown_to_html = markdown.markdown(md, extensions=['markdown.extensions.tables']) template_variables['markdown_to_html'] = markdown_to_html.replace('<th', '<td') template_variables['title'] = u'iTFT Purchase Agreement' else: currency_messages = [] for currency in BANK_ACCOUNTS: account = BANK_ACCOUNTS[currency] if currency == 'BTC': currency_messages.append( u'when using Bitcoin: to the Company’s BitCoin wallet hosted by BitOasis Technologies FZE, at the' u' following digital address: <b>%s</b> (the “<b>Wallet</b>”)' % account) else: currency_messages.append( u'when using %s: to the Company’s bank account at Mashreq Bank, IBAN: <b>%s</b> SWIFT/BIC:' u' <b>BOMLAEAD</b>' % (get_currency_name(currency, locale='en_GB'), account)) template_variables['currency_messages'] = currency_messages html_file = 'token_tft_btc.html' if currency_short == 'BTC' else 'token_tft.html' return _render_pdf_from_html(html_file, template_variables)
def create_token_agreement_pdf(full_name, address, amount, currency_full, currency_short, token=TOKEN_TFT): # don't forget to update intercom tags when adding new contracts / tokens if token == TOKEN_ITFT: html_file = 'token_itft.html' elif currency_short == 'BTC': html_file = 'token_tft_btc.html' else: html_file = 'token_tft.html' if currency_short == 'BTC': amount_formatted = '{:.8f}'.format(amount) else: amount_formatted = '{:.2f}'.format(amount) conversion = {} if token: stats = get_global_stats(TOKEN_TFT) conversion = { currency.currency: round_currency_amount(currency.currency, currency.value / stats.value) for currency in stats.currencies } currency_messages = [] for currency in BANK_ACCOUNTS: account = BANK_ACCOUNTS[currency] if currency == 'BTC': currency_messages.append( u'when using Bitcoin: to the Company’s BitCoin wallet hosted by BitOasis Technologies FZE, at the' u' following digital address: <b>%s</b> (the “<b>Wallet</b>”)' % account) else: currency_messages.append( u'when using %s: to the Company’s bank account at Mashreq Bank, IBAN: <b>%s</b> SWIFT/BIC:' u' <b>BOMLAEAD</b>' % (get_currency_name(currency, locale='en_GB'), account)) template_variables = { 'logo_path': 'assets/logo.jpg', 'effective_date': _get_effective_date(), 'full_name': full_name, 'address': address, 'amount': amount_formatted, 'currency_full': currency_full, 'currency_short': currency_short, 'currency_messages': currency_messages, 'conversion': conversion } source_html = JINJA_ENVIRONMENT.get_template(html_file).render( template_variables) output_stream = StringIO() pisa.CreatePDF(src=source_html, dest=output_stream, path='%s' % ASSETS_FOLDER) pdf_contents = output_stream.getvalue() output_stream.close() return pdf_contents
def api_get_global_stat(stats_id): return GlobalStatsTO.from_model(get_global_stats(stats_id))