Ejemplo n.º 1
0
def price_as_dict(price):
    if price is None:
        return None
    return {
        'currency': price.currency,
        'gross': price.gross.amount,
        'grossLocalized': prices_i18n.amount(price.gross),
        'net': price.net.amount,
        'netLocalized': prices_i18n.amount(price.net)}
Ejemplo n.º 2
0
def price_as_dict(price):
    if price is None:
        return None
    return {
        'currency': price.currency,
        'gross': price.gross.amount,
        'grossLocalized': prices_i18n.amount(price.gross),
        'net': price.net.amount,
        'netLocalized': prices_i18n.amount(price.net)}
Ejemplo n.º 3
0
def price_as_dict(price):
    if price is None:
        return None
    return {
        "currency": price.currency,
        "gross": price.gross.amount,
        "grossLocalized": prices_i18n.amount(price.gross),
        "net": price.net.amount,
        "netLocalized": prices_i18n.amount(price.net),
    }
Ejemplo n.º 4
0
def price_as_dict(price):
    if price is None:
        return None
    return {
        "currency": price.currency,
        "gross": price.gross.amount,
        "grossLocalized": prices_i18n.amount(price.gross),
        "net": price.net.amount,
        "netLocalized": prices_i18n.amount(price.net),
    }
Ejemplo n.º 5
0
 def get_ajax_label(self, discounts=None):
     price = self.get_price(discounts)
     return "%s, %s, %s" % (
         self.sku,
         self.display_product(),
         prices_i18n.amount(price),
     )
Ejemplo n.º 6
0
def capture_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related("payments")
    order = get_object_or_404(orders.prefetch_related("lines", "user"),
                              pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = order.total.gross
    form = CapturePaymentForm(request.POST or None,
                              payment=payment,
                              initial={"amount": amount.amount})
    if form.is_valid() and form.capture(request.user):
        msg = pgettext_lazy("Dashboard message related to a payment",
                            "Captured %(amount)s") % {
                                "amount": prices_i18n.amount(amount)
                            }
        events.payment_captured_event(order=order,
                                      user=request.user,
                                      amount=amount.amount,
                                      payment=payment)
        messages.success(request, msg)
        return redirect("tradingroom:order-details", order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        "captured": amount,
        "form": form,
        "order": order,
        "payment": payment
    }
    return TemplateResponse(request,
                            "tradingroom/order/modal/capture.html",
                            ctx,
                            status=status)
Ejemplo n.º 7
0
def refund_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related("payments")
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(request.POST or None,
                             payment=payment,
                             initial={"amount": amount})
    if form.is_valid() and form.refund(request.user):
        amount = form.cleaned_data["amount"]
        msg = pgettext_lazy("Dashboard message related to a payment",
                            "Refunded %(amount)s") % {
                                "amount": prices_i18n.amount(
                                    payment.get_captured_amount())
                            }
        events.payment_refunded_event(order=order,
                                      user=request.user,
                                      amount=amount,
                                      payment=payment)
        messages.success(request, msg)
        return redirect("tradingroom:order-details", order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        "captured": payment.get_captured_amount(),
        "form": form,
        "order": order,
        "payment": payment,
    }
    return TemplateResponse(request,
                            "tradingroom/order/modal/refund.html",
                            ctx,
                            status=status)
Ejemplo n.º 8
0
def capture_payment(request, order_pk, payment_pk):
    order = get_object_or_404(Order, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = order.total.quantize('0.01').gross
    form = CapturePaymentForm(request.POST or None,
                              payment=payment,
                              initial={'amount': amount})
    if form.is_valid() and form.capture():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy('Dashboard message related to a payment',
                            'Captured %(amount)s') % {
                                'amount': prices_i18n.amount(amount)
                            }
        order.history.create(content=msg, user=request.user)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        'captured': payment.captured_amount,
        'currency': payment.currency,
        'form': form,
        'order': order,
        'payment': payment
    }
    return TemplateResponse(request,
                            'dashboard/order/modal/capture.html',
                            ctx,
                            status=status)
Ejemplo n.º 9
0
def capture_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related('payments')
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = order.total.gross
    form = CapturePaymentForm(request.POST or None,
                              payment=payment,
                              initial={'amount': amount.amount})
    if form.is_valid() and form.capture():
        msg = pgettext_lazy('Dashboard message related to a payment',
                            'Captured %(amount)s') % {
                                'amount': prices_i18n.amount(amount)
                            }
        order.events.create(parameters={'amount': amount},
                            user=request.user,
                            type=OrderEvents.PAYMENT_CAPTURED.value)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        'captured': amount,
        'form': form,
        'order': order,
        'payment': payment
    }
    return TemplateResponse(request,
                            'dashboard/order/modal/capture.html',
                            ctx,
                            status=status)
