From 23db7a89a9ef6958169b6d3ba9833b8f640d2482 Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 19 Jul 2021 14:20:54 -0400 Subject: [PATCH] Updated PO upload template, moved call to button, improved cleaned_decimal method to handle comma separator --- InvenTree/InvenTree/helpers.py | 29 ++++-- .../order/order_wizard/po_upload.html | 92 ++++++++++++------- .../order/templates/order/po_navbar.html | 8 -- .../order/purchase_order_detail.html | 3 + InvenTree/order/views.py | 11 +-- 5 files changed, 85 insertions(+), 58 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 330bd2bb68..0b091efd02 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -631,13 +631,30 @@ def clean_decimal(number): """ Clean-up decimal value """ # Check if empty - if number is None or number == '': + if number is None or number == '' or number == 0: return Decimal(0) - # Check if decimal type - try: - clean_number = Decimal(number) - except InvalidOperation: - clean_number = number + # Convert to string and remove spaces + number = str(number).replace(' ', '') + + # Guess what type of decimal and thousands separators are used + count_comma = number.count(',') + count_point = number.count('.') + + if count_comma == 1: + # Comma is used as decimal separator + if count_point > 0: + # Points are used as thousands separators: remove them + number = number.replace('.', '') + # Replace decimal separator with point + number = number.replace(',', '.') + elif count_point == 1: + # Point is used as decimal separator + if count_comma > 0: + # Commas are used as thousands separators: remove them + number = number.replace(',', '') + + # Convert to Decimal type + clean_number = Decimal(number) return clean_number.quantize(Decimal(1)) if clean_number == clean_number.to_integral() else clean_number.normalize() diff --git a/InvenTree/order/templates/order/order_wizard/po_upload.html b/InvenTree/order/templates/order/order_wizard/po_upload.html index 4357bce2c6..7c2dea1af9 100644 --- a/InvenTree/order/templates/order/order_wizard/po_upload.html +++ b/InvenTree/order/templates/order/order_wizard/po_upload.html @@ -1,50 +1,74 @@ -{% extends "order/order_base.html" %} +{% extends "order/purchase_order_detail.html" %} {% load inventree_extras %} {% load i18n %} {% load static %} -{% block heading %} -{% trans "Upload File for Purchase Order" %} -{{ wizard.form.media }} +{% block menubar %} + {% endblock %} -{% block details %} -{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %} +{% block page_content %} -

{% blocktrans with step=wizard.steps.step1 count=wizard.steps.count %}Step {{step}} of {{count}}{% endblocktrans %} -{% if description %}- {{ description }}{% endif %}

+
+
+ {% block heading %} +

{% trans "Upload File for Purchase Order" %}

+ {{ wizard.form.media }} + {% endblock %} +
+
+ {% block details %} + {% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %} -{% block form_alert %} -{% endblock form_alert %} +

{% blocktrans with step=wizard.steps.step1 count=wizard.steps.count %}Step {{step}} of {{count}}{% endblocktrans %} + {% if description %}- {{ description }}{% endif %}

-
-{% csrf_token %} -{% load crispy_forms_tags %} + {% block form_alert %} + {% endblock form_alert %} -{% block form_buttons_top %} -{% endblock form_buttons_top %} + + {% csrf_token %} + {% load crispy_forms_tags %} - -{{ wizard.management_form }} -{% block form_content %} -{% crispy wizard.form %} -{% endblock form_content %} -
+ {% block form_buttons_top %} + {% endblock form_buttons_top %} -{% block form_buttons_bottom %} -{% if wizard.steps.prev %} - -{% endif %} - -
-{% endblock form_buttons_bottom %} + + {{ wizard.management_form }} + {% block form_content %} + {% crispy wizard.form %} + {% endblock form_content %} +
-{% else %} - -{% endif %} -{% endblock details %} + {% block form_buttons_bottom %} + {% if wizard.steps.prev %} + + {% endif %} + + + {% endblock form_buttons_bottom %} + + {% else %} + + {% endif %} + {% endblock details %} +
+ +{% endblock %} {% block js_ready %} {{ block.super }} diff --git a/InvenTree/order/templates/order/po_navbar.html b/InvenTree/order/templates/order/po_navbar.html index 9f7967810d..bddcce4ba3 100644 --- a/InvenTree/order/templates/order/po_navbar.html +++ b/InvenTree/order/templates/order/po_navbar.html @@ -15,14 +15,6 @@ {% trans "Order Items" %} - {% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %} -
  • - - - {% trans "Upload File" %} - -
  • - {% endif %}
  • diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 193fd75daa..b05bfa7cc2 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -22,6 +22,9 @@ + + {% trans "Upload File" %} + {% endif %}
  • diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index be1107f17b..a109b036e0 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -393,16 +393,7 @@ class PurchaseOrderUpload(FileManagementFormView): p_val = row['data'][p_idx]['cell'] if p_val: - # Delete commas - p_val = p_val.replace(',', '') - - try: - # Attempt to extract a valid decimal value from the field - purchase_price = Decimal(p_val) - # Store the 'purchase_price' value - row['purchase_price'] = purchase_price - except (ValueError, InvalidOperation): - pass + row['purchase_price'] = p_val # Check if there is a column corresponding to "reference" if r_idx >= 0: