mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
calculate purchase price for part
This commit is contained in:
parent
1da004d30a
commit
a2ffd06abf
@ -35,6 +35,8 @@ from stdimage.models import StdImageField
|
|||||||
from decimal import Decimal, InvalidOperation
|
from decimal import Decimal, InvalidOperation
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
from djmoney.contrib.exchange.models import convert_money
|
||||||
|
from common.settings import currency_code_default
|
||||||
|
|
||||||
from InvenTree import helpers
|
from InvenTree import helpers
|
||||||
from InvenTree import validators
|
from InvenTree import validators
|
||||||
@ -1514,7 +1516,7 @@ class Part(MPTTModel):
|
|||||||
|
|
||||||
return (min_price, max_price)
|
return (min_price, max_price)
|
||||||
|
|
||||||
def get_bom_price_range(self, quantity=1, internal=False):
|
def get_bom_price_range(self, quantity=1, internal=False, purchase=False):
|
||||||
""" Return the price range of the BOM for this part.
|
""" Return the price range of the BOM for this part.
|
||||||
Adds the minimum price for all components in the BOM.
|
Adds the minimum price for all components in the BOM.
|
||||||
|
|
||||||
@ -1531,7 +1533,7 @@ class Part(MPTTModel):
|
|||||||
print("Warning: Item contains itself in BOM")
|
print("Warning: Item contains itself in BOM")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
prices = item.sub_part.get_price_range(quantity * item.quantity, internal=internal)
|
prices = item.sub_part.get_price_range(quantity * item.quantity, internal=internal, purchase=purchase)
|
||||||
|
|
||||||
if prices is None:
|
if prices is None:
|
||||||
continue
|
continue
|
||||||
@ -1555,16 +1557,17 @@ class Part(MPTTModel):
|
|||||||
|
|
||||||
return (min_price, max_price)
|
return (min_price, max_price)
|
||||||
|
|
||||||
def get_price_range(self, quantity=1, buy=True, bom=True, internal=False):
|
def get_price_range(self, quantity=1, buy=True, bom=True, internal=False, purchase=False):
|
||||||
|
|
||||||
""" Return the price range for this part. This price can be either:
|
""" Return the price range for this part. This price can be either:
|
||||||
|
|
||||||
- Supplier price (if purchased from suppliers)
|
- Supplier price (if purchased from suppliers)
|
||||||
- BOM price (if built from other parts)
|
- BOM price (if built from other parts)
|
||||||
- Internal price (if set for the part)
|
- Internal price (if set for the part)
|
||||||
|
- Purchase price (if set for the part)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Minimum of the supplier, BOM or internal price. If no pricing available, returns None
|
Minimum of the supplier, BOM, internal or purchase price. If no pricing available, returns None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# only get internal price if set and should be used
|
# only get internal price if set and should be used
|
||||||
@ -1572,6 +1575,12 @@ class Part(MPTTModel):
|
|||||||
internal_price = self.get_internal_price(quantity)
|
internal_price = self.get_internal_price(quantity)
|
||||||
return internal_price, internal_price
|
return internal_price, internal_price
|
||||||
|
|
||||||
|
# only get purchase price if set and should be used
|
||||||
|
if purchase:
|
||||||
|
purchase_price = self.get_purchase_price(quantity)
|
||||||
|
if purchase_price:
|
||||||
|
return purchase_price
|
||||||
|
|
||||||
buy_price_range = self.get_supplier_price_range(quantity) if buy else None
|
buy_price_range = self.get_supplier_price_range(quantity) if buy else None
|
||||||
bom_price_range = self.get_bom_price_range(quantity, internal=internal) if bom else None
|
bom_price_range = self.get_bom_price_range(quantity, internal=internal) if bom else None
|
||||||
|
|
||||||
@ -1641,6 +1650,11 @@ class Part(MPTTModel):
|
|||||||
def internal_unit_pricing(self):
|
def internal_unit_pricing(self):
|
||||||
return self.get_internal_price(1)
|
return self.get_internal_price(1)
|
||||||
|
|
||||||
|
def get_purchase_price(self, quantity):
|
||||||
|
currency = currency_code_default()
|
||||||
|
prices = [convert_money(item.purchase_price, currency).amount for item in self.stock_items.all()]
|
||||||
|
return min(prices) * quantity, max(prices) * quantity
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def copy_bom_from(self, other, clear=True, **kwargs):
|
def copy_bom_from(self, other, clear=True, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user