Ejemplo n.º 10
0
 def validate_limit(self, value):
     limit = self.limit or value.gross
     if value.gross < limit:
         msg = pgettext(
             'Voucher not applicable',
             'This offer is only valid for orders over %(amount)s.')
         raise NotApplicable(msg % {'amount': amount(limit)}, limit=limit)
Ejemplo n.º 11
0
def refund_payment(request, task_pk, payment_pk):
    tasks = Task.objects.confirmed().prefetch_related('payments')
    task = get_object_or_404(tasks, pk=task_pk)
    payment = get_object_or_404(task.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(
        request.POST or None, payment=payment, initial={'amount': amount})
    if form.is_valid() and form.refund():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy(
            'Dashboard message related to a payment',
            'Refunded %(amount)s') % {
                'amount': prices_i18n.amount(payment.get_captured_amount())}
        task.events.create(
            parameters={'amount': amount},
            user=request.user,
            type=TaskEvents.PAYMENT_REFUNDED.value)
        messages.success(request, msg)
        return redirect('dashboard:task-details', task_pk=task.pk)
    status = 400 if form.errors else 200
    ctx = {
        'captured': payment.get_captured_amount(),
        'form': form,
        'task': task,
        'payment': payment}
    return TemplateResponse(request, 'dashboard/task/modal/refund.html', ctx,
                            status=status)
Ejemplo n.º 12
0
def refund_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related('payments')
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(request.POST or None,
                             payment=payment,
                             initial={'amount': amount})
    if form.is_valid() and form.refund():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy('Dashboard message related to a payment',
                            'Refunded %(amount)s') % {
                                'amount': prices_i18n.amount(amount)
                            }
        order.history.create(content=msg, user=request.user)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        'captured': payment.captured_amount,
        'currency': payment.currency,
        'form': form,
        'order': order,
        'payment': payment
    }
    return TemplateResponse(request,
                            'dashboard/order/modal/refund.html',
                            ctx,
                            status=status)
Ejemplo n.º 13
0
 def validate_limit(self, value):
     limit = self.limit or value.gross
     if value.gross < limit:
         msg = pgettext(
             'Voucher not applicable',
             'This offer is only valid for orders over %(amount)s.')
         raise NotApplicable(msg % {'amount': amount(limit)}, limit=limit)
Ejemplo n.º 14
0
def refund_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related("payments")
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(
        request.POST or None, payment=payment, initial={"amount": amount}
    )
    if form.is_valid() and form.refund(request.user):
        amount = form.cleaned_data["amount"]
        msg = pgettext_lazy(
            "Dashboard message related to a payment", "Refunded %(amount)s"
        ) % {"amount": prices_i18n.amount(payment.get_captured_amount())}
        events.payment_refunded_event(
            order=order, user=request.user, amount=amount, payment=payment
        )
        messages.success(request, msg)
        return redirect("dashboard:order-details", order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        "captured": payment.get_captured_amount(),
        "form": form,
        "order": order,
        "payment": payment,
    }
    return TemplateResponse(
        request, "dashboard/order/modal/refund.html", ctx, status=status
    )
Ejemplo n.º 15
0
def refund_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related('payments')
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(
        request.POST or None, payment=payment, initial={'amount': amount})
    if form.is_valid() and form.refund():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy(
            'Dashboard message related to a payment',
            'Refunded %(amount)s') % {
                'amount': prices_i18n.amount(payment.get_captured_amount())}
        order.events.create(
            parameters={'amount': amount},
            user=request.user,
            type=OrderEvents.PAYMENT_REFUNDED.value)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {
        'captured': payment.get_captured_amount(),
        'form': form,
        'order': order,
        'payment': payment}
    return TemplateResponse(request, 'dashboard/order/modal/refund.html', ctx,
                            status=status)
Ejemplo n.º 16
0
 def validate_min_amount_spent(self, value):
     min_amount_spent = self.min_amount_spent
     if min_amount_spent and value.gross < min_amount_spent:
         msg = pgettext(
             'Voucher not applicable',
             'This offer is only valid for orders over %(amount)s.')
         raise NotApplicable(msg % {'amount': amount(min_amount_spent)},
                             min_amount_spent=min_amount_spent)
