From cb0ef30effafd7bf9319ae3bae3f1af2e2163b2e Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 18 May 2021 10:17:19 +0200 Subject: [PATCH] form overrides --- InvenTree/common/views.py | 21 +++++++++++++++++++-- InvenTree/order/views.py | 11 ++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/InvenTree/common/views.py b/InvenTree/common/views.py index 72a8d7fb1a..b645d16651 100644 --- a/InvenTree/common/views.py +++ b/InvenTree/common/views.py @@ -191,10 +191,27 @@ class FileManagementFormView(MultiStepFormView): def __init__(self, *args, **kwargs): """ initialize the FormView """ - # perform all checks and inits from MultiStepFormView + # check if form_list should be overriden + if hasattr(self, 'form_list_override'): + # check for list + if not isinstance(self.form_list_override, list): + raise ValueError('form_list_override must be a list') + + # loop through and override /add form_list enrties + for entry in self.form_list_override: + # fetch postition + pos = [self.form_list.index(i) for i in self.form_list if i[0] == 'items'] + # replace if exists + if pos: + self.form_list[pos[0]] = entry + # or append + else: + self.form_list.append(entry) + + # perform all checks and inits for MultiStepFormView super().__init__(*args, **kwargs) - # Check + # Check for file manager class if not(hasattr(self, 'file_manager_class') and issubclass(self.file_manager_class, FileManager)): raise NotImplementedError('A subclass of a file manager class needs to be set!') diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index bbda2f1716..2cb7263269 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -32,6 +32,7 @@ from part.models import Part from common.models import InvenTreeSetting from common.views import FileManagementFormView from common.files import FileManager +from common import forms as cm_forms from . import forms as order_forms from part.views import PartPricing @@ -573,7 +574,16 @@ class SalesOrderShip(AjaxUpdateView): class PurchaseOrderUpload(FileManagementFormView): ''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) ''' + class MyMatch(cm_forms.MatchItem): + """ override MatchItem fields """ + def get_special_field(self, col_guess, row, file_manager): + """ set special field """ + # run default + super().get_special_field(col_guess, row, file_manager) name = 'order' + form_list_override = [ + ('items', MyMatch), + ] form_steps_template = [ 'order/order_wizard/po_upload.html', 'order/order_wizard/match_fields.html', @@ -584,7 +594,6 @@ class PurchaseOrderUpload(FileManagementFormView): _("Match Fields"), _("Match Supplier Parts"), ] - # Form field name: PurchaseOrderLineItem field form_field_map = { 'item_select': 'part', 'quantity': 'quantity',