mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Fixed form validation for previous step, hide tab depending on order status, added purchase_price field
This commit is contained in:
@ -48,7 +48,7 @@
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
{{ row.index }}
|
||||
{% add row.index 1 %}
|
||||
</td>
|
||||
<td>
|
||||
{% for field in form.visible_fields %}
|
||||
@ -71,6 +71,12 @@
|
||||
{% if row.errors.quantity %}
|
||||
<p class='help-inline'>{{ row.errors.quantity }}</p>
|
||||
{% endif %}
|
||||
{% elif item.column.guess == 'Purchase_Price' %}
|
||||
{% for field in form.visible_fields %}
|
||||
{% if field.name == row.price_select %}
|
||||
{{ field }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{{ item.cell }}
|
||||
{% endif %}
|
||||
|
@ -13,6 +13,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block details %}
|
||||
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
|
||||
|
||||
<p>{% blocktrans with step=wizard.steps.step1 count=wizard.steps.count %}Step {{step}} of {{count}}{% endblocktrans %}
|
||||
{% if description %}- {{ description }}{% endif %}</p>
|
||||
@ -42,6 +43,11 @@
|
||||
</form>
|
||||
{% endblock form_buttons_bottom %}
|
||||
|
||||
{% else %}
|
||||
<div class='alert alert-danger alert-block' role='alert'>
|
||||
{% trans "Order is already processed. Files cannot be uploaded." %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock details %}
|
||||
|
||||
{% block js_ready %}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load inventree_extras %}
|
||||
{% load status_codes %}
|
||||
|
||||
<ul class='list-group'>
|
||||
<li class='list-group-item'>
|
||||
@ -14,12 +15,14 @@
|
||||
{% trans "Details" %}
|
||||
</a>
|
||||
</li>
|
||||
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
|
||||
<li class='list-group-item {% if tab == "upload" %}active{% endif %}' title='{% trans "Upload File" %}'>
|
||||
<a href='{% url "po-upload" order.id %}'>
|
||||
<span class='fas fa-file-upload'></span>
|
||||
{% trans "Upload File" %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class='list-group-item {% if tab == "received" %}active{% endif %}' title='{% trans "Received Stock Items" %}'>
|
||||
<a href='{% url "po-received" order.id %}'>
|
||||
<span class='fas fa-sign-in-alt'></span>
|
||||
|
@ -583,6 +583,7 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
_("Match Fields"),
|
||||
_("Match Supplier Parts"),
|
||||
]
|
||||
key_price_select = 'purchase_price'
|
||||
|
||||
def get_order(self):
|
||||
""" Get order or return 404 """
|
||||
@ -612,8 +613,9 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
q_idx = self.get_column_index('Quantity')
|
||||
s_idx = self.get_column_index('Supplier_SKU')
|
||||
m_idx = self.get_column_index('Manufacturer_MPN')
|
||||
# p_idx = self.get_column_index('Unit_Price')
|
||||
# e_idx = self.get_column_index('Extended_Price')
|
||||
p_idx = self.get_column_index('Purchase_Price')
|
||||
r_idx = self.get_column_index('Reference')
|
||||
n_idx = self.get_column_index('Notes')
|
||||
|
||||
for row in self.rows:
|
||||
|
||||
@ -634,12 +636,11 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
try:
|
||||
# Attempt to extract a valid quantity from the field
|
||||
quantity = Decimal(q_val)
|
||||
# Store the 'quantity' value
|
||||
row['quantity'] = quantity
|
||||
except (ValueError, InvalidOperation):
|
||||
pass
|
||||
|
||||
# Store the 'quantity' value
|
||||
row['quantity'] = quantity
|
||||
|
||||
# Check if there is a column corresponding to "Supplier SKU"
|
||||
if s_idx >= 0:
|
||||
sku = row['data'][s_idx]['cell']
|
||||
@ -670,8 +671,32 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
# If there is an exact match based on SKU or MPN, use that
|
||||
row['item_match'] = exact_match_part
|
||||
|
||||
# Check if there is a column corresponding to "purchase_price"
|
||||
if p_idx >= 0:
|
||||
p_val = row['data'][p_idx]['cell']
|
||||
|
||||
if p_val:
|
||||
# Delete commas
|
||||
p_val = p_val.replace(',', '')
|
||||
|
||||
try:
|
||||
# Attempt to extract a valid quantity from the field
|
||||
purchase_price = Decimal(p_val)
|
||||
# Store the 'purchase_price' value
|
||||
row['purchase_price'] = purchase_price
|
||||
except (ValueError, InvalidOperation):
|
||||
pass
|
||||
|
||||
# Check if there is a column corresponding to "reference"
|
||||
if r_idx >= 0:
|
||||
pass
|
||||
|
||||
# Check if there is a column corresponding to "notes"
|
||||
if n_idx >= 0:
|
||||
pass
|
||||
|
||||
def done(self, form_list, **kwargs):
|
||||
""" Once all the data is in, process it to add SupplierPart items to the order """
|
||||
""" Once all the data is in, process it to add PurchaseOrderLineItem instances to the order """
|
||||
|
||||
order = self.get_order()
|
||||
|
||||
@ -708,6 +733,18 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
# Update items
|
||||
items[idx]['quantity'] = form_value
|
||||
|
||||
if field == self.key_price_select:
|
||||
if idx not in items:
|
||||
# Insert into items
|
||||
items.update({
|
||||
idx: {
|
||||
'purchase_price': form_value,
|
||||
}
|
||||
})
|
||||
else:
|
||||
# Update items
|
||||
items[idx]['purchase_price'] = form_value
|
||||
|
||||
# Create PurchaseOrderLineItem instances
|
||||
for purchase_order_item in items.values():
|
||||
try:
|
||||
@ -718,6 +755,7 @@ class PurchaseOrderUpload(FileManagementFormView):
|
||||
order=order,
|
||||
part=supplier_part,
|
||||
quantity=purchase_order_item['quantity'],
|
||||
purchase_price=purchase_order_item['purchase_price'],
|
||||
)
|
||||
try:
|
||||
purchase_order_line_item.save()
|
||||
|
Reference in New Issue
Block a user