2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

More work

- Consolidated "in_stock" filter to single code location
- Improve 'limit_choices_to' for BuildItem and SalesOrderAllocation
- Various template improvements etc
This commit is contained in:
Oliver Walters
2020-04-26 16:38:29 +10:00
parent 4147163418
commit e768ada83b
20 changed files with 362 additions and 79 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-04-26 05:51
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('stock', '0033_auto_20200426_0539'),
('order', '0029_auto_20200423_1042'),
]
operations = [
migrations.AlterField(
model_name='salesorderallocation',
name='item',
field=models.ForeignKey(help_text='Select stock item to allocate', limit_choices_to={'belongs_to': None, 'build_order': None, 'customer': None, 'part__salable': True}, on_delete=django.db.models.deletion.CASCADE, related_name='sales_order_allocations', to='stock.StockItem'),
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-04-26 06:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('stock', '0034_auto_20200426_0602'),
('order', '0030_auto_20200426_0551'),
]
operations = [
migrations.AlterField(
model_name='salesorderallocation',
name='item',
field=models.ForeignKey(help_text='Select stock item to allocate', limit_choices_to={'belongs_to': None, 'build_order': None, 'part__salable': True, 'sales_order': None}, on_delete=django.db.models.deletion.CASCADE, related_name='sales_order_allocations', to='stock.StockItem'),
),
]

View File

@ -19,7 +19,7 @@ import os
from datetime import datetime
from decimal import Decimal
from part.models import Part
from part import models as PartModels
from stock import models as stock_models
from company.models import Company, SupplierPart
@ -511,7 +511,7 @@ class SalesOrderAllocation(models.Model):
try:
if not self.line.part == self.item.part:
errors['item'] = _('Cannot allocate stock item to a line with a different part')
except Part.DoesNotExist:
except PartModels.Part.DoesNotExist:
errors['line'] = _('Cannot allocate stock to a line without a part')
if self.quantity > self.item.quantity:
@ -535,7 +535,12 @@ class SalesOrderAllocation(models.Model):
'stock.StockItem',
on_delete=models.CASCADE,
related_name='sales_order_allocations',
limit_choices_to={'part__salable': True},
limit_choices_to={
'part__salable': True,
'belongs_to': None,
'sales_order': None,
'build_order': None,
},
help_text=_('Select stock item to allocate')
)
@ -565,6 +570,8 @@ class SalesOrderAllocation(models.Model):
- Mark the StockItem as belonging to the Customer (this will remove it from stock)
"""
order = self.line.order
item = self.item
# If the allocated quantity is less than the amount available,
@ -579,7 +586,7 @@ class SalesOrderAllocation(models.Model):
self.save()
# Assign the StockItem to the SalesOrder customer
item.customer = self.line.order.customer
item.sales_order = order
# Clear the location
item.location = None