2019-06-05 10:59:30 +00:00
|
|
|
"""
|
|
|
|
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
|
2019-09-20 01:52:38 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2019-06-10 12:14:23 +00:00
|
|
|
|
2019-09-23 09:02:36 +00:00
|
|
|
from mptt.fields import TreeNodeChoiceField
|
|
|
|
|
2019-06-05 10:59:30 +00:00
|
|
|
from InvenTree.forms import HelperForm
|
2020-03-31 10:23:57 +00:00
|
|
|
from InvenTree.fields import RoundingDecimalFormField
|
2021-01-02 10:54:07 +00:00
|
|
|
from InvenTree.fields import DatePickerFormField
|
2019-06-05 10:59:30 +00:00
|
|
|
|
2019-09-23 09:02:36 +00:00
|
|
|
from stock.models import StockLocation
|
2020-03-22 07:41:41 +00:00
|
|
|
from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment
|
2020-04-20 23:42:11 +00:00
|
|
|
from .models import SalesOrder, SalesOrderLineItem, SalesOrderAttachment
|
2020-04-22 11:26:38 +00:00
|
|
|
from .models import SalesOrderAllocation
|
2019-06-05 12:24:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-05 12:24:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrder
|
|
|
|
fields = [
|
2019-06-10 12:14:23 +00:00
|
|
|
'confirm',
|
2019-06-05 12:24:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-12-04 23:29:16 +00:00
|
|
|
class CompletePurchaseOrderForm(HelperForm):
|
|
|
|
|
2020-10-30 10:34:56 +00:00
|
|
|
confirm = forms.BooleanField(required=True, help_text=_("Mark order as complete"))
|
2019-12-04 23:29:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrder
|
|
|
|
fields = [
|
|
|
|
'confirm',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-20 01:52:38 +00:00
|
|
|
class CancelPurchaseOrderForm(HelperForm):
|
|
|
|
|
2020-10-30 10:34:56 +00:00
|
|
|
confirm = forms.BooleanField(required=True, help_text=_('Cancel order'))
|
2019-09-20 01:52:38 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrder
|
|
|
|
fields = [
|
|
|
|
'confirm',
|
|
|
|
]
|
2020-04-23 11:38:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CancelSalesOrderForm(HelperForm):
|
|
|
|
|
2020-10-30 10:34:56 +00:00
|
|
|
confirm = forms.BooleanField(required=True, help_text=_('Cancel order'))
|
2020-04-23 11:38:40 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SalesOrder
|
|
|
|
fields = [
|
|
|
|
'confirm',
|
|
|
|
]
|
2019-09-20 01:52:38 +00:00
|
|
|
|
|
|
|
|
2020-04-24 00:20:56 +00:00
|
|
|
class ShipSalesOrderForm(HelperForm):
|
|
|
|
|
2020-10-30 10:34:56 +00:00
|
|
|
confirm = forms.BooleanField(required=True, help_text=_('Ship order'))
|
2020-04-24 00:20:56 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SalesOrder
|
|
|
|
fields = [
|
|
|
|
'confirm',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-23 09:02:36 +00:00
|
|
|
class ReceivePurchaseOrderForm(HelperForm):
|
|
|
|
|
|
|
|
location = TreeNodeChoiceField(queryset=StockLocation.objects.all(), required=True, help_text=_('Receive parts to this location'))
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrder
|
|
|
|
fields = [
|
|
|
|
'location',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-05 12:24:18 +00:00
|
|
|
class EditPurchaseOrderForm(HelperForm):
|
|
|
|
""" Form for editing a PurchaseOrder object """
|
|
|
|
|
2020-05-14 11:51:44 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
2020-05-16 01:05:45 +00:00
|
|
|
self.field_prefix = {
|
2020-05-15 23:36:43 +00:00
|
|
|
'reference': 'PO',
|
|
|
|
'link': 'fa-link',
|
2021-01-14 06:44:21 +00:00
|
|
|
'target_date': 'fa-calendar-alt',
|
2020-05-15 23:36:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 01:05:45 +00:00
|
|
|
self.field_placeholder = {
|
2020-10-19 11:49:28 +00:00
|
|
|
'reference': _('Purchase Order reference'),
|
2020-05-15 23:36:43 +00:00
|
|
|
}
|
2020-05-14 11:51:44 +00:00
|
|
|
|
2020-05-15 23:36:43 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2020-05-14 11:51:44 +00:00
|
|
|
|
2021-01-14 06:44:21 +00:00
|
|
|
target_date = DatePickerFormField(
|
|
|
|
help_text=_('Target date for order delivery. Order will be overdue after this date.'),
|
|
|
|
)
|
|
|
|
|
2019-06-05 12:24:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrder
|
|
|
|
fields = [
|
|
|
|
'reference',
|
|
|
|
'supplier',
|
2020-04-15 04:24:59 +00:00
|
|
|
'supplier_reference',
|
2019-06-05 12:24:18 +00:00
|
|
|
'description',
|
2021-01-14 06:44:21 +00:00
|
|
|
'target_date',
|
2020-04-06 01:56:52 +00:00
|
|
|
'link',
|
2021-03-10 05:26:20 +00:00
|
|
|
'responsible',
|
2019-06-05 12:24:18 +00:00
|
|
|
]
|
2019-06-05 10:59:30 +00:00
|
|
|
|
|
|
|
|
2020-04-20 12:13:07 +00:00
|
|
|
class EditSalesOrderForm(HelperForm):
|
|
|
|
""" Form for editing a SalesOrder object """
|
|
|
|
|
2020-05-14 11:51:44 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
2020-05-16 01:05:45 +00:00
|
|
|
self.field_prefix = {
|
2020-05-15 23:36:43 +00:00
|
|
|
'reference': 'SO',
|
|
|
|
'link': 'fa-link',
|
2021-01-02 10:54:07 +00:00
|
|
|
'target_date': 'fa-calendar-alt',
|
2020-05-15 23:36:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 01:05:45 +00:00
|
|
|
self.field_placeholder = {
|
2020-05-15 23:36:43 +00:00
|
|
|
'reference': _('Enter sales order number'),
|
|
|
|
}
|
2020-05-14 11:51:44 +00:00
|
|
|
|
2020-05-15 23:36:43 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2020-05-14 11:51:44 +00:00
|
|
|
|
2021-01-02 10:54:07 +00:00
|
|
|
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',
|
2021-03-10 05:26:20 +00:00
|
|
|
'link',
|
|
|
|
'responsible',
|
2020-04-20 12:13:07 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-03-22 07:41:41 +00:00
|
|
|
class EditPurchaseOrderAttachmentForm(HelperForm):
|
|
|
|
""" Form for editing a PurchaseOrderAttachment object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrderAttachment
|
|
|
|
fields = [
|
|
|
|
'order',
|
|
|
|
'attachment',
|
|
|
|
'comment'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-04-20 23:42:11 +00:00
|
|
|
class EditSalesOrderAttachmentForm(HelperForm):
|
|
|
|
""" Form for editing a SalesOrderAttachment object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SalesOrderAttachment
|
|
|
|
fields = [
|
|
|
|
'order',
|
|
|
|
'attachment',
|
|
|
|
'comment'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-05 10:59:30 +00:00
|
|
|
class EditPurchaseOrderLineItemForm(HelperForm):
|
2019-06-05 12:24:18 +00:00
|
|
|
""" Form for editing a PurchaseOrderLineItem object """
|
2019-06-05 10:59:30 +00:00
|
|
|
|
2020-03-31 10:23:57 +00:00
|
|
|
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
|
|
|
|
|
2019-06-05 10:59:30 +00:00
|
|
|
class Meta:
|
|
|
|
model = PurchaseOrderLineItem
|
|
|
|
fields = [
|
|
|
|
'order',
|
|
|
|
'part',
|
|
|
|
'quantity',
|
|
|
|
'reference',
|
2020-11-12 07:05:24 +00:00
|
|
|
'purchase_price',
|
2019-06-13 11:57:35 +00:00
|
|
|
'notes',
|
2019-06-05 11:56:52 +00:00
|
|
|
]
|
2020-04-20 23:02:10 +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'
|
|
|
|
]
|
2020-04-22 11:26:38 +00:00
|
|
|
|
|
|
|
|
2021-03-29 05:43:26 +00:00
|
|
|
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',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-04-22 11:26:38 +00:00
|
|
|
class EditSalesOrderAllocationForm(HelperForm):
|
2021-03-29 05:43:26 +00:00
|
|
|
"""
|
|
|
|
Form for editing a SalesOrderAllocation item
|
|
|
|
"""
|
2020-04-22 11:26:38 +00:00
|
|
|
|
|
|
|
quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SalesOrderAllocation
|
|
|
|
|
|
|
|
fields = [
|
|
|
|
'line',
|
|
|
|
'item',
|
|
|
|
'quantity']
|