mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
More web testing, looks ready
This commit is contained in:
parent
2f2e5862a9
commit
9e56bf90c5
@ -156,7 +156,7 @@ class EditSupplierPartForm(HelperForm):
|
||||
""" Returns tuples for all manufacturers """
|
||||
empty_choice = [('', '----------')]
|
||||
|
||||
manufacturers = [(manufacturer.id, manufacturer.name) for manufacturer in Company.objects.all()]
|
||||
manufacturers = [(manufacturer.id, manufacturer.name) for manufacturer in Company.objects.filter(is_manufacturer=True)]
|
||||
|
||||
return empty_choice + manufacturers
|
||||
|
||||
|
@ -70,7 +70,7 @@ class Migration(migrations.Migration):
|
||||
('MPN', models.CharField(help_text='Manufacturer Part Number', max_length=100, null=True, verbose_name='MPN')),
|
||||
('link', InvenTree.fields.InvenTreeURLField(blank=True, help_text='URL for external manufacturer part link', null=True, verbose_name='Link')),
|
||||
('description', models.CharField(blank=True, help_text='Manufacturer part description', max_length=250, null=True, verbose_name='Description')),
|
||||
('manufacturer', models.ForeignKey(help_text='Select manufacturer', limit_choices_to={'is_manufacturer': True}, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='manufacturer_parts', to='company.Company', verbose_name='Manufacturer')),
|
||||
('manufacturer', models.ForeignKey(help_text='Select manufacturer', limit_choices_to={'is_manufacturer': True}, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='manufactured_parts', to='company.Company', verbose_name='Manufacturer')),
|
||||
('part', models.ForeignKey(help_text='Select part', limit_choices_to={'purchaseable': True}, on_delete=django.db.models.deletion.CASCADE, related_name='manufacturer_parts', to='part.Part', verbose_name='Base Part')),
|
||||
],
|
||||
options={
|
||||
@ -80,7 +80,7 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='supplierpart',
|
||||
name='manufacturer_part',
|
||||
field=models.ForeignKey(blank=True, help_text='Select manufacturer part', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='manufacturer_parts', to='company.ManufacturerPart', verbose_name='Manufacturer Part'),
|
||||
field=models.ForeignKey(blank=True, help_text='Select manufacturer part', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='supplier_parts', to='company.ManufacturerPart', verbose_name='Manufacturer Part'),
|
||||
),
|
||||
# Make new ManufacturerPart with SupplierPart "manufacturer" and "MPN"
|
||||
# fields, then link it to the new SupplierPart "manufacturer_part" field
|
||||
|
@ -308,7 +308,7 @@ class ManufacturerPart(models.Model):
|
||||
Company,
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
related_name='manufacturer_parts',
|
||||
related_name='manufactured_parts',
|
||||
limit_choices_to={
|
||||
'is_manufacturer': True
|
||||
},
|
||||
|
@ -527,6 +527,26 @@ class SupplierPartEdit(AjaxUpdateView):
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = _('Edit Supplier Part')
|
||||
|
||||
def save(self, supplier_part, form, **kwargs):
|
||||
""" Save ManufacturerPart data """
|
||||
|
||||
# Save supplier part object
|
||||
supplier_part = super().save(supplier_part, form)
|
||||
|
||||
# Save manufacturer part object
|
||||
manufacturer_id = form.cleaned_data.get('manufacturer', None)
|
||||
try:
|
||||
manufacturer = Company.objects.get(pk=manufacturer_id)
|
||||
except Company.DoesNotExist:
|
||||
pass
|
||||
MPN = form.cleaned_data.get('MPN', None)
|
||||
|
||||
manufacturer_part = supplier_part.manufacturer_part
|
||||
manufacturer_part.manufacturer = manufacturer
|
||||
manufacturer_part.MPN = MPN
|
||||
|
||||
manufacturer_part.save()
|
||||
|
||||
def get_form(self):
|
||||
form = super().get_form()
|
||||
|
||||
@ -541,6 +561,19 @@ class SupplierPartEdit(AjaxUpdateView):
|
||||
|
||||
return form
|
||||
|
||||
def get_initial(self):
|
||||
""" Fetch data from ManufacturerPart """
|
||||
|
||||
initials = super(SupplierPartEdit, self).get_initial().copy()
|
||||
|
||||
supplier_part = self.get_object()
|
||||
|
||||
if supplier_part.manufacturer_part:
|
||||
initials['manufacturer'] = supplier_part.manufacturer_part.manufacturer.id
|
||||
initials['MPN'] = supplier_part.manufacturer_part.MPN
|
||||
|
||||
return initials
|
||||
|
||||
|
||||
class SupplierPartCreate(AjaxCreateView):
|
||||
""" Create view for making new SupplierPart """
|
||||
@ -587,7 +620,6 @@ class SupplierPartCreate(AjaxCreateView):
|
||||
|
||||
# Process manufacturer data
|
||||
part = form.cleaned_data.get('part', None)
|
||||
print(f'{part=}')
|
||||
manufacturer_id = form.cleaned_data.get('manufacturer', None)
|
||||
|
||||
manufacturer_part = None
|
||||
@ -602,12 +634,10 @@ class SupplierPartCreate(AjaxCreateView):
|
||||
# Save the supplier part object
|
||||
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)
|
||||
|
||||
@ -667,9 +697,7 @@ class SupplierPartCreate(AjaxCreateView):
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user