diff --git a/InvenTree/company/fixtures/supplier_part.yaml b/InvenTree/company/fixtures/supplier_part.yaml index 446339d58b..02cf33e12e 100644 --- a/InvenTree/company/fixtures/supplier_part.yaml +++ b/InvenTree/company/fixtures/supplier_part.yaml @@ -52,3 +52,10 @@ part: 2 supplier: 2 SKU: 'ZERGM312' + +- model: company.supplierpart + pk: 5 + fields: + part: 4 + supplier: 2 + SKU: 'R_4K7_0603' diff --git a/InvenTree/company/tests.py b/InvenTree/company/tests.py index b1e05efe14..e4a70b077a 100644 --- a/InvenTree/company/tests.py +++ b/InvenTree/company/tests.py @@ -65,7 +65,7 @@ class CompanySimpleTest(TestCase): self.assertEqual(acme.supplied_part_count, 4) self.assertTrue(appel.has_parts) - self.assertEqual(appel.supplied_part_count, 3) + self.assertEqual(appel.supplied_part_count, 4) self.assertTrue(zerg.has_parts) self.assertEqual(zerg.supplied_part_count, 2) diff --git a/InvenTree/order/fixtures/order.yaml b/InvenTree/order/fixtures/order.yaml index 6b65c20786..769f7702e5 100644 --- a/InvenTree/order/fixtures/order.yaml +++ b/InvenTree/order/fixtures/order.yaml @@ -68,6 +68,7 @@ order: 1 part: 1 quantity: 100 + destination: 5 # Desk/Drawer_1 # 250 x ACME0002 (M2x4 LPHS) # Partially received (50) @@ -95,3 +96,10 @@ part: 3 quantity: 100 +# 1 x R_4K7_0603 +- model: order.purchaseorderlineitem + pk: 23 + fields: + order: 1 + part: 5 + quantity: 1 diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 3973888e95..effa696d43 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -79,12 +79,17 @@ class ShipSalesOrderForm(HelperForm): class ReceivePurchaseOrderForm(HelperForm): - location = TreeNodeChoiceField(queryset=StockLocation.objects.all(), required=True, label=_('Location'), help_text=_('Receive parts to this location')) + location = TreeNodeChoiceField( + queryset=StockLocation.objects.all(), + required=True, + label=_("Destination"), + help_text=_("Receive parts to this location"), + ) class Meta: model = PurchaseOrder fields = [ - 'location', + "location", ] @@ -195,6 +200,7 @@ class EditPurchaseOrderLineItemForm(HelperForm): 'quantity', 'reference', 'purchase_price', + 'destination', 'notes', ] diff --git a/InvenTree/order/migrations/0046_purchaseorderlineitem_destination.py b/InvenTree/order/migrations/0046_purchaseorderlineitem_destination.py new file mode 100644 index 0000000000..fa08c91e0d --- /dev/null +++ b/InvenTree/order/migrations/0046_purchaseorderlineitem_destination.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2 on 2021-05-13 22:38 + +from django.db import migrations +import django.db.models.deletion +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("stock", "0063_auto_20210511_2343"), + ("order", "0045_auto_20210504_1946"), + ] + + operations = [ + migrations.AddField( + model_name="purchaseorderlineitem", + name="destination", + field=mptt.fields.TreeForeignKey( + blank=True, + help_text="Where does the Purchaser want this item to be stored?", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="po_lines", + to="stock.stocklocation", + verbose_name="Destination", + ), + ), + ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 49504b6d89..c150331f94 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -20,6 +20,7 @@ from django.utils.translation import ugettext_lazy as _ from common.settings import currency_code_default from markdownx.models import MarkdownxField +from mptt.models import TreeForeignKey from djmoney.models.fields import MoneyField @@ -672,6 +673,29 @@ class PurchaseOrderLineItem(OrderLineItem): help_text=_('Unit purchase price'), ) + destination = TreeForeignKey( + 'stock.StockLocation', on_delete=models.DO_NOTHING, + verbose_name=_('Destination'), + related_name='po_lines', + blank=True, null=True, + help_text=_('Where does the Purchaser want this item to be stored?') + ) + + def get_destination(self): + """Show where the line item is or should be placed""" + # NOTE: If a line item gets split when recieved, only an arbitrary + # stock items location will be reported as the location for the + # entire line. + for stock in stock_models.StockItem.objects.filter( + supplier_part=self.part, purchase_order=self.order + ): + if stock.location: + return stock.location + if self.destination: + return self.destination + if self.part and self.part.part and self.part.part.default_location: + return self.part.part.default_location + def remaining(self): """ Calculate the number of items remaining to be received """ r = self.quantity - self.received diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 6091140313..a50c72e13e 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -17,6 +17,7 @@ from InvenTree.serializers import InvenTreeAttachmentSerializerField from company.serializers import CompanyBriefSerializer, SupplierPartSerializer from part.serializers import PartBriefSerializer +from stock.serializers import LocationBriefSerializer from .models import PurchaseOrder, PurchaseOrderLineItem from .models import PurchaseOrderAttachment, SalesOrderAttachment @@ -116,6 +117,8 @@ class POLineItemSerializer(InvenTreeModelSerializer): purchase_price_string = serializers.CharField(source='purchase_price', read_only=True) + destination = LocationBriefSerializer(source='get_destination', read_only=True) + class Meta: model = PurchaseOrderLineItem @@ -132,6 +135,7 @@ class POLineItemSerializer(InvenTreeModelSerializer): 'purchase_price', 'purchase_price_currency', 'purchase_price_string', + 'destination', ] diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 5359b61651..0ad73923a2 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -234,6 +234,10 @@ $("#po-table").inventreeTable({ return (progressA < progressB) ? 1 : -1; } }, + { + field: 'destination.pathstring', + title: '{% trans "Destination" %}', + }, { field: 'notes', title: '{% trans "Notes" %}', diff --git a/InvenTree/order/templates/order/receive_parts.html b/InvenTree/order/templates/order/receive_parts.html index 35ce4b6513..bfddf01ce9 100644 --- a/InvenTree/order/templates/order/receive_parts.html +++ b/InvenTree/order/templates/order/receive_parts.html @@ -22,6 +22,7 @@ {% trans "Received" %} {% trans "Receive" %} {% trans "Status" %} + {% trans "Destination" %} {% for line in lines %} @@ -53,6 +54,9 @@ + + {{ line.get_destination }} +