mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Auto-fill build quantity
This commit is contained in:
parent
c8650ce34c
commit
ba542dcbdb
@ -39,6 +39,11 @@ class EditBuildForm(HelperForm):
|
||||
help_text=_('Target date for build completion. Build will be overdue after this date.')
|
||||
)
|
||||
|
||||
quantity = RoundingDecimalFormField(
|
||||
max_digits=10, decimal_places=5,
|
||||
help_text=_('Number of items to build')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Build
|
||||
fields = [
|
||||
|
@ -675,6 +675,14 @@ class BuildCreate(AjaxCreateView):
|
||||
|
||||
initials = super(BuildCreate, self).get_initial().copy()
|
||||
|
||||
|
||||
initials['parent'] = self.request.GET.get('parent', None)
|
||||
|
||||
# User has provided a SalesOrder ID
|
||||
initials['sales_order'] = self.request.GET.get('sales_order', None)
|
||||
|
||||
initials['quantity'] = self.request.GET.get('quantity', 1)
|
||||
|
||||
part = self.request.GET.get('part', None)
|
||||
|
||||
if part:
|
||||
@ -684,18 +692,18 @@ class BuildCreate(AjaxCreateView):
|
||||
# User has provided a Part ID
|
||||
initials['part'] = part
|
||||
initials['destination'] = part.get_default_location()
|
||||
|
||||
to_order = part.quantity_to_order
|
||||
|
||||
if to_order < 1:
|
||||
to_order = 1
|
||||
|
||||
initials['quantity'] = to_order
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
initials['reference'] = Build.getNextBuildNumber()
|
||||
|
||||
initials['parent'] = self.request.GET.get('parent', None)
|
||||
|
||||
# User has provided a SalesOrder ID
|
||||
initials['sales_order'] = self.request.GET.get('sales_order', None)
|
||||
|
||||
initials['quantity'] = self.request.GET.get('quantity', 1)
|
||||
|
||||
# Pre-fill the issued_by user
|
||||
initials['issued_by'] = self.request.user
|
||||
|
||||
|
@ -976,20 +976,43 @@ class Part(MPTTModel):
|
||||
|
||||
return quantity
|
||||
|
||||
def required_order_quantity(self):
|
||||
"""
|
||||
Return total required to fulfil orders
|
||||
"""
|
||||
|
||||
return self.required_build_order_quantity() + self.required_sales_order_quantity()
|
||||
|
||||
@property
|
||||
def quantity_to_order(self):
|
||||
""" Return the quantity needing to be ordered for this part. """
|
||||
"""
|
||||
Return the quantity needing to be ordered for this part.
|
||||
|
||||
# How many do we need to have "on hand" at any point?
|
||||
required = self.net_stock - self.minimum_stock
|
||||
Here, an "order" could be one of:
|
||||
- Build Order
|
||||
- Sales Order
|
||||
|
||||
if required < 0:
|
||||
return abs(required)
|
||||
To work out how many we need to order:
|
||||
|
||||
# Do not need to order any
|
||||
return 0
|
||||
Stock on hand = self.total_stock
|
||||
Required for orders = self.required_order_quantity()
|
||||
Currently on order = self.on_order
|
||||
Currently building = self.quantity_being_built
|
||||
|
||||
"""
|
||||
|
||||
# Total requirement
|
||||
required = self.required_order_quantity()
|
||||
|
||||
# Subtract stock levels
|
||||
required -= max(self.total_stock, self.minimum_stock)
|
||||
|
||||
# Subtract quantity on order
|
||||
required -= self.on_order
|
||||
|
||||
# Subtract quantity being built
|
||||
required -= self.quantity_being_built
|
||||
|
||||
required = self.net_stock
|
||||
return max(required, 0)
|
||||
|
||||
@property
|
||||
|
Loading…
Reference in New Issue
Block a user