Ejemplo n.º 17
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     price = obj.get_price(self.discounts, self.taxes)
     price = price.gross if self.display_gross else price.net
     label = pgettext_lazy(
         "Variant choice field label", "%(variant_label)s - %(price)s"
     ) % {"variant_label": variant_label, "price": amount(price)}
     return label
Ejemplo n.º 18
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     price = obj.get_price(self.discounts, self.taxes)
     price = price.gross if self.display_gross else price.net
     label = pgettext_lazy(
         'Variant choice field label',
         '%(variant_label)s - %(price)s') % {
             'variant_label': variant_label, 'price': amount(price)}
     return label
Ejemplo n.º 19
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     label = pgettext_lazy(
         'Variant choice field label',
         '%(variant_label)s - %(price)s') % {
             'variant_label': variant_label,
             'price': amount(
                 obj.get_price_per_item(discounts=self.discounts).gross)}
     return label
Ejemplo n.º 20
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     price = obj.get_price(self.discounts, self.taxes)
     price = price.gross if self.display_gross else price.net
     label = pgettext_lazy(
         'Variant choice field label',
         '%(variant_label)s - %(price)s') % {
             'variant_label': variant_label, 'price': amount(price)}
     return label
Ejemplo n.º 21
0
 def validate_min_amount_spent(self, value):
     min_amount_spent = self.min_amount_spent
     if min_amount_spent and value.gross < min_amount_spent:
         msg = pgettext(
             'Voucher not applicable',
             'This offer is only valid for orders over %(amount)s.')
         raise NotApplicable(
             msg % {'amount': amount(min_amount_spent)},
             min_amount_spent=min_amount_spent)
Ejemplo n.º 22
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     price = obj.get_price(self.discounts, self.taxes)
     price = price.gross if self.display_gross else price.net
     label = pgettext_lazy("Variant choice field label",
                           "%(variant_label)s - %(price)s") % {
                               "variant_label": variant_label,
                               "price": amount(price)
                           }
     return label
Ejemplo n.º 23
0
 def validate_min_amount_spent(self, value):
     min_amount_spent = self.min_amount_spent
     if min_amount_spent and value < min_amount_spent:
         msg = pgettext(
             "Voucher not applicable",
             "This offer is only valid for orders over %(amount)s.",
         )
         raise NotApplicable(
             msg % {"amount": amount(min_amount_spent)},
             min_amount_spent=min_amount_spent,
         )
Ejemplo n.º 24
0
 def label_from_instance(self, obj):
     variant_label = smart_text(obj)
     price = self.extensions.apply_taxes_to_product(
         obj.product, obj.get_price(self.discounts), self.country)
     price = price.gross if self.display_gross else price.net
     label = pgettext_lazy("Variant choice field label",
                           "%(variant_label)s - %(price)s") % {
                               "variant_label": variant_label,
                               "price": amount(price)
                           }
     return label
Ejemplo n.º 25
0
def test_non_cannonical_locale_zh_CN(money_fixture, settings):
    # Test detecting an error that occur for language 'zh_CN' for which
    # the canonical code is 'zh_Hans_CN', see:
    #     Babel 1.0+ doesn't support `zh_CN`
    #     https://github.com/python-babel/babel/issues/37
    # This should now work, as we are using:
    #     `Locale.parse('zh_CN')`
    # which does the conversion to the canonical name.

    # Making sure the default "LANGUAGE_CODE" is "en_US"
    settings.LANGUAGE_CODE = 'en_US'

    # Checking format of the default locale
    amount = prices_i18n.amount(money_fixture, format='html')
    assert amount == '<span class="currency">$</span>10.00'

    # Checking if 'zh_CN' has changed the format
    translation.activate('zh_CN')
    amount = prices_i18n.amount(money_fixture, format='html')
    assert amount == '<span class="currency">US$</span>10.00'  # 'US' before '$'
Ejemplo n.º 26
0
def test_non_cannonical_locale_zh_CN(money_fixture, settings):
    # Test detecting an error that occur for language 'zh_CN' for which
    # the canonical code is 'zh_Hans_CN', see:
    #     Babel 1.0+ doesn't support `zh_CN`
    #     https://github.com/python-babel/babel/issues/37
    # This should now work, as we are using:
    #     `Locale.parse('zh_CN')`
    # which does the conversion to the canonical name.

    # Making sure the default "LANGUAGE_CODE" is "en_US"
    settings.LANGUAGE_CODE = "en_US"

    # Checking format of the default locale
    amount = prices_i18n.amount(money_fixture, format="html")
    assert amount == '<span class="currency">$</span>10.00'

    # Checking if 'zh_CN' has changed the format
    translation.activate("zh_CN")
    amount = prices_i18n.amount(money_fixture, format="html")
    assert amount == '<span class="currency">US$</span>10.00'  # 'US' before '$'
