2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-28 14:25:56 +00:00

Add integration of django-money

- Proper currency support
- Add PurchasePrice field to StockItem model
- This keeps track of both the price and the currency
- Display purchase price on the stockitem detail page
This commit is contained in:
Oliver Walters
2020-11-10 16:22:42 +11:00
parent 9d9ef5fc9c
commit 734436b02e
6 changed files with 47 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ from markdownx.models import MarkdownxField
from mptt.models import MPTTModel, TreeForeignKey
from djmoney.models.fields import MoneyField
from decimal import Decimal, InvalidOperation
from datetime import datetime
from InvenTree import helpers
@@ -135,6 +137,7 @@ class StockItem(MPTTModel):
infinite: If True this StockItem can never be exhausted
sales_order: Link to a SalesOrder object (if the StockItem has been assigned to a SalesOrder)
build_order: Link to a BuildOrder object (if the StockItem has been assigned to a BuildOrder)
purchase_price: The unit purchase price for this StockItem - this is the unit price at time of purchase (if this item was purchased from an external supplier)
"""
# A Query filter which will be re-used in multiple places to determine if a StockItem is actually "in stock"
@@ -456,6 +459,15 @@ class StockItem(MPTTModel):
help_text=_('Stock Item Notes')
)
purchase_price = MoneyField(
max_digits=19,
decimal_places=4,
default_currency='USD',
null=True,
verbose_name=_('Purchase Price'),
help_text=_('Single unit purchase price at time of purchase'),
)
def clearAllocations(self):
"""
Clear all order allocations for this StockItem: