mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Calculate parts on order for a Part / SupplierPart
This commit is contained in:
parent
4af1f6ca9f
commit
31ad31365a
@ -32,6 +32,19 @@ class OrderStatus(StatusCode):
|
|||||||
RETURNED: _("Returned"),
|
RETURNED: _("Returned"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Open orders
|
||||||
|
OPEN = [
|
||||||
|
PENDING,
|
||||||
|
PLACED,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Failed orders
|
||||||
|
FAILED = [
|
||||||
|
CANCELLED,
|
||||||
|
LOST,
|
||||||
|
RETURNED
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class StockStatus(StatusCode):
|
class StockStatus(StatusCode):
|
||||||
|
|
||||||
|
@ -10,9 +10,10 @@ import os
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.db import models
|
||||||
|
from django.db.models import Sum
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.db import models
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.staticfiles.templatetags.staticfiles import static
|
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||||
@ -132,10 +133,7 @@ class Company(models.Model):
|
|||||||
|
|
||||||
def outstanding_purchase_orders(self):
|
def outstanding_purchase_orders(self):
|
||||||
""" Return purchase orders which are 'outstanding' """
|
""" Return purchase orders which are 'outstanding' """
|
||||||
return self.purchase_orders.filter(status__in=[
|
return self.purchase_orders.filter(status__in=OrderStatus.OPEN)
|
||||||
OrderStatus.PENDING,
|
|
||||||
OrderStatus.PLACED
|
|
||||||
])
|
|
||||||
|
|
||||||
def complete_purchase_orders(self):
|
def complete_purchase_orders(self):
|
||||||
return self.purchase_orders.filter(status=OrderStatus.COMPLETE)
|
return self.purchase_orders.filter(status=OrderStatus.COMPLETE)
|
||||||
@ -143,12 +141,7 @@ class Company(models.Model):
|
|||||||
def failed_purchase_orders(self):
|
def failed_purchase_orders(self):
|
||||||
""" Return any purchase orders which were not successful """
|
""" Return any purchase orders which were not successful """
|
||||||
|
|
||||||
return self.purchase_orders.filter(status__in=[
|
return self.purchase_orders.filter(status__in=OrderStatus.FAILED)
|
||||||
OrderStatus.CANCELLED,
|
|
||||||
OrderStatus.LOST,
|
|
||||||
OrderStatus.RETURNED
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
class Contact(models.Model):
|
class Contact(models.Model):
|
||||||
""" A Contact represents a person who works at a particular company.
|
""" A Contact represents a person who works at a particular company.
|
||||||
@ -307,6 +300,24 @@ class SupplierPart(models.Model):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def open_orders(self):
|
||||||
|
""" Return a database query for PO line items for this SupplierPart,
|
||||||
|
limited to purchase orders that are open / outstanding.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.purchase_order_line_items.prefetch_related('order').filter(order__status__in=OrderStatus.OPEN)
|
||||||
|
|
||||||
|
def on_order(self):
|
||||||
|
""" Return the total quantity of items currently on order.
|
||||||
|
|
||||||
|
Subtract partially received stock as appropriate
|
||||||
|
"""
|
||||||
|
|
||||||
|
totals = self.open_orders().aggregate(Sum('quantity'), Sum('received'))
|
||||||
|
|
||||||
|
return totals['quantity__sum'] - totals['received__sum']
|
||||||
|
|
||||||
|
|
||||||
def purchase_orders(self):
|
def purchase_orders(self):
|
||||||
""" Returns a list of purchase orders relating to this supplier part """
|
""" Returns a list of purchase orders relating to this supplier part """
|
||||||
|
|
||||||
|
@ -806,6 +806,11 @@ class Part(models.Model):
|
|||||||
|
|
||||||
return orders
|
return orders
|
||||||
|
|
||||||
|
def on_order(self):
|
||||||
|
""" Return the total number of items on order for this part. """
|
||||||
|
|
||||||
|
return sum([part.on_order() for part in self.supplier_parts.all()])
|
||||||
|
|
||||||
|
|
||||||
def attach_file(instance, filename):
|
def attach_file(instance, filename):
|
||||||
""" Function for storing a file for a PartAttachment
|
""" Function for storing a file for a PartAttachment
|
||||||
|
@ -96,6 +96,12 @@
|
|||||||
<td>{{ part.allocation_count }}</td>
|
<td>{{ part.allocation_count }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if part.on_order > 0 %}
|
||||||
|
<tr>
|
||||||
|
<td>On Order</td>
|
||||||
|
<td>{{ part.on_order }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user