def cents_to_brl(value): if value: value = int(value) # valor com centavos em float value = float(value) / 100 m = Money(value, "BRL") return m.format("pt_BR", "¤ #,##0.00") return None
def encode(): source = request.args.get('source', default = "Red Hat Summit 2019", type = str) id = request.args.get('id', default = DEFAULT_ID, type = str) amount = request.args.get('amount', default = "0.0", type = str) try: if (id == DEFAULT_ID): img = qrcode.make(source + ";" + id + ";" + amount) return _serve_pil_image(img) else: money_amount = Money(amount, Currency.USD) img = qrcode.make(source + ";" + id + ";" + money_amount.format('en_US')) return _serve_pil_image(img) except Exception as e: logging.error(traceback.format_exc()) return "Error generating QR code."
def get_context_data(self, **kwargs): context = super(OrderSummaryView, self).get_context_data(**kwargs) queryset = self.get_queryset() locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') subtotal = 0 for item in queryset: db_price = item.inventory.inv_price unit_price = Decimal(sub(r'[^\d.]', '', db_price)) subtotal += unit_price*item.quantity subtotal = Money(subtotal, Currency.USD) tax = subtotal * SALES_TAX_RATE grand_total = subtotal + tax subtotal = subtotal.format('en_US') tax = tax.format('en_US') grand_total = grand_total.format('en_US') context['total'] = subtotal context['tax'] = tax context['grand_total'] = grand_total return context