from django_filters import rest_framework as filters
from apps.mpr.models import PurchaseRequisition, WarehouseEntry, WarehouseStock, MaterialRequisition


class PurchaseRequisitionFilter(filters.FilterSet):
    req_date_after = filters.DateFilter(field_name='req_date', lookup_expr='gte')
    req_date_before = filters.DateFilter(field_name='req_date', lookup_expr='lte')

    class Meta:
        model = PurchaseRequisition
        fields = ['belong_dept', 'req_date_after', 'req_date_before']


class WarehouseEntryFilter(filters.FilterSet):
    entry_date_after = filters.DateFilter(field_name='entry_date', lookup_expr='gte')
    entry_date_before = filters.DateFilter(field_name='entry_date', lookup_expr='lte')

    class Meta:
        model = WarehouseEntry
        fields = ['warehouse', 'entry_type', 'entry_method', 'entry_date_after', 'entry_date_before']


class WarehouseStockFilter(filters.FilterSet):
    entry_date_after = filters.DateFilter(field_name='entry_date', lookup_expr='gte')
    entry_date_before = filters.DateFilter(field_name='entry_date', lookup_expr='lte')

    class Meta:
        model = WarehouseStock
        fields = ['warehouse', 'entry_type', 'entry_method', 'supplier_name',
                  'invoice_received', 'status', 'entry_date_after', 'entry_date_before']


class MaterialRequisitionFilter(filters.FilterSet):
    req_date_after = filters.DateFilter(field_name='req_date', lookup_expr='gte')
    req_date_before = filters.DateFilter(field_name='req_date', lookup_expr='lte')

    class Meta:
        model = MaterialRequisition
        fields = ['belong_dept', 'req_date_after', 'req_date_before']
