Inventory - Save with more than 200 Items takes a long time to save (200sec).
In this case I am using VT 6.4. In VT7.2 more than 65 items will be deleted without comment! I coud not test my case.
I have a quote with more than 200 items. When I save the quote it takes more than 200 seconds. The reason why is the trigger at line 'jQuery('.closeDiv').trigger('click');' ca. 1150 in modules/Inventory/resources/edit.js
registerLineItemActionSaveEvent : function(){
var editForm = this.getForm();
editForm.on('click','button[name="lineItemActionSave"]',function(e){ <<-- CHANGED
var match = true;
var formError = jQuery('#EditView').data('jqv').InvalidFields;
var closestDiv = jQuery('button[name="lineItemActionSave"]').closest('.validCheck').find('input[data-validation-engine]').not('.hide');
jQuery(closestDiv).each(function(key,value){
if(jQuery.inArray(value,formError) != -1){
match = false;
}
});
if(!match){
editForm.removeData('submit');
return false;
} else {
jQuery('.closeDiv').trigger('click'); // <<-- PROBLEM / DELETE
jQuery(e.target).closest('.validCheck').find('.closeDiv').trigger('click'); //<<-- NEW
}
});
},
jQuery('.closeDiv').trigger('click') triggers -->lineItemActionSave . The function will be run as much as ".closeDiv" are available. And these are a lot.
My solution, I dont know if it is the best, but it works. Change Line jQuery('.closeDiv').trigger('click'); in function registerLineItemActionSaveEvent and add the Line in function registerSubmitEvent.
registerSubmitEvent : function () {
var thisInstance = this;
var editViewForm = this.getForm();
this._super();
editViewForm.submit(function(e){
var deletedItemInfo = jQuery('.deletedItem',editViewForm);
if(deletedItemInfo.length > 0){
e.preventDefault();
var msg = app.vtranslate('JS_PLEASE_REMOVE_LINE_ITEM_THAT_IS_DELETED');
var params = {
text : msg,
type: 'error'
}
Vtiger_Helper_Js.showPnotify(params);
editViewForm.removeData('submit');
return false;
}
thisInstance.updateLineItemElementByOrder();
var lineItemTable = thisInstance.getLineItemContentsContainer();
jQuery('.closeDiv').trigger('click'); // <<--- NEW
jQuery('.discountSave',lineItemTable).trigger('click');
thisInstance.lineItemToTalResultCalculations();
thisInstance.saveProductCount();
thisInstance.saveSubTotalValue();
thisInstance.saveTotalValue();
thisInstance.savePreTaxTotalValue();
})
},
There is a wrong target to check if discount container is visible. The result is, that lineItemDiscountChangeActions() is called to often.
/**
* Function which will register event for focusout of discount input fields like percentage and amount
*/
registerDisountValueChange : function() {
var thisInstance = this;
var lineItemTable = this.getLineItemContentsContainer();
lineItemTable.on('click','.discountSave', function(e){
var parentElem = jQuery(e.currentTarget).closest('.discountUI'); // <<-- NEW
//if the element is not hidden then we need to handle the focus out
if(!app.isHidden(parentElem) || !parentElem.hasClass('hide') ){ // <<-- CHANGED
var lineItemRow = jQuery(e.currentTarget).closest('tr.'+thisInstance.rowClass);
thisInstance.lineItemDiscountChangeActions(lineItemRow);
}
});
},
Other code changes, to make the code faster:
lineItemResultActions: function(){
var thisInstance = this;
var lineItemResultTab = this.getLineItemResultContainer();
this.registerFinalDiscountShowEvent();
this.registerFinalDiscountValueChangeEvent();
this.registerFinalDiscountChangeEvent();
this.registerLineItemActionSaveEvent();
this.registerLineItemsPopUpCancelClickEvent();
this.registerGroupTaxShowEvent();
this.registerGroupTaxChangeEvent();
this.registerShippingAndHandlingChargesChange();
this.registerShippingAndHandlingTaxShowEvent();
this.registerAdjustmentTypeChange();
this.registerAdjustmentValueChange();
lineItemResultTab.on('click','.closeDiv',function(e){
if( !jQuery(e.target).closest('div').hasClass('hide')) // <<-- NEW
jQuery(e.target).closest('div').addClass('hide');
});
},
lineItemActions: function() {
var lineItemTable = this.getLineItemContentsContainer();
this.registerDisountChangeEvent();
this.registerDisountValueChange();
this.registerLineItemDiscountShowEvent();
this.registerLineItemAutoComplete();
this.registerClearLineItemSelection();
this.registerProductAndServicePopup();
this.registerPriceBookPopUp();
this.registerQuantityChangeEventHandler();
this.registerListPriceChangeEvent();
this.registerTaxPercentageChange();
this.registerLineItemTaxShowEvent();
this.registerDeleteLineItemEvent();
this.registerTaxTypeChange();
this.registerCurrencyChangeEvent();
lineItemTable.on('click','.closeDiv',function(e){
if( !jQuery(e.target).closest('div').hasClass('hide')) // <<-- NEW
jQuery(e.currentTarget).closest('div').addClass('hide');
});
lineItemTable.on('click','.clearComment',function(e){
var elem = jQuery(e.currentTarget);
var parentElem = elem.closest('div');
var comment = jQuery('.lineItemCommentBox',parentElem).val('');
});
},