Repository: inventree/InvenTree

Issue:
When ordering parts, show the pricing for each supplier
Next to each available supplier, display the price calculated based on the provided quantity.


Discussion:

Resolving patch:
diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py
--- a/InvenTree/InvenTree/views.py
+++ b/InvenTree/InvenTree/views.py
@@ -337,7 +337,7 @@ def validate(self, obj, form, **kwargs):
         # Do nothing by default
         pass
 
-    def renderJsonResponse(self, request, form=None, data={}, context=None):
+    def renderJsonResponse(self, request, form=None, data=None, context=None):
         """ Render a JSON response based on specific class context.
 
         Args:
@@ -349,6 +349,9 @@ def renderJsonResponse(self, request, form=None, data={}, context=None):
         Returns:
             JSON response object
         """
+        # a empty dict as default can be dangerous - set it here if empty
+        if not data:
+            data = {}
 
         if not request.is_ajax():
             return HttpResponseRedirect('/')
diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py
--- a/InvenTree/common/models.py
+++ b/InvenTree/common/models.py
@@ -205,6 +205,13 @@ class InvenTreeSetting(models.Model):
             'validator': bool,
         },
 
+        'PART_SHOW_PRICE_IN_FORMS': {
+            'name': _('Show Price in Forms'),
+            'description': _('Display part price in some forms'),
+            'default': True,
+            'validator': bool,
+        },
+
         'PART_INTERNAL_PRICE': {
             'name': _('Internal Prices'),
             'description': _('Enable internal prices for parts'),
diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py
--- a/InvenTree/order/views.py
+++ b/InvenTree/order/views.py
@@ -1004,6 +1004,15 @@ def get_context_data(self):
 
         return ctx
 
+    def get_data(self):
+        """ enrich respone json data """
+        data = super().get_data()
+        # if in selection-phase, add a button to update the prices
+        if getattr(self, 'form_step', 'select_parts') == 'select_parts':
+            data['buttons'] = [{'name': 'update_price', 'title': _('Update prices')}]  # set buttons
+            data['hideErrorMessage'] = '1'  # hide the error message
+        return data
+
     def get_suppliers(self):
         """ Calculates a list of suppliers which the user will need to create POs for.
         This is calculated AFTER the user finishes selecting the parts to order.
@@ -1238,9 +1247,10 @@ def post(self, request, *args, **kwargs):
         valid = False
 
         if form_step == 'select_parts':
-            # No errors? Proceed to PO selection form
-            if part_errors is False:
+            # No errors? and the price-update button was not used to submit? Proceed to PO selection form
+            if part_errors is False and 'act-btn_update_price' not in request.POST:
                 self.ajax_template_name = 'order/order_wizard/select_pos.html'
+                self.form_step = 'select_purchase_orders'  # set step (important for get_data)
 
             else:
                 self.ajax_template_name = 'order/order_wizard/select_parts.html'


Test patch: