How to detect in Quotes if there are unsaved Quoted Line items (and possibly force save them)?

In Quotes I had this all working perfectly for Sugar 7 but I'm having trouble in Sugar 12 with the new Sidecar Quotes module.  

I have a custom Quotes header button next to "Edit" that says "Send to ERP" which takes all the quote data and line items and makes an API call to the ERP to insert as a sales order.  In Sugar 7 this was very easy cause I would only display the "Send to ERP" button on the detail view which inherently meant that all QLI's were saved with their QTY, Sale price etc.  

The problem I'm facing in Sugar 12 is how to detect if a QLI has not yet been saved and either FORCE a save programmatically through javascript on all unsaved line items (thats my preference) or produce an Alert that there are unsaved changes similar to when you try to navigate away from a page without saving.  

Example 1:

User created a quote and fills out all header info and hits SAVE.  When a record is NOT in edit mode, the "Send to ERP" button is visible.  User adds a QLI to the quote which has a QTY of 5.  User realizes they made a mistake and hits "EDIT" on the QLI and updates the QTY to 10.  They then forget to save the Line item and hit "Send to ERP" which reads the DB and sends a QTY of 5 to the ERP but the user actually had updated it to 10.

Example 2:

Forget about my custom button and look at Sugar STOCK quotes.  Same issue arises in another area.  Create a quote, add a QLI to it.  Click EDIT on one of the QLI's and change something about it like the QTY.  Then WITHOUT saving the edited QLI, download the quote template as PDF.  The PDF will spit out the previous QTY and not the recently edited but yet unsaved QLI.  

I have to dummy proof the daylights out of this.  My sales reps will constantly forget to save line items and send the wrong values to the ERP and wrong values on Quotes via PDF.  Would love to hear any and all ideas on this.  Thanks!

Parents
  • Ok so I made I mistake and broke a cardinal rule.  I overrode the wrong JS controller which does handle for SOME of what I'm looking to do. 

    extendsFrom: 'RecordView',  //  Woooooooppppsss
    
    extendsFrom: 'QuotesRecordView',  //  This is what I needed

    I went digging through /modules/Quotes/clients/base/views/record/record.js and a nifty little function jumped out at me.  

        saveClicked: function() {
            //if we don't have any qlis in edit mode, save.  If we do, show a warning.
            if (this.editCount == 0) {
                this._super('saveClicked');
            } else {
                app.alert.show('quotes_qli_editmode', {
                    level: 'error',
                    title: '',
                    messages: [app.lang.get('LBL_SAVE_LINE_ITEMS', 'Quotes')]
                });
            }
    
        },

    So my solution is actually pretty easy.  I just need to add an event listener for a click on my custom button and then hijack this function.  Sadly and surprisingly, Sugar does not call this function on PDF template rowactions and lets you send inaccurate templates with unsaved QLI's so I'll have to add this hijack to detect rowaction clicks on those as well.  

    I'll probably submit this as a bug for the PDF section.  Surprised Sugar lets you download/email PDF's with unsaved line items >.<

    Basic code example here:

     extendsFrom: 'QuotesRecordView',
     
      initialize: function (options) {
            this._super('initialize', [options]);
    		
            //add listener for custom button
            this.context.on('button:send_to_ssi:click', this.send_to_ssi, this);
    		
        },
        
    
        send_to_ssi: function() 
    	{
    		//if we don't have any qlis in edit mode, Process Send to SSI ERP.  If we do, show a warning.
            if (this.editCount == 0) 
            {
    	        // Do my funky ERP stuff here
    		}
    		else {
                app.alert.show('quotes_qli_editmode', {
                    level: 'error',
                    title: '',
                    messages: "There are unsaved Line Items on this Quote.  Please click the Blue 'Save' check mark next to any Line items which have not been saved before attempting to submit as Order to SSI ERP"
                });
            }
    		
        },
     

Reply
  • Ok so I made I mistake and broke a cardinal rule.  I overrode the wrong JS controller which does handle for SOME of what I'm looking to do. 

    extendsFrom: 'RecordView',  //  Woooooooppppsss
    
    extendsFrom: 'QuotesRecordView',  //  This is what I needed

    I went digging through /modules/Quotes/clients/base/views/record/record.js and a nifty little function jumped out at me.  

        saveClicked: function() {
            //if we don't have any qlis in edit mode, save.  If we do, show a warning.
            if (this.editCount == 0) {
                this._super('saveClicked');
            } else {
                app.alert.show('quotes_qli_editmode', {
                    level: 'error',
                    title: '',
                    messages: [app.lang.get('LBL_SAVE_LINE_ITEMS', 'Quotes')]
                });
            }
    
        },

    So my solution is actually pretty easy.  I just need to add an event listener for a click on my custom button and then hijack this function.  Sadly and surprisingly, Sugar does not call this function on PDF template rowactions and lets you send inaccurate templates with unsaved QLI's so I'll have to add this hijack to detect rowaction clicks on those as well.  

    I'll probably submit this as a bug for the PDF section.  Surprised Sugar lets you download/email PDF's with unsaved line items >.<

    Basic code example here:

     extendsFrom: 'QuotesRecordView',
     
      initialize: function (options) {
            this._super('initialize', [options]);
    		
            //add listener for custom button
            this.context.on('button:send_to_ssi:click', this.send_to_ssi, this);
    		
        },
        
    
        send_to_ssi: function() 
    	{
    		//if we don't have any qlis in edit mode, Process Send to SSI ERP.  If we do, show a warning.
            if (this.editCount == 0) 
            {
    	        // Do my funky ERP stuff here
    		}
    		else {
                app.alert.show('quotes_qli_editmode', {
                    level: 'error',
                    title: '',
                    messages: "There are unsaved Line Items on this Quote.  Please click the Blue 'Save' check mark next to any Line items which have not been saved before attempting to submit as Order to SSI ERP"
                });
            }
    		
        },
     

Children
No Data