#coding=utf-8
import django_filters
from models import FinanceCategory, FinancePurpose, dbFinanceIncome
from apps.base import clean_datetime_range

class FinanceCategoryFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(name='name', lookup_expr='icontains')

    class Meta:
        model = FinanceCategory
        fields = "__all__"


class FinancePurposeFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(name='name', lookup_expr='icontains')
    category_name = django_filters.CharFilter(name='category__name', lookup_expr='icontains')

    class Meta:
        model = FinancePurpose
        fields = "__all__"

class FinanceIncomeFilter(django_filters.FilterSet):
    referer_no = django_filters.CharFilter(name='referer_no', lookup_expr='icontains')
    account_name = django_filters.CharFilter(name='account__name', lookup_expr='icontains')

    class Meta:
        model = dbFinanceIncome
        fields = "__all__"

    def __init__(self, data=None, *args, **kwargs):
        data = clean_datetime_range(data, 'create_time')
        super(FinanceIncomeFilter, self).__init__(data, *args, **kwargs)
