mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +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()
|
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):
|
def required_parts(self):
|
||||||
""" Return a list of parts required to make this part (list of BOM items) """
|
""" Return a list of parts required to make this part (list of BOM items) """
|
||||||
parts = []
|
parts = []
|
||||||
|
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.shortcuts import HttpResponseRedirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.views.generic import DetailView, ListView, FormView
|
from django.views.generic import DetailView, ListView, FormView
|
||||||
@ -1092,19 +1093,46 @@ class BomUpload(FormView):
|
|||||||
valid = True
|
valid = True
|
||||||
|
|
||||||
for row in self.bom_rows:
|
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', [])
|
errors = row.get('errors', [])
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
|
|
||||||
self.template_name = 'part/bom_upload/select_parts.html'
|
self.template_name = 'part/bom_upload/select_parts.html'
|
||||||
|
|
||||||
ctx = self.get_context_data(form=None)
|
ctx = self.get_context_data(form=None)
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
# Save the BOM data
|
self.part.clear_bom()
|
||||||
pass
|
|
||||||
|
# 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:
|
else:
|
||||||
ctx['form_errors'] = True
|
ctx['form_errors'] = True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user