from quotation.models import Order_Item
from django import template

register = template.Library()

@register.filter(name='get_status_label')
def get_status_label(value):
    return dict(Order_Item.STATUS_CHOICES).get(value, 'Unknown')
    
@register.filter(name='currency')
def currency(value):
    try:
        value = float(value)
        return "{:,.2f}".format(value)
    except (ValueError, TypeError):
        return value
        
@register.simple_tag(name='product_list_to_bill_count')
def product_list_to_bill_count(value):
    return value
    # order_items= Order_Item.objects.filter(serial_number__isnull=True).values('product__id','product__product_name','product__sku').annotate(qty=Count('product__id'))
    # order_item=[]
    # for or1 in order_items:
    #     sr=SerialNumber.objects.filter(product__id=or1['product__id'],customer=None).count()
    #     if or1['qty']-sr == 0:
    #         pass
    #     else:
    #         or1['reuiredbilledqty']=or1['qty']-sr
    #         order_item.append(or1)
    # if len(order_item) > 0:
    #     return {'unread_count': len(order_item)}
    # else:
    #     return {'unread_count': 0 }
