# -*- coding: utf-8 -*-
from django import forms
from django.forms import ModelForm
from .models import *
from product.models import Product
from django.utils.translation import gettext_lazy as _



#2020-10-02
class SchemeForm(ModelForm):
    class Meta:
        model = GiftsScheme
        fields = '__all__'
        widgets = {
            'company': forms.HiddenInput(),
            'user':forms.HiddenInput(),    
            'div_ids': forms.HiddenInput(),
            'subdiv_ids': forms.HiddenInput(),   
        }
    def __init__(self, *args, **kwargs):
        super(SchemeForm, self).__init__(*args, **kwargs)
        self.fields['tm_app_latest'].widget.attrs['class'] = "datetimepicker"
        


class SchemProductForm(ModelForm):
    class Meta:
        model = SchemeProducts
        fields = '__all__'
        widgets = {
            'scheme': forms.HiddenInput(),
            'product':forms.HiddenInput(),  
        }

    def __init__(self, *args, **kwargs):
        super(SchemProductForm, self).__init__(*args, **kwargs)
        self.fields['product'].widget.attrs['class'] = "pid"
SchemeProductFormset=forms.models.inlineformset_factory(GiftsScheme, SchemeProducts,SchemProductForm, extra=0, can_delete=True)


class SchemeMaterialForm(ModelForm):
    class Meta:
        model = SchemeMaterials
        fields = '__all__'
        widgets = {
            'scheme': forms.HiddenInput(),
            'material':forms.HiddenInput(),  
            'status':forms.HiddenInput(), 
        }

    def __init__(self, *args, **kwargs):
        super(SchemeMaterialForm, self).__init__(*args, **kwargs)
        self.fields['material'].widget.attrs['class'] = "mid"
SchemeMaterialFormset=forms.models.inlineformset_factory(GiftsScheme, SchemeMaterials,SchemeMaterialForm, extra=0, can_delete=True)






class GiftApplicationForm(ModelForm):
    class Meta:
        model = GiftsApplication
        fields = '__all__'
        widgets = {
            'company': forms.HiddenInput(),
            'scheme':forms.HiddenInput(),
            'ancestor_id':forms.HiddenInput(),
            'user':forms.HiddenInput(),             
        }   
        


class GApplicationProductForm(ModelForm):
    class Meta:
        model = GiftsApplication
        fields = '__all__'
        widgets = {
            'application': forms.HiddenInput(),
            'product':forms.HiddenInput(),  
        }

    def __init__(self, *args, **kwargs):
        super(GApplicationProductForm, self).__init__(*args, **kwargs)
        self.fields['product'].widget.attrs['class'] = "pid"
GApplicationProductFormset=forms.models.inlineformset_factory(GiftsApplication, ApplicationProducts,GApplicationProductForm, extra=0, can_delete=True)


class GApplicationMaterialForm(ModelForm):
    class Meta:
        model = ApplicationMaterials
        fields = '__all__'
        widgets = {
            'application': forms.HiddenInput(),
            'material':forms.HiddenInput(),              
        }

    def __init__(self, *args, **kwargs):
        super(GApplicationMaterialForm, self).__init__(*args, **kwargs)
        self.fields['material'].widget.attrs['class'] = "mid"
GApplicationMaterialFormset=forms.models.inlineformset_factory(GiftsApplication, ApplicationMaterials,GApplicationMaterialForm, extra=0, can_delete=True)




class GiftRequisitionForm(ModelForm):
    class Meta:
        model = GiftsRequisition
        fields = '__all__'
        widgets = {
            'company': forms.HiddenInput(),
            'ancestor_id':forms.HiddenInput(),
            'scheme':forms.HiddenInput(),
            'user':forms.HiddenInput(),   
            'agent':forms.HiddenInput(),
            'status':forms.HiddenInput(),
            'salesman':forms.HiddenInput(),
            'saldiv':forms.HiddenInput(),
            'subdiv':forms.HiddenInput()
        }   
        


class GRequisitionProductForm(ModelForm):
    class Meta:
        model = RequisitionProducts
        fields = '__all__'
        widgets = {
            'requisition': forms.HiddenInput(),
            'product':forms.HiddenInput(),  
        }

    def __init__(self, *args, **kwargs):
        super(GRequisitionProductForm, self).__init__(*args, **kwargs)
        self.fields['product'].widget.attrs['class'] = "pid"
GRequisitionProductFormset=forms.models.inlineformset_factory(GiftsRequisition, RequisitionProducts,GRequisitionProductForm, extra=0, can_delete=True)



class GRequisitionMaterialForm(ModelForm):
    class Meta:
        model = RequisitionMaterials
        fields = '__all__'
        widgets = {
            'requisition': forms.HiddenInput(),
            'material':forms.HiddenInput(),              
        }

    def __init__(self, *args, **kwargs):
        super(GRequisitionMaterialForm, self).__init__(*args, **kwargs)
        self.fields['material'].widget.attrs['class'] = "mid"
GRequisitionMaterialFormset=forms.models.inlineformset_factory(GiftsRequisition, RequisitionMaterials,GRequisitionMaterialForm, extra=0, can_delete=True)
