mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor PurchaseOrderIssue form
This commit is contained in:
parent
5afc3bfce2
commit
bf48e3204b
@ -326,6 +326,17 @@ class PurchaseOrderComplete(PurchaseOrderContextMixin, generics.CreateAPIView):
|
|||||||
serializer_class = serializers.PurchaseOrderCompleteSerializer
|
serializer_class = serializers.PurchaseOrderCompleteSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseOrderIssue(PurchaseOrderContextMixin, generics.CreateAPIView):
|
||||||
|
"""
|
||||||
|
API endpoint to 'complete' a purchase order
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = models.PurchaseOrder.objects.all()
|
||||||
|
|
||||||
|
serializer_class = serializers.PurchaseOrderIssueSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderReceive(PurchaseOrderContextMixin, generics.CreateAPIView):
|
class PurchaseOrderReceive(PurchaseOrderContextMixin, generics.CreateAPIView):
|
||||||
"""
|
"""
|
||||||
API endpoint to receive stock items against a purchase order.
|
API endpoint to receive stock items against a purchase order.
|
||||||
@ -1132,6 +1143,7 @@ order_api_urls = [
|
|||||||
|
|
||||||
# Individual purchase order detail URLs
|
# Individual purchase order detail URLs
|
||||||
re_path(r'^(?P<pk>\d+)/', include([
|
re_path(r'^(?P<pk>\d+)/', include([
|
||||||
|
re_path(r'^issue/', PurchaseOrderIssue.as_view(), name='api-po-issue'),
|
||||||
re_path(r'^receive/', PurchaseOrderReceive.as_view(), name='api-po-receive'),
|
re_path(r'^receive/', PurchaseOrderReceive.as_view(), name='api-po-receive'),
|
||||||
re_path(r'^cancel/', PurchaseOrderCancel.as_view(), name='api-po-cancel'),
|
re_path(r'^cancel/', PurchaseOrderCancel.as_view(), name='api-po-cancel'),
|
||||||
re_path(r'^complete/', PurchaseOrderComplete.as_view(), name='api-po-complete'),
|
re_path(r'^complete/', PurchaseOrderComplete.as_view(), name='api-po-complete'),
|
||||||
|
@ -19,16 +19,6 @@ from .models import PurchaseOrder
|
|||||||
from .models import SalesOrder
|
from .models import SalesOrder
|
||||||
|
|
||||||
|
|
||||||
class IssuePurchaseOrderForm(HelperForm):
|
|
||||||
|
|
||||||
confirm = forms.BooleanField(required=True, initial=False, label=_('Confirm'), help_text=_('Place order'))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PurchaseOrder
|
|
||||||
fields = [
|
|
||||||
'confirm',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CancelSalesOrderForm(HelperForm):
|
class CancelSalesOrderForm(HelperForm):
|
||||||
|
|
||||||
|
@ -230,8 +230,20 @@ class PurchaseOrderCompleteSerializer(serializers.Serializer):
|
|||||||
def save(self):
|
def save(self):
|
||||||
|
|
||||||
order = self.context['order']
|
order = self.context['order']
|
||||||
|
order.complete_order()
|
||||||
|
|
||||||
|
|
||||||
|
class PurchaseOrderIssueSerializer(serializers.Serializer):
|
||||||
|
""" Serializer for issuing (sending) a purchase order """
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
fields = []
|
||||||
|
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
|
||||||
|
order = self.context['order']
|
||||||
|
order.place_order()
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderLineItemSerializer(InvenTreeModelSerializer):
|
class PurchaseOrderLineItemSerializer(InvenTreeModelSerializer):
|
||||||
|
@ -186,10 +186,14 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
|
|
||||||
{% if order.status == PurchaseOrderStatus.PENDING %}
|
{% if order.status == PurchaseOrderStatus.PENDING %}
|
||||||
$("#place-order").click(function() {
|
$("#place-order").click(function() {
|
||||||
launchModalForm("{% url 'po-issue' order.id %}",
|
|
||||||
{
|
issuePurchaseOrder(
|
||||||
reload: true,
|
{{ order.pk }},
|
||||||
});
|
{
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
{% extends "modal_form.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block pre_form_content %}
|
|
||||||
|
|
||||||
<div class='alert alert-warning alert-block'>
|
|
||||||
{% trans 'After placing this purchase order, line items will no longer be editable.' %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
@ -11,7 +11,6 @@ from . import views
|
|||||||
|
|
||||||
purchase_order_detail_urls = [
|
purchase_order_detail_urls = [
|
||||||
|
|
||||||
re_path(r'^issue/', views.PurchaseOrderIssue.as_view(), name='po-issue'),
|
|
||||||
re_path(r'^upload/', views.PurchaseOrderUpload.as_view(), name='po-upload'),
|
re_path(r'^upload/', views.PurchaseOrderUpload.as_view(), name='po-upload'),
|
||||||
re_path(r'^export/', views.PurchaseOrderExport.as_view(), name='po-export'),
|
re_path(r'^export/', views.PurchaseOrderExport.as_view(), name='po-export'),
|
||||||
|
|
||||||
|
@ -113,33 +113,6 @@ class SalesOrderCancel(AjaxUpdateView):
|
|||||||
order.cancel_order()
|
order.cancel_order()
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderIssue(AjaxUpdateView):
|
|
||||||
""" View for changing a purchase order from 'PENDING' to 'ISSUED' """
|
|
||||||
|
|
||||||
model = PurchaseOrder
|
|
||||||
ajax_form_title = _('Issue Order')
|
|
||||||
ajax_template_name = "order/order_issue.html"
|
|
||||||
form_class = order_forms.IssuePurchaseOrderForm
|
|
||||||
|
|
||||||
def validate(self, order, form, **kwargs):
|
|
||||||
|
|
||||||
confirm = str2bool(self.request.POST.get('confirm', False))
|
|
||||||
|
|
||||||
if not confirm:
|
|
||||||
form.add_error('confirm', _('Confirm order placement'))
|
|
||||||
|
|
||||||
def save(self, order, form, **kwargs):
|
|
||||||
"""
|
|
||||||
Once the form has been validated, place the order.
|
|
||||||
"""
|
|
||||||
order.place_order()
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
return {
|
|
||||||
'success': _('Purchase order issued')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderUpload(FileManagementFormView):
|
class PurchaseOrderUpload(FileManagementFormView):
|
||||||
''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) '''
|
''' PurchaseOrder: Upload file, match to fields and parts (using multi-Step form) '''
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
createSalesOrderShipment,
|
createSalesOrderShipment,
|
||||||
editPurchaseOrderLineItem,
|
editPurchaseOrderLineItem,
|
||||||
exportOrder,
|
exportOrder,
|
||||||
|
issurPurchaseOrder,
|
||||||
loadPurchaseOrderLineItemTable,
|
loadPurchaseOrderLineItemTable,
|
||||||
loadPurchaseOrderExtraLineTable
|
loadPurchaseOrderExtraLineTable
|
||||||
loadPurchaseOrderTable,
|
loadPurchaseOrderTable,
|
||||||
@ -142,7 +143,9 @@ function completeShipment(shipment_id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Launches a modal form to mark a PurchaseOrder as "complete"
|
||||||
|
*/
|
||||||
function completePurchaseOrder(order_id, options={}) {
|
function completePurchaseOrder(order_id, options={}) {
|
||||||
|
|
||||||
constructForm(
|
constructForm(
|
||||||
@ -174,39 +177,75 @@ function completePurchaseOrder(order_id, options={}) {
|
|||||||
return html;
|
return html;
|
||||||
},
|
},
|
||||||
onSuccess: function(response) {
|
onSuccess: function(response) {
|
||||||
if (options.onSuccess) {
|
handleFormSuccess(response, options);
|
||||||
options.onSuccess(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Launches a modal form to mark a PurchaseOrder as 'cancelled'
|
||||||
|
*/
|
||||||
function cancelPurchaseOrder(order_id, options={}) {
|
function cancelPurchaseOrder(order_id, options={}) {
|
||||||
|
|
||||||
var html = `
|
|
||||||
<div class='alert alert-info alert-block'>
|
|
||||||
{% trans "Are you sure you wish to cancel this purchase order?" %}
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
constructForm(
|
constructForm(
|
||||||
`/api/order/po/${order_id}/cancel/`,
|
`/api/order/po/${order_id}/cancel/`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
title: '{% trans "Cancel Purchase Order" %}',
|
title: '{% trans "Cancel Purchase Order" %}',
|
||||||
confirm: true,
|
confirm: true,
|
||||||
preFormContent: html,
|
preFormContent: function(opts) {
|
||||||
onSuccess: function(response) {
|
var html = `
|
||||||
if (options.onSuccess) {
|
<div class='alert alert-info alert-block'>
|
||||||
options.onSuccess(response);
|
{% trans "Are you sure you wish to cancel this purchase order?" %}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
if (!opts.context.can_cancel) {
|
||||||
|
html += `
|
||||||
|
<div class='alert alert-danger alert-block'>
|
||||||
|
{% trans "This purchase order can not be cancelled" %}
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
onSuccess: function(response) {
|
||||||
|
handleFormSuccess(response, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Launches a modal form to mark a PurchaseOrder as "issued"
|
||||||
|
*/
|
||||||
|
function issuePurchaseOrder(order_id, options={}) {
|
||||||
|
|
||||||
|
constructForm(
|
||||||
|
`/api/order/po/${order_id}/issue/`,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
title: '{% trans "Issue Purchase Order" %}',
|
||||||
|
confirm: true,
|
||||||
|
preFormContent: function(opts) {
|
||||||
|
var html = `
|
||||||
|
<div class='alert alert-block alert-warning'>
|
||||||
|
{% trans 'After placing this purchase order, line items will no longer be editable.' %}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
return html;
|
||||||
|
},
|
||||||
|
onSuccess: function(response) {
|
||||||
|
handleFormSuccess(response, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Open a dialog to create a new sales order shipment
|
// Open a dialog to create a new sales order shipment
|
||||||
function createSalesOrderShipment(options={}) {
|
function createSalesOrderShipment(options={}) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user