mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	total_price for orders (#4447)
* Adds unit test for counting queries on PurchaseOrderList API endpoint - We will work to make this queryset more efficient * PEP fixes * Add 'total_price' fields to SalesOrder and PurchaseOrder models * PurchaseOrder list API now has constant query count * Data migration for updating existing PurchaseOrder and SalesOrder instances - Calculate total_price for any existing order - Will fail if exchange rates are not available * Add total_price_currency to API serializers * Render total_price in SalesOrder table * Add ability to filter both lists by total_price field * Update total_price whenever an order is updated * Update total price whenever a lineitem is saved or deleted * Add query-counting unit test for SalesOrder list API * Calling refresh_from_db inside a save() method is *not* a good idea
This commit is contained in:
		@@ -2,7 +2,6 @@
 | 
			
		||||
 | 
			
		||||
from django.core.exceptions import ObjectDoesNotExist
 | 
			
		||||
 | 
			
		||||
from djmoney.contrib.exchange.models import ExchangeBackend, Rate
 | 
			
		||||
from djmoney.money import Money
 | 
			
		||||
 | 
			
		||||
import common.models
 | 
			
		||||
@@ -18,31 +17,6 @@ from InvenTree.status_codes import PurchaseOrderStatus
 | 
			
		||||
class PartPricingTests(InvenTreeTestCase):
 | 
			
		||||
    """Unit tests for part pricing calculations"""
 | 
			
		||||
 | 
			
		||||
    def generate_exchange_rates(self):
 | 
			
		||||
        """Generate some exchange rates to work with"""
 | 
			
		||||
 | 
			
		||||
        rates = {
 | 
			
		||||
            'AUD': 1.5,
 | 
			
		||||
            'CAD': 1.7,
 | 
			
		||||
            'GBP': 0.9,
 | 
			
		||||
            'USD': 1.0,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        # Create a dummy backend
 | 
			
		||||
        ExchangeBackend.objects.create(
 | 
			
		||||
            name='InvenTreeExchange',
 | 
			
		||||
            base_currency='USD',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        backend = ExchangeBackend.objects.get(name='InvenTreeExchange')
 | 
			
		||||
 | 
			
		||||
        for currency, rate in rates.items():
 | 
			
		||||
            Rate.objects.create(
 | 
			
		||||
                currency=currency,
 | 
			
		||||
                value=rate,
 | 
			
		||||
                backend=backend,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        """Setup routines"""
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user