Add prepended text to order references for forms

This commit is contained in:
Oliver Walters 2020-05-14 21:51:44 +10:00
parent 16aa18429a
commit 007d2d4054
2 changed files with 49 additions and 0 deletions

View File

@ -7,6 +7,8 @@ from __future__ import unicode_literals
from django import forms from django import forms
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Field, Layout
from crispy_forms.bootstrap import PrependedText
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -19,6 +21,16 @@ class HelperForm(forms.ModelForm):
self.helper.form_tag = False self.helper.form_tag = False
"""
Create a default 'layout' for this form.
Ref: https://django-crispy-forms.readthedocs.io/en/latest/layouts.html
This is required to do fancy things later (like adding PrependedText, etc).
Simply create a 'blank' layout for each available field.
"""
self.helper.layout = Layout(*self.fields.keys())
class DeleteForm(forms.Form): class DeleteForm(forms.Form):
""" Generic deletion form which provides simple user confirmation """ Generic deletion form which provides simple user confirmation

View File

@ -8,6 +8,9 @@ from __future__ import unicode_literals
from django import forms from django import forms
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from crispy_forms.layout import Field, Layout
from crispy_forms.bootstrap import PrependedText
from mptt.fields import TreeNodeChoiceField from mptt.fields import TreeNodeChoiceField
from InvenTree.forms import HelperForm from InvenTree.forms import HelperForm
@ -88,6 +91,23 @@ class ReceivePurchaseOrderForm(HelperForm):
class EditPurchaseOrderForm(HelperForm): class EditPurchaseOrderForm(HelperForm):
""" Form for editing a PurchaseOrder object """ """ Form for editing a PurchaseOrder object """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# TODO - Refactor this?
self.helper.layout = Layout(
Field(PrependedText(
'reference',
'PO',
placeholder=_("Purchase Order")
)),
Field('supplier'),
Field('supplier_reference'),
Field('description'),
Field('link'),
)
class Meta: class Meta:
model = PurchaseOrder model = PurchaseOrder
fields = [ fields = [
@ -102,6 +122,23 @@ class EditPurchaseOrderForm(HelperForm):
class EditSalesOrderForm(HelperForm): class EditSalesOrderForm(HelperForm):
""" Form for editing a SalesOrder object """ """ Form for editing a SalesOrder object """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# TODO - Refactor?
self.helper.layout = Layout(
Field(PrependedText(
'reference',
'SO',
placeholder=_("Sales Order")
)),
Field('customer'),
Field('customer_reference'),
Field('description'),
Field('link'),
)
class Meta: class Meta:
model = SalesOrder model = SalesOrder
fields = [ fields = [