mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 15:15:42 +00:00 
			
		
		
		
	Fix for "new purchase order" button
This commit is contained in:
		@@ -78,7 +78,13 @@ function createPurchaseOrder(options={}) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        onSuccess: function(data) {
 | 
					        onSuccess: function(data) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (options.onSuccess) {
 | 
				
			||||||
 | 
					                options.onSuccess(data);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                // Default action is to redirect browser to the new PO
 | 
				
			||||||
                location.href = `/order/purchase-order/${data.pk}/`;
 | 
					                location.href = `/order/purchase-order/${data.pk}/`;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        title: '{% trans "Create Purchase Order" %}',
 | 
					        title: '{% trans "Create Purchase Order" %}',
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -116,7 +122,7 @@ function newSupplierPartFromOrderWizard(e) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    createSupplierPart({
 | 
					    createSupplierPart({
 | 
				
			||||||
        part: part,
 | 
					        part: part,
 | 
				
			||||||
        onSuccess: function(response) {
 | 
					        onSuccess: function(data) {
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
            // TODO: 2021-08-23 - This whole form wizard needs to be refactored.
 | 
					            // TODO: 2021-08-23 - This whole form wizard needs to be refactored.
 | 
				
			||||||
            // In the future, use the API forms functionality to add the new item
 | 
					            // In the future, use the API forms functionality to add the new item
 | 
				
			||||||
@@ -124,7 +130,7 @@ function newSupplierPartFromOrderWizard(e) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            var dropdown = `#id_supplier_part_${part}`;
 | 
					            var dropdown = `#id_supplier_part_${part}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var pk = response.pk;
 | 
					            var pk = data.pk;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            inventreeGet(
 | 
					            inventreeGet(
 | 
				
			||||||
                `/api/company/part/${pk}/`,
 | 
					                `/api/company/part/${pk}/`,
 | 
				
			||||||
@@ -165,20 +171,40 @@ function newPurchaseOrderFromOrderWizard(e) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    var supplier = $(src).attr('supplierid');
 | 
					    var supplier = $(src).attr('supplierid');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    launchModalForm("/order/purchase-order/new/", {
 | 
					    createPurchaseOrder({
 | 
				
			||||||
        modal: '#modal-form-secondary',
 | 
					 | 
				
			||||||
        data: {
 | 
					 | 
				
			||||||
        supplier: supplier,
 | 
					        supplier: supplier,
 | 
				
			||||||
 | 
					        onSuccess: function(data) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // TODO: 2021-08-23 - The whole form wizard needs to be refactored
 | 
				
			||||||
 | 
					            // In the future, the drop-down should be using a dynamic AJAX request
 | 
				
			||||||
 | 
					            // to fill out the select2 options!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var pk = data.pk;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            inventreeGet(
 | 
				
			||||||
 | 
					                `/api/order/po/${pk}/`,
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    supplier_detail: true,
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
                    success: function(response) {
 | 
					                    success: function(response) {
 | 
				
			||||||
            /* A new purchase order has been created! */
 | 
					                        var text = global_settings.PURCHASEORDER_REFERENCE_PREFIX || '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var dropdown = '#id-purchase-order-' + supplier;
 | 
					                        text += response.reference;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var option = new Option(response.text, response.pk, true, true);
 | 
					                        if (response.supplier_detail) {
 | 
				
			||||||
 | 
					                            text += ` ${response.supplier_detail.name}`;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        var dropdown = `#id-purchase-order-${supplier}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        var option = new Option(text, pk, true, true);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
                        $('#modal-form').find(dropdown).append(option).trigger('change');
 | 
					                        $('#modal-form').find(dropdown).append(option).trigger('change');
 | 
				
			||||||
        },
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }); 
 | 
					    }); 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user