Skip to content

Commit

Permalink
Change staus messages to javascript sof add supplierpatd
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Jun 30, 2024
1 parent 176e3a2 commit f0b5503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
16 changes: 8 additions & 8 deletions inventree_supplier_panel/supplier_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,23 @@ def add_supplierpart(self, request):
part = Part.objects.filter(id=data['pk'])[0]
supplier = Company.objects.filter(id=data['supplier'])[0]
if (data['sku'] == ''):
self.status_code = 'Please provide part number'
return HttpResponse('OK')
# self.status_code = 'Please provide part number'
return HttpResponse('Please provide part number')

manufacturer_part = ManufacturerPart.objects.filter(part=data['pk'])
if len(manufacturer_part) == 0:
self.status_code = 'Part has no manufacturer part'
return HttpResponse('OK')
# self.status_code = 'Part has no manufacturer part'
return HttpResponse('Part has no manufacturer part')

supplier_parts = SupplierPart.objects.filter(part=data['pk'])
for sp in supplier_parts:
if sp.SKU.strip() == data['sku'].strip():
self.status_code = 'Supplierpart with this SKU already exists'
return HttpResponse('OK')
# self.status_code = 'Supplierpart with this SKU already exists'
return HttpResponse('Supplierpart with this SKU already exists')

part_data = self.get_partdata(data['supplier'], data['sku'])
if (self.status_code != 200):
return HttpResponse('OK')
return HttpResponse(self.message)
if self.debug:
print(part_data['price_breaks'])
sp = SupplierPart.objects.create(part=part,
Expand All @@ -299,7 +299,7 @@ def add_supplierpart(self, request):
)
for pb in part_data['price_breaks']:
SupplierPriceBreak.objects.create(part=sp, quantity=pb['Quantity'], price=pb['Price'], price_currency=pb['Currency'])
return HttpResponse('OK')
return HttpResponse('Part created')

# ---------------------------- Define the suppliers ----------------------------
debug = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@
supplier: supplier,
pk: pk,
}
document.getElementById("state").className='alert alert-block alert-info'
document.getElementById("state").textContent="Asking Supplier..."
response = await inventreeFormDataUpload(url=cmd_url, data=JSON.stringify(data))
location.reload();
document.getElementById("state").textContent=response
if (response == "Part created") {
location.reload()
document.getElementById("state").className='alert alert-block alert-info'
document.getElementById("state").textContent=response
} else {
document.getElementById("state").className='alert alert-block alert-danger'
}
// location.reload()
}
</script>

<!--
{% if plugin.status_code == 200 %}
<div class='alert alert-block alert-info'>
{{ plugin.status_code }} {{ plugin.message }}
Expand All @@ -25,6 +36,8 @@
{{ plugin.status_code }} {{ plugin.message }}
</div>
{% endif %}
-->
<p id="state" class='alert alert-block alert-info'>Ready</p>

<table class='table table-condensed'>
<form>
Expand Down

0 comments on commit f0b5503

Please sign in to comment.