Add function to duplicate stock item

This commit is contained in:
Oliver Walters 2019-04-18 23:28:46 +10:00
parent 05beb26c82
commit 8040ad8a6a
4 changed files with 31 additions and 3 deletions

View File

@ -102,7 +102,7 @@
{
follow: true,
data: {
copy_part: {{ part.id }},
copy: {{ part.id }},
},
}
);

View File

@ -78,7 +78,7 @@ class PartCreate(AjaxCreateView):
def get_initial(self):
# Is the client attempting to copy an existing part?
part_to_copy = self.request.GET.get('copy_part', None)
part_to_copy = self.request.GET.get('copy', None)
if part_to_copy:
try:

View File

@ -13,6 +13,7 @@
<h3>
<div style='float: right;'>
<div class="dropdown" style="float: right;">
<button class='btn btn-primary' type='button' id='duplicate-item'>Copy Stock Item</button>
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Options
<span class="caret"></span></button>
<ul class="dropdown-menu">
@ -140,6 +141,19 @@
{% endblock %}
{% block js_ready %}
{{ block.super }}
$("#duplicate-item").click(function() {
launchModalForm(
"{% url 'stock-item-create' %}",
{
follow: true,
data: {
copy: {{ item.id }},
},
}
);
});
$("#stock-edit").click(function () {
launchModalForm(
"{% url 'stock-item-edit' item.id %}",

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.shortcuts import get_object_or_404
from django.views.generic import DetailView, ListView
from django.forms.models import model_to_dict
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
@ -126,7 +127,20 @@ class StockItemCreate(AjaxCreateView):
ajax_form_title = 'Create new Stock Item'
def get_initial(self):
initials = super(StockItemCreate, self).get_initial().copy()
# Is the client attempting to copy an existing stock item?
item_to_copy = self.request.GET.get('copy', None)
if item_to_copy:
try:
original = StockItem.objects.get(pk=item_to_copy)
initials = model_to_dict(original)
self.ajax_form_title = "Copy Stock Item"
except StockItem.DoesNotExist:
initials = super(StockItemCreate, self).get_initial().copy()
else:
initials = super(StockItemCreate, self).get_initial().copy()
part_id = self.request.GET.get('part', None)
loc_id = self.request.GET.get('location', None)