Add button to delete a SalesOrderLineItem

This commit is contained in:
Oliver Walters 2020-04-22 22:36:55 +10:00
parent 26d1a25f31
commit 2a4e903785
6 changed files with 34 additions and 10 deletions

View File

@ -69,5 +69,7 @@ class RoundingDecimalField(models.DecimalField):
defaults = { defaults = {
'form_class': RoundingDecimalFormField 'form_class': RoundingDecimalFormField
} }
defaults.update(kwargs) defaults.update(kwargs)
return super(RoundingDecimalField, self).formfield(**kwargs)
return super().formfield(**kwargs)

View File

@ -463,9 +463,10 @@ class SalesOrderAllocation(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='sales_order_allocations', related_name='sales_order_allocations',
limit_choices_to={'part__salable': True}, limit_choices_to={'part__salable': True},
help_text=_('Select stock item to allocate')
) )
quantity = RoundingDecimalField(max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], default=1) quantity = RoundingDecimalField(max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], default=1, help_text=_('Enter stock allocation quantity'))
def get_allocated(self): def get_allocated(self):
""" String representation of the allocated quantity """ """ String representation of the allocated quantity """

View File

@ -156,6 +156,8 @@ $("#so-lines-table").inventreeTable({
} }
html += makeIconButton('fa-edit', 'button-edit', pk, '{% trans "Edit line item" %}'); html += makeIconButton('fa-edit', 'button-edit', pk, '{% trans "Edit line item" %}');
html += makeIconButton('fa-trash-alt', 'button-delete', pk, '{% trans "Delete line item " %}');
html += `</div>`; html += `</div>`;
return html; return html;
@ -181,12 +183,17 @@ $("#so-lines-table").on('load-success.bs.table', function() {
launchModalForm(`/order/sales-order/line/${pk}/edit/`, { launchModalForm(`/order/sales-order/line/${pk}/edit/`, {
success: reloadTable, success: reloadTable,
}); });
console.log("clicked!"); });
table.find(".button-delete").click(function() {
var pk = $(this).attr('pk');
launchModalForm(`/order/sales-order/line/${pk}/delete/`, {
reload: true,
});
}); });
table.find(".button-add").click(function() { table.find(".button-add").click(function() {
console.log("add");
var pk = $(this).attr('pk'); var pk = $(this).attr('pk');
launchModalForm(`/order/sales-order/allocation/new/`, { launchModalForm(`/order/sales-order/allocation/new/`, {
@ -199,13 +206,9 @@ $("#so-lines-table").on('load-success.bs.table', function() {
}); });
table.find(".button-build").click(function() { table.find(".button-build").click(function() {
console.log("build");
var pk = $(this).attr('pk');
}); });
table.find(".button-buy").click(function() { table.find(".button-buy").click(function() {
console.log("buy");
}); });
}); });

View File

@ -0,0 +1,5 @@
{% extends "modal_delete_form.html" %}
{% block pre_form_content %}
Are you sure you wish to delete this line item?
{% endblock %}

View File

@ -65,7 +65,8 @@ purchase_order_urls = [
so_line_urls = [ so_line_urls = [
url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'), url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'),
url(r'^(?P<pk>\d+)/', include([ url(r'^(?P<pk>\d+)/', include([
url(r'^edit/', views.SOLineItemEdit.as_view(), name='so-line-item-edit') url(r'^edit/', views.SOLineItemEdit.as_view(), name='so-line-item-edit'),
url(r'^delete/', views.SOLineItemDelete.as_view(), name='so-line-item-delete'),
])), ])),
] ]

View File

@ -1163,6 +1163,18 @@ class POLineItemDelete(AjaxDeleteView):
} }
class SOLineItemDelete(AjaxDeleteView):
model = SalesOrderLineItem
ajax_form_title = _("Delete Line Item")
ajax_template_name = "order/so_lineitem_delete.html"
def get_data(self):
return {
'danger': _('Deleted line item'),
}
class SalesOrderAllocationCreate(AjaxCreateView): class SalesOrderAllocationCreate(AjaxCreateView):
""" View for creating a new SalesOrderAllocation """ """ View for creating a new SalesOrderAllocation """