Ejemplo n.º 27
0
def test_non_existing_locale(money_fixture):
    # Test detecting an error that occur for language 'zh_CN' for which
    # the canonical code is 'zh_Hans_CN', see:
    #     Babel 1.0+ doesn't support `zh_CN`
    #     https://github.com/python-babel/babel/issues/37
    # Though to make this test more reliable we mock the language with totally
    # made up code 'oO_Oo' as the 'zh_CN' "alias" might work in the future, see:
    #     Babel needs to support Fuzzy Locales
    #     https://github.com/python-babel/babel/issues/30
    translation.activate('oO_Oo')
    amount = prices_i18n.amount(money_fixture, format='html')
    assert amount  # No exception, success!
Ejemplo n.º 28
0
def test_non_existing_locale(money_fixture):
    # Test detecting an error that occur for language 'zh_CN' for which
    # the canonical code is 'zh_Hans_CN', see:
    #     Babel 1.0+ doesn't support `zh_CN`
    #     https://github.com/python-babel/babel/issues/37
    # Though to make this test more reliable we mock the language with totally
    # made up code 'oO_Oo' as the 'zh_CN' "alias" might work in the future, see:
    #     Babel needs to support Fuzzy Locales
    #     https://github.com/python-babel/babel/issues/30
    translation.activate("oO_Oo")
    amount = prices_i18n.amount(money_fixture, format="html")
    assert amount  # No exception, success!
