InvenTree/InvenTree/order/forms.py

254 lines
5.8 KiB
Python
Raw Normal View History

"""
Django Forms for interacting with Order objects
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2019-06-10 12:14:23 +00:00
from django import forms
from django.utils.translation import ugettext as _
2019-06-10 12:14:23 +00:00
from mptt.fields import TreeNodeChoiceField
from InvenTree.forms import HelperForm
from InvenTree.fields import RoundingDecimalFormField
from InvenTree.fields import DatePickerFormField
from stock.models import StockLocation
from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment
from .models import SalesOrder, SalesOrderLineItem, SalesOrderAttachment
from .models import SalesOrderAllocation
class IssuePurchaseOrderForm(HelperForm):
2020-10-30 10:34:56 +00:00
confirm = forms.BooleanField(required=True, initial=False, help_text=_('Place order'))
2019-06-10 12:14:23 +00:00
class Meta:
model = PurchaseOrder
fields = [
2019-06-10 12:14:23 +00:00
'confirm',
]
class CompletePurchaseOrderForm(HelperForm):
2020-10-30 10:34:56 +00:00
confirm = forms.BooleanField(required=True, help_text=_("Mark order as complete"))
class Meta:
model = PurchaseOrder
fields = [
'confirm',
]
class CancelPurchaseOrderForm(HelperForm):
2020-10-30 10:34:56 +00:00
confirm = forms.BooleanField(required=True, help_text=_('Cancel order'))
class Meta:
model = PurchaseOrder
fields = [
'confirm',
]
class CancelSalesOrderForm(HelperForm):
2020-10-30 10:34:56 +00:00
confirm = forms.BooleanField(required=True, help_text=_('Cancel order'))
class Meta:
model = SalesOrder
fields = [
'confirm',
]
class ShipSalesOrderForm(HelperForm):
2020-10-30 10:34:56 +00:00
confirm = forms.BooleanField(required=True, help_text=_('Ship order'))
class Meta:
model = SalesOrder
fields = [
'confirm',
]
class ReceivePurchaseOrderForm(HelperForm):
location = TreeNodeChoiceField(queryset=StockLocation.objects.all(), required=True, help_text=_('Receive parts to this location'))
class Meta:
model = PurchaseOrder
fields = [
'location',
]
class EditPurchaseOrderForm(HelperForm):
""" Form for editing a PurchaseOrder object """
def __init__(self, *args, **kwargs):
self.field_prefix = {
'reference': 'PO',
'link': 'fa-link',
'target_date': 'fa-calendar-alt',
}
self.field_placeholder = {
2020-10-19 11:49:28 +00:00
'reference': _('Purchase Order reference'),
}
super().__init__(*args, **kwargs)
target_date = DatePickerFormField(
help_text=_('Target date for order delivery. Order will be overdue after this date.'),
)
class Meta:
model = PurchaseOrder
fields = [
'reference',
'supplier',
2020-04-15 04:24:59 +00:00
'supplier_reference',
'description',
'target_date',
2020-04-06 01:56:52 +00:00
'link',
'responsible',
]
2020-04-20 12:13:07 +00:00
class EditSalesOrderForm(HelperForm):
""" Form for editing a SalesOrder object """
def __init__(self, *args, **kwargs):
self.field_prefix = {
'reference': 'SO',
'link': 'fa-link',
'target_date': 'fa-calendar-alt',
}
self.field_placeholder = {
'reference': _('Enter sales order number'),
}
super().__init__(*args, **kwargs)
target_date = DatePickerFormField(
help_text=_('Target date for order completion. Order will be overdue after this date.'),
2020-12-18 01:40:47 +00:00
)
2020-04-20 12:13:07 +00:00
class Meta:
model = SalesOrder
fields = [
'reference',
'customer',
'customer_reference',
'description',
2020-12-18 01:40:47 +00:00
'target_date',
'link',
'responsible',
2020-04-20 12:13:07 +00:00
]
class EditPurchaseOrderAttachmentForm(HelperForm):
""" Form for editing a PurchaseOrderAttachment object """
class Meta:
model = PurchaseOrderAttachment
fields = [
'order',
'attachment',
'comment'
]
class EditSalesOrderAttachmentForm(HelperForm):
""" Form for editing a SalesOrderAttachment object """
class Meta:
model = SalesOrderAttachment
fields = [
'order',
'attachment',
'comment'
]
class EditPurchaseOrderLineItemForm(HelperForm):
""" Form for editing a PurchaseOrderLineItem object """
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
class Meta:
model = PurchaseOrderLineItem
fields = [
'order',
'part',
'quantity',
'reference',
'purchase_price',
'notes',
2019-06-05 11:56:52 +00:00
]
class EditSalesOrderLineItemForm(HelperForm):
""" Form for editing a SalesOrderLineItem object """
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
class Meta:
model = SalesOrderLineItem
fields = [
'order',
'part',
'quantity',
'reference',
'notes'
]
class CreateSalesOrderAllocationForm(HelperForm):
"""
Form for creating a SalesOrderAllocation item.
This can be allocated by selecting a specific stock item,
or by providing a sequence of serial numbers
"""
quantity = RoundingDecimalFormField(max_digits = 10, decimal_places=5)
serials = forms.CharField(
label=_("Serial Numbers"),
required=False,
help_text=_('Enter stock serial numbers'),
)
class Meta:
model = SalesOrderAllocation
fields = [
'line',
'item',
'quantity',
]
class EditSalesOrderAllocationForm(HelperForm):
"""
Form for editing a SalesOrderAllocation item
"""
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
class Meta:
model = SalesOrderAllocation
fields = [
'line',
'item',
'quantity']