2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-26 05:15:55 +00:00

added sale price history

This commit is contained in:
2021-06-27 21:32:27 +02:00
parent 4462b1e250
commit 5598f7fad1
3 changed files with 104 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ import common.settings as inventree_settings
from . import forms as part_forms
from .bom import MakeBomTemplate, BomUploadManager, ExportBom, IsValidBOMFormat
from order.models import PurchaseOrderLineItem
from .admin import PartResource
@@ -1038,6 +1039,36 @@ class PartPricingView(PartDetail):
# add to global context
ctx['bom_parts'] = ctx_bom_parts
# Sale price history
sale_items = PurchaseOrderLineItem.objects.filter(part__part=part).order_by('order__issue_date').\
prefetch_related('order', ).all()
if sale_items:
sale_history = []
for sale_item in sale_items:
# check for not fully defined elements
if None in [sale_item.purchase_price, sale_item.quantity]:
continue
price = convert_money(sale_item.purchase_price, default_currency)
line = {
'price': price.amount if price else 0,
'qty': sale_item.quantity,
}
# set date for graph labels
if sale_item.order.issue_date:
line['date'] = sale_item.order.issue_date.strftime('%d.%m.%Y')
elif sale_item.order.creation_date:
line['date'] = sale_item.order.creation_date.strftime('%d.%m.%Y')
else:
line['date'] = _('None')
sale_history.append(line)
ctx['sale_history'] = sale_history
return ctx
def get_initials(self):