Ejemplo n.º 29
0
def refund_payment(request, order_pk, payment_pk):
    order = get_object_or_404(Order, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = payment.captured_amount
    form = RefundPaymentForm(request.POST or None, payment=payment,
                             initial={'amount': amount})
    if form.is_valid() and form.refund():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy(
            'Dashboard message related to a payment',
            'Refunded %(amount)s') % {'amount': prices_i18n.amount(amount)}
        order.history.create(content=msg, user=request.user)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {'captured': payment.captured_amount, 'currency': payment.currency,
           'form': form, 'order': order, 'payment': payment}
    return TemplateResponse(request, 'dashboard/order/modal/refund.html', ctx,
                            status=status)
Ejemplo n.º 30
0
def capture_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related('payments')
    order = get_object_or_404(orders, pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = order.total.quantize('0.01').gross
    form = CapturePaymentForm(request.POST or None, payment=payment,
                              initial={'amount': amount})
    if form.is_valid() and form.capture():
        amount = form.cleaned_data['amount']
        msg = pgettext_lazy(
            'Dashboard message related to a payment',
            'Captured %(amount)s') % {'amount': prices_i18n.amount(amount)}
        order.history.create(content=msg, user=request.user)
        messages.success(request, msg)
        return redirect('dashboard:order-details', order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {'captured': payment.captured_amount, 'currency': payment.currency,
           'form': form, 'order': order, 'payment': payment}
    return TemplateResponse(request, 'dashboard/order/modal/capture.html', ctx,
                            status=status)
Ejemplo n.º 31
0
def capture_payment(request, order_pk, payment_pk):
    orders = Order.objects.confirmed().prefetch_related("payments")
    order = get_object_or_404(orders.prefetch_related("lines", "user"), pk=order_pk)
    payment = get_object_or_404(order.payments, pk=payment_pk)
    amount = order.total.gross
    form = CapturePaymentForm(
        request.POST or None, payment=payment, initial={"amount": amount.amount}
    )
    if form.is_valid() and form.capture(request.user):
        msg = pgettext_lazy(
            "Dashboard message related to a payment", "Captured %(amount)s"
        ) % {"amount": prices_i18n.amount(amount)}
        events.payment_captured_event(
            order=order, user=request.user, amount=amount.amount, payment=payment
        )
        messages.success(request, msg)
        return redirect("dashboard:order-details", order_pk=order.pk)
    status = 400 if form.errors else 200
    ctx = {"captured": amount, "form": form, "order": order, "payment": payment}
    return TemplateResponse(
        request, "dashboard/order/modal/capture.html", ctx, status=status
    )
Ejemplo n.º 32
0
 def resolve_localized(self, info):
     return prices_i18n.amount(self)
Ejemplo n.º 33
0
 def get_ajax_label(self, discounts=None):
     price = self.get_price(discounts).gross
     return '%s, %s, %s' % (
         self.sku, self.display_product(), prices_i18n.amount(price))
Ejemplo n.º 34
0
def discount_as_negative(discount, html=False):
    zero = Money(0, currency=discount.currency)
    return prices_i18n.amount(zero - discount, 'html' if html else 'text')
Ejemplo n.º 35
0
def display_task_event(task_event):
    """This function is used to keep the  backwards compatibility
    with the old dashboard and new type of task events
    (storing enums instead of messages)
    """
    event_type = task_event.type
    params = task_event.parameters
    if event_type == TaskEvents.PLACED_FROM_DRAFT.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Task created from draft task by %(user_name)s' %
            {'user_name': task_event.user})
    if event_type == TaskEvents.PAYMENT_VOIDED.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Payment was voided by %(user_name)s' %
            {'user_name': task_event.user})
    if event_type == TaskEvents.PAYMENT_REFUNDED.value:
        amount = get_money_from_params(params['amount'])
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Successfully refunded: %(amount)s' %
            {'amount': prices_i18n.amount(amount)})
    if event_type == TaskEvents.PAYMENT_CAPTURED.value:
        amount = get_money_from_params(params['amount'])
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Successfully captured: %(amount)s' %
            {'amount': prices_i18n.amount(amount)})
    if event_type == TaskEvents.TASK_MARKED_AS_PAID.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Task manually marked as paid by %(user_name)s' %
            {'user_name': task_event.user})
    if event_type == TaskEvents.CANCELED.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Task was canceled by %(user_name)s' %
            {'user_name': task_event.user})
    if event_type == TaskEvents.FULFILLMENT_REAVAILED_ITEMS.value:
        return npgettext_lazy('Dashboard message related to an task',
                              'We reavailed %(quantity)d item',
                              'We reavailed %(quantity)d items',
                              number='quantity') % {
                                  'quantity': params['quantity']
                              }
    if event_type == TaskEvents.NOTE_ADDED.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            '%(user_name)s added note: %(note)s' % {
                'note': params['message'],
                'user_name': task_event.user
            })
    if event_type == TaskEvents.FULFILLMENT_CANCELED.value:
        return pgettext_lazy(
            'Dashboard message',
            'Fulfillment #%(fulfillment)s canceled by %(user_name)s') % {
                'fulfillment': params['composed_id'],
                'user_name': task_event.user
            }
    if event_type == TaskEvents.FULFILLMENT_FULFILLED_ITEMS.value:
        return npgettext_lazy('Dashboard message related to an task',
                              'Fulfilled %(quantity_fulfilled)d item',
                              'Fulfilled %(quantity_fulfilled)d items',
                              number='quantity_fulfilled') % {
                                  'quantity_fulfilled': params['quantity']
                              }
    if event_type == TaskEvents.PLACED.value:
        return pgettext_lazy('Dashboard message related to an task',
                             'Task was placed')
    if event_type == TaskEvents.TASK_FULLY_PAID.value:
        return pgettext_lazy('Dashboard message related to an task',
                             'Task was fully paid')
    if event_type == TaskEvents.EMAIL_SENT.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            '%(email_type)s email was sent to the customer '
            '(%(email)s)') % {
                'email_type': EMAIL_CHOICES[params['email_type']],
                'email': params['email']
            }
    if event_type == TaskEvents.UPDATED.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Task details were updated by %(user_name)s' %
            {'user_name': task_event.user})
    if event_type == TaskEvents.TRACKING_UPDATED.value:
        return pgettext_lazy(
            'Dashboard message related to an task',
            'Fulfillment #%(fulfillment)s tracking was updated to'
            ' %(tracking_number)s by %(user_name)s') % {
                'fulfillment': params['composed_id'],
                'tracking_number': params['tracking_number'],
                'user_name': task_event.user
            }
    if event_type == TaskEvents.OVERSOLD_ITEMS.value:
        return npgettext_lazy('Dashboard message related to an task',
                              '%(quantity)d line item oversold on this task.',
                              '%(quantity)d line items oversold on this task.',
                              number='quantity') % {
                                  'quantity': len(params['oversold_items'])
                              }

    if event_type == TaskEvents.OTHER.value:
        return task_event.parameters['message']
    raise ValueError('Not supported event type: %s' % (event_type))
Ejemplo n.º 36
0
def discount_as_negative(discount, html=False):
    zero = Money(0, discount.currency)
    return prices_i18n.amount(zero - discount, 'html' if html else 'text')
Ejemplo n.º 37
0
 def get_ajax_label(self, discounts=None):
     price = self.get_price(discounts).gross
     return '%s, %s, %s' % (self.sku, self.display_skill(),
                            prices_i18n.amount(price))
