import logging
from django import forms

from core.models import Order, OrderLine, ShippingMethod

logger = logging.getLogger(__name__)

class OrderLineFulfillForm(forms.ModelForm):
    # send_shipment_details_to_customer = forms.BooleanField(initial=True)

    class Meta:
        model = OrderLine
        fields = ('quantity_fulfilled',)
        widgets = {
            'quantity_fulfilled': forms.NumberInput(attrs = {
                'min': 0,
            })
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['quantity_fulfilled'].widget.attrs['max'] = self.instance.quantity

OrderLineFormset = forms.inlineformset_factory(
    Order, OrderLine, form=OrderLineFulfillForm,
    extra=0, can_delete=False
)
