# -*- coding: utf-8 -*-
from django import forms
from django.forms import ModelForm
from .models import *

from django.utils.translation import gettext_lazy as _




class StorehouseForm(ModelForm):
    class Meta:
        model=Storehouse
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),                
        }


class BatchForm(ModelForm):
    class Meta:
        model=Batch
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),        
            'vtype':forms.HiddenInput(),   
            'user':forms.HiddenInput(),  
            'order':forms.HiddenInput(),   
            'customer':forms.HiddenInput(),  
            'vendors':forms.HiddenInput(), 
        }
    def __init__(self,* args,** kwargs):
        super(BatchForm,self).__init__(* args,** kwargs)  
        self.fields['dt_voucher'].widget.attrs['class'] = "datepicker"
    

class StkDetailsForm(ModelForm):
    class Meta:
        model=StkDetails
        fields='__all__'
        widgets={
            'batch':forms.HiddenInput(),                   
            'vtype':forms.HiddenInput(),   
            'user':forms.HiddenInput(),
            'materials':forms.HiddenInput(),
            'packaging':forms.HiddenInput(),
            'semifinishedgoods':forms.HiddenInput(),
            'product':forms.HiddenInput(),
            'company':forms.HiddenInput(), 
            'store_fr':forms.HiddenInput(),
            'store_to':forms.HiddenInput(),
            'qc':forms.HiddenInput(),
        }

    def __init__(self,* args,** kwargs):
        super(StkDetailsForm,self).__init__(* args,** kwargs)        
        self.fields['materials'].widget.attrs['class'] = "mat_id"
        self.fields['packaging'].widget.attrs['class'] = "pkg_id"  
        self.fields['semifinishedgoods'].widget.attrs['class']="sem_id"    
        self.fields['product'].widget.attrs['class']="fg_id" 
        self.fields['company'].widget.attrs['class'] = "company_id"
        self.fields['store_fr'].widget.attrs['class'] = "store_fr_id"
        self.fields['store_to'].widget.attrs['class'] = "store_to_id"
        self.fields['vtype'].widget.attrs['class']="vtype_id"
        self.fields['qty'].widget.attrs['class'] = "qty"
        self.fields['unit'].widget.attrs['class'] = "unit"

StkDetailsFormset=forms.models.inlineformset_factory(Batch, StkDetails, StkDetailsForm, extra=1, can_delete=True)  


class MaterialsForm(ModelForm):
    class Meta:
        model=Materials
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),
            'unit':forms.HiddenInput(),
        }


class BOMForm(ModelForm):
    class Meta:
        model=BOM
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),
            'product':forms.HiddenInput(),
        }


class BOMmaterialsForm(ModelForm):
    class Meta:
        model=BOMmaterials
        fields='__all__'
        widgets={
            #'bom': forms.HiddenInput(),
            'materials': forms.HiddenInput(),
            'unit': forms.HiddenInput(),            
        }
BOMmaterialsFormset=forms.models.inlineformset_factory(BOM, BOMmaterials,
        BOMmaterialsForm, extra=0, can_delete=True)    

class BOMpackagingForm(ModelForm):
    class Meta:
        model=BOMpackaging
        fields='__all__'
        widgets={
            'bom': forms.HiddenInput(),
            'packaging': forms.HiddenInput(),
            'unit': forms.HiddenInput(),            
        }
BOMpackagingFormset=forms.models.inlineformset_factory(BOM, BOMpackaging,
        BOMpackagingForm, extra=0, can_delete=True)   

class BOMsemifinishedgoodsForm(ModelForm):
    class Meta:
        model=BOMsemifinishedgoods
        fields='__all__'
        widgets={
            'bom': forms.HiddenInput(),
            'semifinishedgoods': forms.HiddenInput(),
            'unit': forms.HiddenInput(),            
        }
BOMsemifinishedgoodsFormset=forms.models.inlineformset_factory(BOM,
        BOMsemifinishedgoods, BOMsemifinishedgoodsForm, extra=0, can_delete=True)   


class OrderForm(ModelForm):
    class Meta:
        model=Order
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),
            'agent':forms.HiddenInput(),
            'user':forms.HiddenInput(),
        }
    def __init__(self,* args,** kwargs):
        super(OrderForm,self).__init__(* args,** kwargs)        
        self.fields['dt_delivery'].widget.attrs['class'] = "datepicker"

        
class OrderDetailsForm(ModelForm):
    class Meta:
        model=OrderDetails
        fields='__all__'
        widgets={
            'product':forms.HiddenInput(),
            #'unit':forms.HiddenInput(),
        }
    def __init__(self,* args,** kwargs):
        super(OrderDetailsForm,self).__init__(* args,** kwargs)        
        self.fields['product'].widget.attrs['class'] = "id_product"
OrderDetailsFormset=forms.models.inlineformset_factory(Order, OrderDetails,
        OrderDetailsForm, extra=1, can_delete=True)   




class VendorForm(ModelForm):
    class Meta:
        model=Vendor
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),            
        }

class VendorPhotosForm(ModelForm):
    class Meta:
        model=VendorPhotos
        fields='__all__'
        widgets={
            'vendor':forms.HiddenInput(),            
        }
  

 
class CustomerForm(ModelForm):
    class Meta:
        model=Customer
        fields='__all__'
        widgets={
            'company':forms.HiddenInput(),            
        }
           