Ejemplo n.º 38
0
def test_templatetag_i18n_amount_wrong_param(money_fixture):
    amount = prices_i18n.amount(money_fixture, format="test")
    assert amount == "$10.00"
Ejemplo n.º 39
0
 def get_variant_label(variant, discounts):
     return '%s, %s, %s' % (
         variant.sku, variant.display_product(),
         prices_i18n.amount(variant.get_price_per_item(discounts).gross))
Ejemplo n.º 40
0
def test_templatetag_i18n_amount_wrong_param(money_fixture):
    amount = prices_i18n.amount(money_fixture, format='test')
    assert amount == '$10.00'
Ejemplo n.º 41
0
def test_templatetag_i18n_amount_html(money_fixture):
    amount = prices_i18n.amount(money_fixture, format="html")
    assert amount == '<span class="currency">$</span>10.00'
Ejemplo n.º 42
0
def display_order_event(order_event: OrderEvent):
    """This function is used to keep the backwards compatibility
        with the old dashboard and new type of order events
        (storing enums instead of messages)
        """
    event_type = order_event.type
    params = order_event.parameters
    if event_type == events.OrderEvents.PLACED_FROM_DRAFT:
        return pgettext_lazy(
            "Dashboard message related to an order", "Order placed from draft order"
        )
    if event_type == events.OrderEvents.PAYMENT_VOIDED:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "Payment was voided by %(user_name)s" % {"user_name": order_event.user},
        )
    if event_type == events.OrderEvents.PAYMENT_REFUNDED:
        amount = get_money_from_params(params["amount"])
        return pgettext_lazy(
            "Dashboard message related to an order",
            "Successfully refunded: %(amount)s"
            % {"amount": prices_i18n.amount(amount)},
        )
    if event_type == events.OrderEvents.PAYMENT_CAPTURED:
        amount = get_money_from_params(params["amount"])
        return pgettext_lazy(
            "Dashboard message related to an order",
            "Successfully captured: %(amount)s"
            % {"amount": prices_i18n.amount(amount)},
        )
    if event_type == events.OrderEvents.ORDER_MARKED_AS_PAID:
        return pgettext_lazy(
            "Dashboard message related to an order", "Order manually marked as paid"
        )
    if event_type == events.OrderEvents.CANCELED:
        return pgettext_lazy(
            "Dashboard message related to an order", "Order was canceled"
        )
    if event_type == events.OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:
        return npgettext_lazy(
            "Dashboard message related to an order",
            "We restocked %(quantity)d item",
            "We restocked %(quantity)d items",
            number="quantity",
        ) % {"quantity": params["quantity"]}
    if event_type == events.OrderEvents.NOTE_ADDED:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "%(user_name)s added note: %(note)s"
            % {"note": params["message"], "user_name": order_event.user},
        )
    if event_type == events.OrderEvents.FULFILLMENT_CANCELED:
        return pgettext_lazy(
            "Dashboard message",
            "Fulfillment #%(fulfillment)s canceled by %(user_name)s",
        ) % {"fulfillment": params["composed_id"], "user_name": order_event.user}
    if event_type == events.OrderEvents.FULFILLMENT_FULFILLED_ITEMS:
        return pgettext_lazy(
            "Dashboard message related to an order", "Fulfilled some items"
        )
    if event_type == events.OrderEvents.PLACED:
        return pgettext_lazy(
            "Dashboard message related to an order", "Order was placed"
        )
    if event_type == events.OrderEvents.ORDER_FULLY_PAID:
        return pgettext_lazy(
            "Dashboard message related to an order", "Order was fully paid"
        )
    if event_type == events.OrderEvents.EMAIL_SENT:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "%(email_type)s email was sent to the customer " "(%(email)s)",
        ) % {
            "email_type": EMAIL_CHOICES[params["email_type"]],
            "email": params["email"],
        }
    if event_type == events.OrderEvents.TRACKING_UPDATED:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "Fulfillment #%(fulfillment)s tracking was updated to"
            " %(tracking_number)s by %(user_name)s",
        ) % {
            "fulfillment": params["composed_id"],
            "tracking_number": params["tracking_number"],
            "user_name": order_event.user,
        }
    if event_type == events.OrderEvents.DRAFT_CREATED:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "The draft was created by %(user_name)s",
        ) % {"user_name": order_event.user}
    if event_type == events.OrderEvents.DRAFT_ADDED_PRODUCTS:
        return pgettext_lazy(
            "Dashboard message related to an order", "%(user_name)s added some products"
        ) % {"user_name": order_event.user}
    if event_type == events.OrderEvents.DRAFT_REMOVED_PRODUCTS:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "%(user_name)s removed some products",
        ) % {"user_name": order_event.user}
    if event_type == events.OrderEvents.OVERSOLD_ITEMS:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "%(user_name)s placed the order by bypassing oversold items",
        ) % {"user_name": order_event.user}
    if event_type == events.OrderEvents.UPDATED_ADDRESS:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "The order address was updated by %(user_name)s",
        ) % {"user_name": order_event.user}
    if event_type == events.OrderEvents.PAYMENT_FAILED:
        return pgettext_lazy(
            "Dashboard message related to an order",
            "The payment was failed by %(user_name)s",
        ) % {"user_name": order_event.user}

    if event_type == events.OrderEvents.OTHER:
        return order_event.parameters["message"]
    raise ValueError("Not supported event type: %s" % (event_type))
