diff --git a/InvenTree/InvenTree/status_codes.py b/InvenTree/InvenTree/status_codes.py index f8089cb5de..2032ec75d8 100644 --- a/InvenTree/InvenTree/status_codes.py +++ b/InvenTree/InvenTree/status_codes.py @@ -167,10 +167,6 @@ class StockStatus(StatusCode): # This can be used as a quick check for filtering NOT_IN_STOCK = 100 - SHIPPED = 110 # Item has been shipped to a customer - ASSIGNED_TO_BUILD = 120 - ASSIGNED_TO_OTHER_ITEM = 130 - options = { OK: _("OK"), ATTENTION: _("Attention needed"), @@ -179,9 +175,6 @@ class StockStatus(StatusCode): LOST: _("Lost"), REJECTED: _("Rejected"), RETURNED: _("Returned"), - SHIPPED: _('Shipped'), - ASSIGNED_TO_BUILD: _("Used for Build"), - ASSIGNED_TO_OTHER_ITEM: _("Installed in Stock Item") } colors = { @@ -190,9 +183,6 @@ class StockStatus(StatusCode): DAMAGED: 'red', DESTROYED: 'red', REJECTED: 'red', - SHIPPED: 'green', - ASSIGNED_TO_BUILD: 'blue', - ASSIGNED_TO_OTHER_ITEM: 'blue', } # The following codes correspond to parts that are 'available' or 'in stock' @@ -208,9 +198,6 @@ class StockStatus(StatusCode): DESTROYED, LOST, REJECTED, - SHIPPED, - ASSIGNED_TO_BUILD, - ASSIGNED_TO_OTHER_ITEM, ] # The following codes are available for receiving goods diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 23043d077f..89e79761e8 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -21,7 +21,7 @@ from markdownx.models import MarkdownxField from mptt.models import MPTTModel, TreeForeignKey -from InvenTree.status_codes import BuildStatus, StockStatus +from InvenTree.status_codes import BuildStatus from InvenTree.fields import InvenTreeURLField from InvenTree.helpers import decimal2string @@ -501,7 +501,6 @@ class BuildItem(models.Model): # TODO - If the item__part object is not trackable, delete the stock item here - item.status = StockStatus.ASSIGNED_TO_BUILD item.build_order = self.build item.save() diff --git a/InvenTree/build/test_build.py b/InvenTree/build/test_build.py index c1fb4a5efd..32ad33dab3 100644 --- a/InvenTree/build/test_build.py +++ b/InvenTree/build/test_build.py @@ -211,15 +211,12 @@ class BuildTest(TestCase): # New stock items created and assigned to the build self.assertEqual(StockItem.objects.get(pk=4).quantity, 50) self.assertEqual(StockItem.objects.get(pk=4).build_order, self.build) - self.assertEqual(StockItem.objects.get(pk=4).status, status.StockStatus.ASSIGNED_TO_BUILD) self.assertEqual(StockItem.objects.get(pk=5).quantity, 50) self.assertEqual(StockItem.objects.get(pk=5).build_order, self.build) - self.assertEqual(StockItem.objects.get(pk=5).status, status.StockStatus.ASSIGNED_TO_BUILD) self.assertEqual(StockItem.objects.get(pk=6).quantity, 250) self.assertEqual(StockItem.objects.get(pk=6).build_order, self.build) - self.assertEqual(StockItem.objects.get(pk=6).status, status.StockStatus.ASSIGNED_TO_BUILD) # And a new stock item created for the build output self.assertEqual(StockItem.objects.get(pk=7).quantity, 1) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index bb403d837d..06d90e33df 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -46,6 +46,18 @@ class AssignStockItemToCustomerForm(HelperForm): ] +class ReturnStockItemForm(HelperForm): + """ + Form for manually returning a StockItem into stock + """ + + class Meta: + model = StockItem + fields = [ + 'location', + ] + + class EditStockItemTestResultForm(HelperForm): """ Form for creating / editing a StockItemTestResult object. diff --git a/InvenTree/stock/migrations/0048_auto_20200807_2344.py b/InvenTree/stock/migrations/0048_auto_20200807_2344.py new file mode 100644 index 0000000000..b859344bb0 --- /dev/null +++ b/InvenTree/stock/migrations/0048_auto_20200807_2344.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-08-07 23:44 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0047_auto_20200605_0932'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='status', + field=models.PositiveIntegerField(choices=[(10, 'OK'), (50, 'Attention needed'), (55, 'Damaged'), (60, 'Destroyed'), (70, 'Lost'), (65, 'Rejected'), (85, 'Returned')], default=10, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 736e2218bf..0a9fc6b8bd 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -140,6 +140,7 @@ class StockItem(MPTTModel): sales_order=None, build_order=None, belongs_to=None, + customer=None, status__in=StockStatus.AVAILABLE_CODES ) @@ -219,12 +220,6 @@ class StockItem(MPTTModel): super().clean() - if self.status == StockStatus.ASSIGNED_TO_OTHER_ITEM and self.belongs_to is None: - raise ValidationError({ - 'belongs_to': "Belongs_to field must be specified as statis is marked as ASSIGNED_TO_OTHER_ITEM", - 'status': 'Status cannot be marked as ASSIGNED_TO_OTHER_ITEM if the belongs_to field is not set', - }) - try: if self.part.trackable: # Trackable parts must have integer values for quantity field! @@ -477,7 +472,6 @@ class StockItem(MPTTModel): # Update StockItem fields with new information item.sales_order = order - item.status = StockStatus.SHIPPED item.customer = customer item.location = None @@ -495,6 +489,23 @@ class StockItem(MPTTModel): # Return the reference to the stock item return item + def returnFromCustomer(self, location, user=None): + """ + Return stock item from customer, back into the specified location. + """ + + self.addTransactionNote( + _("Returned from customer") + " " + self.customer.name, + user, + notes=_("Returned to location") + " " + location.name, + system=True + ) + + self.customer = None + self.location = location + + self.save() + # If stock item is incoming, an (optional) ETA field # expected_arrival = models.DateField(null=True, blank=True) @@ -599,6 +610,10 @@ class StockItem(MPTTModel): if self.build_order is not None: return False + # Not 'in stock' if it has been assigned to a customer + if self.customer is not None: + return False + # Not 'in stock' if the status code makes it unavailable if self.status in StockStatus.UNAVAILABLE_CODES: return False diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index a35b5f0346..ce055d65c5 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -86,30 +86,34 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% endif %} - {% if item.in_stock %} - {% endif %} - - + +