From d0be07ecd577a01ff97a052305b0d08ed167778a Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 1 Apr 2020 17:07:10 +0530 Subject: [PATCH] Add custom_tag get_line_item_from_hosting_order_charge --- datacenterlight/templatetags/custom_tags.py | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index 0cb18e5b..7cc68f07 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -6,7 +6,7 @@ from django.core.urlresolvers import resolve, reverse from django.utils.safestring import mark_safe from django.utils.translation import activate, get_language, ugettext_lazy as _ -from hosting.models import GenericProduct +from hosting.models import GenericProduct, HostingOrder from utils.hosting_utils import get_ip_addresses logger = logging.getLogger(__name__) @@ -63,6 +63,35 @@ def escaped_line_break(value): return value.replace("\\n", "\n") +@register.filter('get_line_item_from_hosting_order_charge') +def get_line_item_from_hosting_order_charge(hosting_order_id, receipt_url): + """ + Returns ready-to-use "html" line item to be shown for a charge in the + invoice list page + + :param hosting_order_id: the HostingOrder id + :return: + """ + hosting_order = HostingOrder.objects.get(id = hosting_order_id) + if hosting_order.stripe_charge_id: + return mark_safe(""" + {product_name} + {created_at} + {total} + + {see_invoice_text} + + """.format( + product_name=hosting_order.generic_product.product_name.capitalize(), + created_at=hosting_order.created_at.strftime('%Y-%m-%d'), + total='%.2f' % (hosting_order.price), + receipt_url=receipt_url, + see_invoice_text=_("See Invoice") + )) + else: + return "" + + @register.filter('get_line_item_from_stripe_invoice') def get_line_item_from_stripe_invoice(invoice): """