Ejemplo n.º 43
0
def test_templatetag_i18n_amount_html(money_fixture):
    amount = prices_i18n.amount(money_fixture, format='html')
    assert amount == '<span class="currency">$</span>10.00'
Ejemplo n.º 44
0
 def get_variant_label(variant, discounts):
     return '%s, %s, %s' % (
         variant.sku, variant.display_product(),
         prices_i18n.amount(variant.get_price_per_item(discounts).gross))
Ejemplo n.º 45
0
def test_templatetag_i18n_amount(money_fixture):
    amount = prices_i18n.amount(money_fixture)
    assert amount == '$10.00'
Ejemplo n.º 46
0
 def resolve_localized(self, info):
     return prices_i18n.amount(self)
Ejemplo n.º 47
0
 def resolve_localized(root, _info):
     return prices_i18n.amount(root)
Ejemplo n.º 48
0
def test_templatetag_i18n_amount(money_fixture):
    amount = prices_i18n.amount(money_fixture)
    assert amount == "$10.00"
Ejemplo n.º 49
0
def display_order_event(order_event):
    """This function is used to keep the  backwards compatibility
    with the old dashboard and new type of order events
    (storing enums instead of messages)
    """
    event_type = order_event.type
    params = order_event.parameters
    if event_type == OrderEvents.PLACED_FROM_DRAFT.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order created from draft order by %(user_name)s' %
            {'user_name': order_event.user})
    if event_type == OrderEvents.PAYMENT_RELEASED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Payment was released by %(user_name)s' %
            {'user_name': order_event.user})
    if event_type == OrderEvents.PAYMENT_REFUNDED.value:
        amount = Money(amount=params['amount'],
                       currency=settings.DEFAULT_CURRENCY)
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Successfully refunded: %(amount)s' %
            {'amount': prices_i18n.amount(amount)})
    if event_type == OrderEvents.PAYMENT_CAPTURED.value:
        amount = Money(amount=params['amount'],
                       currency=settings.DEFAULT_CURRENCY)
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Successfully captured: %(amount)s' %
            {'amount': prices_i18n.amount(amount)})
    if event_type == OrderEvents.ORDER_MARKED_AS_PAID.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order manually marked as paid by %(user_name)s' %
            {'user_name': order_event.user})
    if event_type == OrderEvents.CANCELED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order was canceled by %(user_name)s' %
            {'user_name': order_event.user})
    if event_type == OrderEvents.FULFILLMENT_RESTOCKED_ITEMS.value:
        return npgettext_lazy('Dashboard message related to an order',
                              'We restocked %(quantity)d item',
                              'We restocked %(quantity)d items',
                              'quantity') % {
                                  'quantity': params['quantity']
                              }
    if event_type == OrderEvents.NOTE_ADDED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            '%(user_name)s added note: %(note)s' % {
                'note': params['message'],
                'user_name': order_event.user
            })
    if event_type == OrderEvents.FULFILLMENT_CANCELED.value:
        return pgettext_lazy(
            'Dashboard message',
            'Fulfillment #%(fulfillment)s canceled by %(user_name)s') % {
                'fulfillment': params['composed_id'],
                'user_name': order_event.user
            }
    if event_type == OrderEvents.FULFILLMENT_FULFILLED_ITEMS.value:
        return npgettext_lazy('Dashboard message related to an order',
                              'Fulfilled %(quantity_fulfilled)d item',
                              'Fulfilled %(quantity_fulfilled)d items',
                              'quantity_fulfilled') % {
                                  'quantity_fulfilled': params['quantity']
                              }
    if event_type == OrderEvents.PLACED.value:
        return pgettext_lazy('Dashboard message related to an order',
                             'Order was placed')
    if event_type == OrderEvents.ORDER_FULLY_PAID.value:
        return pgettext_lazy('Dashboard message related to an order',
                             'Order was fully paid')
    if event_type == OrderEvents.EMAIL_SENT.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            '%(email_type)s email was sent to the customer '
            '(%(email)s)') % {
                'email_type': EMAIL_CHOICES[params['email_type']],
                'email': params['email']
            }
    if event_type == OrderEvents.UPDATED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order details were updated by %(user_name)s' %
            {'user_name': order_event.user})
    if event_type == OrderEvents.TRACKING_UPDATED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Fulfillment #%(fulfillment)s tracking was updated to'
            ' %(tracking_number)s by %(user_name)s') % {
                'fulfillment': params['composed_id'],
                'tracking_number': params['tracking_number'],
                'user_name': order_event.user
            }

    if event_type == OrderEvents.OTHER.value:
        return order_event.parameters['message']
    raise ValueError('Not supported event type: %s' % (event_type))
