mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Almost there, needs some interface testing and tweaking
This commit is contained in:
parent
9c8817d73b
commit
0b1f22c7fd
@ -235,6 +235,12 @@ class SupplierPartList(generics.ListCreateAPIView):
|
|||||||
if part is not None:
|
if part is not None:
|
||||||
queryset = queryset.filter(part=part)
|
queryset = queryset.filter(part=part)
|
||||||
|
|
||||||
|
# Filter by manufacturer part?
|
||||||
|
manufacturer_part = params.get('manufacturer_part', None)
|
||||||
|
|
||||||
|
if manufacturer_part is not None:
|
||||||
|
queryset = queryset.filter(manufacturer_part=manufacturer_part)
|
||||||
|
|
||||||
# Filter by 'active' status of the part?
|
# Filter by 'active' status of the part?
|
||||||
active = params.get('active', None)
|
active = params.get('active', None)
|
||||||
|
|
||||||
|
@ -122,13 +122,27 @@ class EditSupplierPartForm(HelperForm):
|
|||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
manufacturer = django.forms.ChoiceField(
|
||||||
|
required=False,
|
||||||
|
help_text=_('Select manufacturer'),
|
||||||
|
choices=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
MPN = django.forms.CharField(
|
||||||
|
required=False,
|
||||||
|
help_text=_('Manufacturer Part Number'),
|
||||||
|
max_length=100,
|
||||||
|
label=_('MPN'),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SupplierPart
|
model = SupplierPart
|
||||||
fields = [
|
fields = [
|
||||||
'part',
|
'part',
|
||||||
'supplier',
|
'supplier',
|
||||||
'SKU',
|
'SKU',
|
||||||
'manufacturer_part',
|
'manufacturer',
|
||||||
|
'MPN',
|
||||||
'description',
|
'description',
|
||||||
'link',
|
'link',
|
||||||
'note',
|
'note',
|
||||||
@ -138,6 +152,19 @@ class EditSupplierPartForm(HelperForm):
|
|||||||
'packaging',
|
'packaging',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_manufacturer_choices(self):
|
||||||
|
""" Returns tuples for all manufacturers """
|
||||||
|
empty_choice = [('', '----------')]
|
||||||
|
|
||||||
|
manufacturers = [(manufacturer.id, manufacturer.name) for manufacturer in Company.objects.all()]
|
||||||
|
|
||||||
|
return empty_choice + manufacturers
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.fields['manufacturer'].choices = self.get_manufacturer_choices()
|
||||||
|
|
||||||
|
|
||||||
class EditPriceBreakForm(HelperForm):
|
class EditPriceBreakForm(HelperForm):
|
||||||
""" Form for creating / editing a supplier price break """
|
""" Form for creating / editing a supplier price break """
|
||||||
|
@ -217,7 +217,7 @@ class Company(models.Model):
|
|||||||
def stock_items(self):
|
def stock_items(self):
|
||||||
""" Return a list of all stock items supplied or manufactured by this company """
|
""" Return a list of all stock items supplied or manufactured by this company """
|
||||||
stock = apps.get_model('stock', 'StockItem')
|
stock = apps.get_model('stock', 'StockItem')
|
||||||
return stock.objects.filter(Q(supplier_part__supplier=self.id) | Q(supplier_part__manufacturer=self.id)).all()
|
return stock.objects.filter(Q(supplier_part__supplier=self.id) | Q(supplier_part__manufacturer_part__manufacturer=self.id)).all()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stock_count(self):
|
def stock_count(self):
|
||||||
@ -335,6 +335,25 @@ class ManufacturerPart(models.Model):
|
|||||||
help_text=_('Manufacturer part description')
|
help_text=_('Manufacturer part description')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, part, manufacturer, mpn, link, description):
|
||||||
|
""" Check if ManufacturerPart instance does not already exist
|
||||||
|
then create it
|
||||||
|
"""
|
||||||
|
|
||||||
|
manufacturer_part = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
manufacturer_part = ManufacturerPart.objects.get(part=part, manufacturer=manufacturer, MPN=mpn)
|
||||||
|
except ManufacturerPart.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not manufacturer_part:
|
||||||
|
manufacturer_part = ManufacturerPart(part=part, manufacturer=manufacturer, MPN=mpn, description=description, link=link)
|
||||||
|
manufacturer_part.save()
|
||||||
|
|
||||||
|
return manufacturer_part
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = ''
|
s = ''
|
||||||
|
|
||||||
@ -440,10 +459,10 @@ class SupplierPart(models.Model):
|
|||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
|
||||||
if self.manufacturer:
|
if self.manufacturer_part.manufacturer:
|
||||||
items.append(self.manufacturer.name)
|
items.append(self.manufacturer_part.manufacturer.name)
|
||||||
if self.MPN:
|
if self.manufacturer_part.MPN:
|
||||||
items.append(self.MPN)
|
items.append(self.manufacturer_part.MPN)
|
||||||
|
|
||||||
return ' | '.join(items)
|
return ' | '.join(items)
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ $('#supplier-create').click(function () {
|
|||||||
{
|
{
|
||||||
reload: true,
|
reload: true,
|
||||||
data: {
|
data: {
|
||||||
part: {{ part.id }}
|
manufacturer_part: {{ part.id }}
|
||||||
},
|
},
|
||||||
secondary: [
|
secondary: [
|
||||||
{
|
{
|
||||||
@ -48,12 +48,6 @@ $('#supplier-create').click(function () {
|
|||||||
title: '{% trans "Create new supplier" %}',
|
title: '{% trans "Create new supplier" %}',
|
||||||
url: "{% url 'supplier-create' %}"
|
url: "{% url 'supplier-create' %}"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
field: 'manufacturer',
|
|
||||||
label: '{% trans "New Manufacturer" %}',
|
|
||||||
title: '{% trans "Create new manufacturer" %}',
|
|
||||||
url: "{% url 'manufacturer-create' %}",
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -82,6 +76,7 @@ loadSupplierPartTable(
|
|||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
part: {{ part.part.id }},
|
part: {{ part.part.id }},
|
||||||
|
manufacturer_part: {{ part.id }},
|
||||||
part_detail: true,
|
part_detail: true,
|
||||||
supplier_detail: true,
|
supplier_detail: true,
|
||||||
manufacturer_detail: true,
|
manufacturer_detail: true,
|
||||||
|
@ -585,9 +585,30 @@ class SupplierPartCreate(AjaxCreateView):
|
|||||||
If single_pricing is defined, add a price break for quantity=1
|
If single_pricing is defined, add a price break for quantity=1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Process manufacturer data
|
||||||
|
part = form.cleaned_data.get('part', None)
|
||||||
|
print(f'{part=}')
|
||||||
|
manufacturer_id = form.cleaned_data.get('manufacturer', None)
|
||||||
|
|
||||||
|
manufacturer_part = None
|
||||||
|
if manufacturer_id:
|
||||||
|
manufacturer = Company.objects.get(pk=manufacturer_id)
|
||||||
|
MPN = form.cleaned_data.get('MPN', None)
|
||||||
|
description = form.cleaned_data.get('description', None)
|
||||||
|
link = form.cleaned_data.get('link', None)
|
||||||
|
|
||||||
|
manufacturer_part = ManufacturerPart.create(part=part, manufacturer=manufacturer, mpn=MPN, description=description, link=link)
|
||||||
|
|
||||||
# Save the supplier part object
|
# Save the supplier part object
|
||||||
supplier_part = super().save(form)
|
supplier_part = super().save(form)
|
||||||
|
|
||||||
|
print(f'{manufacturer_part=}')
|
||||||
|
if manufacturer_part:
|
||||||
|
# Link ManufacturerPart
|
||||||
|
supplier_part.manufacturer_part = manufacturer_part
|
||||||
|
supplier_part.save()
|
||||||
|
print(f'{supplier_part=}')
|
||||||
|
|
||||||
single_pricing = form.cleaned_data.get('single_pricing', None)
|
single_pricing = form.cleaned_data.get('single_pricing', None)
|
||||||
|
|
||||||
if single_pricing:
|
if single_pricing:
|
||||||
@ -606,6 +627,12 @@ class SupplierPartCreate(AjaxCreateView):
|
|||||||
# Hide the part field
|
# Hide the part field
|
||||||
form.fields['part'].widget = HiddenInput()
|
form.fields['part'].widget = HiddenInput()
|
||||||
|
|
||||||
|
if form.initial.get('manufacturer', None):
|
||||||
|
# Hide the manufacturer field
|
||||||
|
form.fields['manufacturer'].widget = HiddenInput()
|
||||||
|
# Hide the MPN field
|
||||||
|
form.fields['MPN'].widget = HiddenInput()
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
@ -619,6 +646,7 @@ class SupplierPartCreate(AjaxCreateView):
|
|||||||
manufacturer_id = self.get_param('manufacturer')
|
manufacturer_id = self.get_param('manufacturer')
|
||||||
supplier_id = self.get_param('supplier')
|
supplier_id = self.get_param('supplier')
|
||||||
part_id = self.get_param('part')
|
part_id = self.get_param('part')
|
||||||
|
manufacturer_part_id = self.get_param('manufacturer_part')
|
||||||
|
|
||||||
supplier = None
|
supplier = None
|
||||||
|
|
||||||
@ -634,6 +662,18 @@ class SupplierPartCreate(AjaxCreateView):
|
|||||||
initials['manufacturer'] = Company.objects.get(pk=manufacturer_id)
|
initials['manufacturer'] = Company.objects.get(pk=manufacturer_id)
|
||||||
except (ValueError, Company.DoesNotExist):
|
except (ValueError, Company.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if manufacturer_part_id:
|
||||||
|
try:
|
||||||
|
# Get ManufacturerPart instance information
|
||||||
|
manufacturer_part_obj = ManufacturerPart.objects.get(pk=manufacturer_part_id)
|
||||||
|
print(manufacturer_part_obj.part.id)
|
||||||
|
initials['part'] = Part.objects.get(pk=manufacturer_part_obj.part.id)
|
||||||
|
print(initials['part'])
|
||||||
|
initials['manufacturer'] = manufacturer_part_obj.manufacturer.id
|
||||||
|
initials['MPN'] = manufacturer_part_obj.MPN
|
||||||
|
except (ValueError, ManufacturerPart.DoesNotExist, Part.DoesNotExist, Company.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
if part_id:
|
if part_id:
|
||||||
try:
|
try:
|
||||||
|
@ -773,7 +773,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
company = params.get('company', None)
|
company = params.get('company', None)
|
||||||
|
|
||||||
if company is not None:
|
if company is not None:
|
||||||
queryset = queryset.filter(Q(supplier_part__supplier=company) | Q(supplier_part__manufacturer=company))
|
queryset = queryset.filter(Q(supplier_part__supplier=company) | Q(supplier_part__manufacturer_part__manufacturer=company))
|
||||||
|
|
||||||
# Filter by supplier
|
# Filter by supplier
|
||||||
supplier = params.get('supplier', None)
|
supplier = params.get('supplier', None)
|
||||||
@ -785,7 +785,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
manufacturer = params.get('manufacturer', None)
|
manufacturer = params.get('manufacturer', None)
|
||||||
|
|
||||||
if manufacturer is not None:
|
if manufacturer is not None:
|
||||||
queryset = queryset.filter(supplier_part__manufacturer=manufacturer)
|
queryset = queryset.filter(supplier_part__manufacturer_part__manufacturer=manufacturer)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Filter by the 'last updated' date of the stock item(s):
|
Filter by the 'last updated' date of the stock item(s):
|
||||||
|
@ -84,7 +84,7 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
'sales_order',
|
'sales_order',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
'supplier_part__supplier',
|
'supplier_part__supplier',
|
||||||
'supplier_part__manufacturer',
|
'supplier_part__manufacturer_part__manufacturer',
|
||||||
'allocations',
|
'allocations',
|
||||||
'sales_order_allocations',
|
'sales_order_allocations',
|
||||||
'location',
|
'location',
|
||||||
|
Loading…
Reference in New Issue
Block a user