From 007d2d4054e3519cac392d7f5f2cd1bdc5799130 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 May 2020 21:51:44 +1000 Subject: [PATCH] Add prepended text to order references for forms --- InvenTree/InvenTree/forms.py | 12 ++++++++++++ InvenTree/order/forms.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py index f0dd5f3d43..c794f7ca25 100644 --- a/InvenTree/InvenTree/forms.py +++ b/InvenTree/InvenTree/forms.py @@ -7,6 +7,8 @@ from __future__ import unicode_literals from django import forms 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 @@ -19,6 +21,16 @@ class HelperForm(forms.ModelForm): 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): """ Generic deletion form which provides simple user confirmation diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 9991fe6670..e7e26064f8 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -8,6 +8,9 @@ from __future__ import unicode_literals from django import forms 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 InvenTree.forms import HelperForm @@ -88,6 +91,23 @@ class ReceivePurchaseOrderForm(HelperForm): class EditPurchaseOrderForm(HelperForm): """ 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: model = PurchaseOrder fields = [ @@ -102,6 +122,23 @@ class EditPurchaseOrderForm(HelperForm): class EditSalesOrderForm(HelperForm): """ 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: model = SalesOrder fields = [