quantity also for modal

This commit is contained in:
Matthias 2021-05-05 20:55:37 +02:00
parent dc4fb64987
commit b392586a08
2 changed files with 18 additions and 3 deletions

View File

@ -400,6 +400,8 @@ function setupCallbacks() {
$(".button-price").click(function() { $(".button-price").click(function() {
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
var idx = $(this).closest('tr').attr('data-index');
var row = table.bootstrapTable('getData')[idx];
launchModalForm( launchModalForm(
"{% url 'line-pricing' %}", "{% url 'line-pricing' %}",
@ -407,6 +409,7 @@ function setupCallbacks() {
submit_text: '{% trans "Calculate price" %}', submit_text: '{% trans "Calculate price" %}',
data: { data: {
line_item: pk, line_item: pk,
quantity: row.quantity,
}, },
} }
); );

View File

@ -1960,7 +1960,18 @@ class PartPricing(AjaxView):
def get_quantity(self): def get_quantity(self):
""" Return set quantity in decimal format """ """ Return set quantity in decimal format """
return Decimal(self.request.POST.get('quantity', 1)) # check POST
qty = self.request.POST.get('quantity', None)
# check GET
if not qty:
qty = self.request.GET.get('quantity', None)
# nothing found: return 1
if not qty:
return Decimal(1)
# return as decimal
return Decimal(qty)
def get_part(self): def get_part(self):
try: try:
@ -2048,7 +2059,8 @@ class PartPricing(AjaxView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return self.renderJsonResponse(request, self.form_class(), context=self.get_pricing()) quantity = self.get_quantity()
return self.renderJsonResponse(request, self.form_class(initial={'quantity': quantity}), context=self.get_pricing(quantity))
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):