2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 19:15:41 +00:00

Merge remote-tracking branch 'inventree/master' into delete-old-forms

# Conflicts:
#	InvenTree/part/views.py
This commit is contained in:
Oliver Walters
2019-04-18 23:51:58 +10:00
6 changed files with 77 additions and 5 deletions

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
@ -122,7 +123,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)