Ejemplo n.º 50
0
def test_templatetag_i18n_amount(amount_fixture):
    amount = prices_i18n.amount(amount_fixture)
    assert amount == '$10.00'
Ejemplo n.º 51
0
def display_order_event(order_event):
    """This function is used to keep the  backwards compatibility
    with the old dashboard and new type of order events
    (storing enums instead of messages)
    """
    event_type = order_event.type
    params = order_event.parameters
    if event_type == OrderEvents.PLACED_FROM_DRAFT.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order created from draft order by %(user_name)s' % {
                'user_name': order_event.user})
    if event_type == OrderEvents.PAYMENT_RELEASED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Payment was released by %(user_name)s' % {
                'user_name': order_event.user})
    if event_type == OrderEvents.PAYMENT_REFUNDED.value:
        amount = Money(
            amount=params['amount'], currency=settings.DEFAULT_CURRENCY)
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Successfully refunded: %(amount)s' % {
                'amount': prices_i18n.amount(amount)})
    if event_type == OrderEvents.PAYMENT_CAPTURED.value:
        amount = Money(
            amount=params['amount'], currency=settings.DEFAULT_CURRENCY)
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Successfully captured: %(amount)s' % {
                'amount': prices_i18n.amount(amount)})
    if event_type == OrderEvents.ORDER_MARKED_AS_PAID.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order manually marked as paid by %(user_name)s' % {
                'user_name': order_event.user})
    if event_type == OrderEvents.CANCELED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order was canceled by %(user_name)s' % {
                'user_name': order_event.user})
    if event_type == OrderEvents.FULFILLMENT_RESTOCKED_ITEMS.value:
        return npgettext_lazy(
            'Dashboard message related to an order',
            'We restocked %(quantity)d item',
            'We restocked %(quantity)d items',
            'quantity') % {'quantity': params['quantity']}
    if event_type == OrderEvents.NOTE_ADDED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            '%(user_name)s added note: %(note)s' % {
                'note': params['message'],
                'user_name': order_event.user})
    if event_type == OrderEvents.FULFILLMENT_CANCELED.value:
        return pgettext_lazy(
            'Dashboard message',
            'Fulfillment #%(fulfillment)s canceled by %(user_name)s') % {
                'fulfillment': params['composed_id'],
                'user_name': order_event.user}
    if event_type == OrderEvents.FULFILLMENT_FULFILLED_ITEMS.value:
        return npgettext_lazy(
            'Dashboard message related to an order',
            'Fulfilled %(quantity_fulfilled)d item',
            'Fulfilled %(quantity_fulfilled)d items',
            'quantity_fulfilled') % {
                'quantity_fulfilled': params['quantity']}
    if event_type == OrderEvents.PLACED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order was placed')
    if event_type == OrderEvents.ORDER_FULLY_PAID.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order was fully paid')
    if event_type == OrderEvents.EMAIL_SENT.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            '%(email_type)s email was sent to the customer '
            '(%(email)s)') % {
                'email_type': EMAIL_CHOICES[params['email_type']],
                'email': params['email']}
    if event_type == OrderEvents.UPDATED.value:
        return pgettext_lazy(
            'Dashboard message related to an order',
            'Order details were updated by %(user_name)s' % {
                'user_name': order_event.user})
    if event_type == OrderEvents.OTHER.value:
        return order_event.parameters['message']
    raise ValueError('Not supported event type: %s' % (event_type))
Ejemplo n.º 52
0
def test_templatetag_i18n_amount_wrong_param(amount_fixture):
    amount = prices_i18n.amount(amount_fixture, format='test')
    assert amount == '$10.00'