mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Save the selected BOM data
This commit is contained in:
parent
c2dbc37f70
commit
482a5dae4b
@ -671,6 +671,13 @@ class Part(models.Model):
|
||||
|
||||
self.save()
|
||||
|
||||
@transaction.atomic
|
||||
def clear_bom(self):
|
||||
""" Clear the BOM items for the part (delete all BOM lines).
|
||||
"""
|
||||
|
||||
self.bom_items.all().delete()
|
||||
|
||||
def required_parts(self):
|
||||
""" Return a list of parts required to make this part (list of BOM items) """
|
||||
parts = []
|
||||
|
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.shortcuts import HttpResponseRedirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.views.generic import DetailView, ListView, FormView
|
||||
@ -1092,19 +1093,46 @@ class BomUpload(FormView):
|
||||
valid = True
|
||||
|
||||
for row in self.bom_rows:
|
||||
# Has a part been selected for the given row?
|
||||
if row.get('part', None) is None:
|
||||
row['errors']['part'] = _('Select a part')
|
||||
|
||||
# Has a quantity been specified?
|
||||
if row.get('quantity', None) is None:
|
||||
row['errors']['quantity'] = _('Specify quantity')
|
||||
|
||||
errors = row.get('errors', [])
|
||||
|
||||
if len(errors) > 0:
|
||||
valid = False
|
||||
|
||||
|
||||
self.template_name = 'part/bom_upload/select_parts.html'
|
||||
|
||||
ctx = self.get_context_data(form=None)
|
||||
|
||||
if valid:
|
||||
# Save the BOM data
|
||||
pass
|
||||
self.part.clear_bom()
|
||||
|
||||
# Generate new BOM items
|
||||
for row in self.bom_rows:
|
||||
part = row.get('part')
|
||||
quantity = row.get('quantity')
|
||||
reference = row.get('reference')
|
||||
notes = row.get('notes')
|
||||
|
||||
# Create a new BOM item!
|
||||
item = BomItem(
|
||||
part=self.part,
|
||||
sub_part=part,
|
||||
quantity=quantity,
|
||||
reference=reference,
|
||||
note=notes
|
||||
)
|
||||
|
||||
item.save()
|
||||
|
||||
# Redirect to the BOM view
|
||||
return HttpResponseRedirect(reverse('part-bom', kwargs={'pk': self.part.id}))
|
||||
else:
|
||||
ctx['form_errors'] = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user