initial showcase implementation

This commit is contained in:
Matthias 2021-04-06 18:17:09 +02:00
parent 53c9475e6d
commit f647120cd1
6 changed files with 113 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -326,7 +326,7 @@ class PurchaseOrder(Order):
return self.pending_line_items().count() == 0
@transaction.atomic
def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK):
def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK, purchase_price=None):
""" Receive a line item (or partial line item) against this PO
"""
@ -348,7 +348,8 @@ class PurchaseOrder(Order):
location=location,
quantity=quantity,
purchase_order=self,
status=status
status=status,
purchase_price=purchase_price,
)
stock.save()

View File

@ -776,6 +776,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
line.receive_quantity,
self.request.user,
status=line.status_code,
purchase_price=line.purchase_price,
)

View File

@ -1,5 +1,6 @@
{% extends "modal_form.html" %}
{% load i18n %}
{% block pre_form_content %}
<div class='alert alert-info alert-block'>
@ -77,6 +78,76 @@ Pricing information for:<br>
</table>
{% endif %}
{% if price_history %}
<h4>{% trans 'Stock Pricing' %}</h4>
{% if price_history|length > 1 %}
<canvas id="priceChart"></canvas>
<script>
var pricedata = {
labels: [
{% for line in price_history %}'{{ line.date }}',{% endfor %}
],
datasets: [{
label: 'Price',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgb(255, 99, 132)',
yAxisID: 'y',
data: [
{% for line in price_history %}{{ line.price|stringformat:".2f" }},{% endfor %}
],
borderWidth: 1,
type: 'line'
},
{
label: 'Qty',
backgroundColor: 'rgba(255, 206, 86, 0.2)',
borderColor: 'rgb(255, 206, 86)',
yAxisID: 'y1',
data: [
{% for line in price_history %}{{ line.qty|stringformat:"f" }},{% endfor %}
],
borderWidth: 1
}]
}
var ctx = document.getElementById('priceChart');
var priceChart = new Chart(ctx, {
type: 'bar',
data: pricedata,
options: {
responsive: true,
plugins: {legend: {position: 'bottom'}},
scales: {
y: {
type: 'linear',
position: 'left',
grid: {display: false},
title: {
display: true,
text: 'Price - USD'
}
},
y1: {
type: 'linear',
position: 'right',
grid: {display: false},
titel: {
display: true,
text: 'Qty',
position: 'right'
}
}
}
}
});
</script>
{% else %}
<div class='alert alert-danger alert-block'>
{% trans 'No stock pricing history is available for this part.' %}
</div>
{% endif %}
{% endif %}
{% if min_unit_buy_price or min_unit_bom_price %}
{% else %}
<div class='alert alert-danger alert-block'>

View File

@ -2027,6 +2027,30 @@ class PartPricing(AjaxView):
ctx['max_total_bom_price'] = max_bom_price
ctx['max_unit_bom_price'] = max_bom_price / quantity
# Stock history
if part.total_stock > 1:
ret = []
stock = part.stock_entries(include_variants=False, in_stock=True)
for stock_item in stock:
if None in [stock_item.purchase_price, stock_item.quantity]:
continue
line = {
'price': stock_item.purchase_price.amount,
'qty': stock_item.quantity
}
if stock_item.supplier_part:
line['name'] = stock_item.supplier_part.pretty_name
if stock_item.supplier_part.unit_pricing and stock_item.purchase_price:
line['price_diff'] = stock_item.supplier_part.unit_pricing - stock_item.purchase_price.amount
if stock_item.purchase_order:
line['date'] = stock_item.purchase_order.issue_date.strftime('%d.%m.%Y')
ret.append(line)
ctx['price_history'] = ret
return ctx
def get(self, request, *args, **kwargs):

View File

@ -136,6 +136,7 @@ InvenTree
<script type="text/javascript" src="{% static 'fullcalendar/main.js' %}"></script>
<script type="text/javascript" src="{% static 'script/select2/select2.js' %}"></script>
<script type='text/javascript' src="{% static 'script/moment.js' %}"></script>
<script type='text/javascript' src="{% static 'script/chart.min.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/inventree.js' %}"></script>
<script type='text/javascript' src="{% static 'script/inventree/api.js' %}"></script>