# -*- coding: utf-8 -*-
# from django import forms

from django.forms import ModelForm
from .models import *

from django import forms
from django.utils.translation import gettext_lazy as _


class EntAppForm(ModelForm):
    class Meta:
        model = EntApplication
        fields = '__all__'
        widgets = {
            'company': forms.HiddenInput(),
            'staff':forms.HiddenInput(),
            'user':forms.HiddenInput(),
            'department':forms.HiddenInput(),
        }

    def __init__(self, *args, **kwargs):
        self._user = kwargs.pop('user')
        super(EntAppForm, self).__init__(*args, **kwargs)  
        self.fields['category'].queryset = Category.objects.filter(company_id=self._user.ancestor_id)


class EntAppPrdForm(ModelForm):
    class Meta:
        model=EntAppProduct
        fields = '__all__'
        widgets = {
            'product': forms.HiddenInput(),            
        }
EntAppPrdFormset=forms.models.inlineformset_factory(EntApplication,EntAppProduct, EntAppPrdForm, extra=0, can_delete=True)        



class ActAppForm(ModelForm):
    class Meta:
        model = ActApplication
        fields = '__all__'
        widgets = {
            'company': forms.HiddenInput(),           
            'user':forms.HiddenInput(),            
        }

    def __init__(self, *args, **kwargs):
        self._user = kwargs.pop('user')
        super(ActAppForm, self).__init__(*args, **kwargs)  
        self.fields['category'].queryset = Category.objects.filter(company_id=self._user.ancestor_id)
        self.fields['dinner_dt'].widget.attrs['class'] = "datepicker"


class ActAppPrdForm(ModelForm):
    class Meta:
        model=ActAppProduct
        fields = '__all__'
        widgets = {
            'product': forms.HiddenInput(),            
        }

ActAppPrdFormset=forms.models.inlineformset_factory(ActApplication,ActAppProduct, ActAppPrdForm, extra=0, can_delete=True)  
