Invoices Do Not Include the Request for a Return Button

In Reference My Account v1.06, invoices do not include the Request for a Return button. As a result, a customer cannot request to return items on an invoice in NetSuite. However, this button does appear on invoices for Reference My Account Premium v1.06.

To add this button, this patch overrides invoice_details.tpl, Invoice.Router.js, and Invoice.Details.View.js in the Invoice module. You can download the code samples described in this procedure here: RequestForAReturnButtonOnInvoices.zip

Note:

In general, NetSuite best practice is to extend JavaScript using the JavaScript prototype object. This improves the chances that your customizations continue to work when migrating to a newer version of SuiteCommerce Advanced. However, this patch requires you to modify files that you cannot extend, and therefore requires you to use a custom module to override the existing module file. For more information, see Develop Your SCA Customization.

Step 1. Override the JavaScript and Template Files

  1. If you have not done so already, create a directory to store your custom module.

    Give this directory a name similar to the module being customized. For example, create Modules/extensions/Invoice.Extension@1.0.0

  2. In your new Invoice.Extension@1.0.0 directory, create subdirectories called JavaScript and Templates.

    For example: Modules/extensions/Invoice.Extension@1.0.0/JavaScript and Modules/extensions/Invoice.Extension@1.0.0/Templates.

  3. Copy the following files:

    In this example, X.Y.Z represents the version of the module in your implementation of SuiteCommerce Advanced.

  4. Paste a copy in your new module’s JavaScript and Templates directories.

    For example: Modules/extensions/Invoice.Extension@1.0.0/JavaScript/Invoice.Router.js or Modules/extensions/Invoice.Extension@1.0.0/Templates/invoice_details.tpl

  5. Open your new copy of Invoice.Router.js and locate the showInvoice() method.

    Replace the existing showInvoice() method with the following code:

                    showInvoice: function (invoice_id, referer) 
    { 
    var invoice = new InvoiceModel({internalid: invoice_id}) 
      , view = new DetailsView({ 
        application: this.application 
      , model: invoice 
      , referer: referer 
    });  
      invoice
        .fetch({ 
          killerId: AjaxRequestsKiller.getKillerId() 
        }) 
        .done(function() { 
          view.isReturnable() 
            .done(function() { 
              view.showContent(); 
            }) 
        }); 
    } 
    
                  
  6. Save the file.

  7. Open your new copy of Invoice.Details.View.js and make the following changes.

    1. Find the following line:

                          , 'underscore' 
      
                        

      Replace this line with the following code:

                          , 'underscore' 
      , 'ReturnAuthorization.GetReturnableLines' 
      , 'OrderHistory.Model' 
      , 'AjaxRequestsKiller' 
      , 'jQuery' 
      
                        
    2. Find the following line:

                          , _ 
      
                        

      Replace this line with the following code:

                          , _ 
      , ReturnLinesCalculator 
      , OrderHistoryModel 
      , AjaxRequestsKiller 
      , JQuery 
      
                        
    3. Find the following lines:

                          , makeAPayment: function () 
        { 
          LivePaymentModel.getInstance().selectInvoice(this.model.id); 
        } 
      
                        

      Replace these lines with the following code:

                          , makeAPayment: function () 
        { 
          LivePaymentModel.getInstance().selectInvoice(this.model.id); 
        }
      
        , makeAPayment: function () 
        { 
          LivePaymentModel.getInstance().selectInvoice(this.model.id); 
        } 
        //@method isReturnable calculates a value based on the fulfillments and returns made, 
        // if the invoice accepts returns 
      , isReturnable: function () 
        { 
          var deferred = JQuery.Deferred();
      
          var self = this; 
          var model = new OrderHistoryModel(); 
          model 
            .fetch({ 
              data: { 
                internalid: this.model.get('createdfrom').internalid 
                , recordtype: this.model.get('createdfrom').recordtype 
              } 
                , killerId: AjaxRequestsKiller.getKillerId() 
            }) 
            .done(function() { 
              var ret_calculator = new ReturnLinesCalculator(model, {notConsiderFulfillments: true}); 
              self.validLines = ret_calculator.calculateLines().validLines.length; 
              deferred.resolve(); 
            }); 
          
          return deferred.promise(); 
        } 
      
                        
    4. Find the following line:

                          , showOpenedAccordion: _.isTabletDevice() || _.isDesktopDevice() 
      
                        

      Replace this line with the following code:

                            , showOpenedAccordion: _.isTabletDevice() || _.isDesktopDevice() 
          //@property {Boolean} showRequestReturnButton 
        , showRequestReturnButton: !!this.validLines 
      
                        
    5. Find the following line inside the initialize() function:

                          this.navSource = options.referer === 'paidinvoices' ? '/paid-invoices' : '/invoices'; 
      
                        

      Replace this line with the following code:

                            this.navSource = options.referer === 'paidinvoices' ? '/paid-invoices' : '/invoices'; 
        this.model = options.model; 
        this.validLines = 0; 
      
                        
  8. Save the file.

  9. Open your new copy of invoice_details.tpl and make the following change.

    Find the following lines:

                      <a target="_blank" class="invoice-details-button-download-as-pdf" href="{{donwloadPdfUrl}}">
        {{translate 'Download as PDF'}}
      </a> 
    
                  

    Replace these lines with the following code:

                      <a target="_blank" class="invoice-details-button-download-as-pdf" href="{{donwloadPdfUrl}}">
        {{translate 'Download as PDF'}}
      </a>
    
      {{#if showRequestReturnButton}} 
    
      <a href="/returns/new/invoice/{{‌model.internalid}}" class="invoice-details-button-request" data-permissions="transactions.tranRtnAuth.2">
        {{translate 'Request a Return'}}
      </a> 
    
      {{/if}} 
    
                  
  10. Save the file.

Step 2: Prepare the Developer Tools For Your Customization

  1. Open your Modules/extensions/ module directory.

  2. Create a file in this directory and name it ns.package.json.

    Modules/extensions/Invoice.Extension@1.0.0/ns.package.json

  3. Build the ns.package.json file using the following code:

                      {
        "gulp": {
          "javascript": [
            "JavaScript/*.js"
          ]
        },
        "overrides": {
          "suitecommerce/Invoice@X.Y.Z/Javascript/Invoice.Router.js" : "JavaScript/Invoice.Router.js",
          "suitecommerce/Invoice@X.Y.Z/Javascript/Invoice.Details.View.js" : "JavaScript/Invoice.Details.View.js",
          "suitecommerce/Invoice@X.Y.Z/Templates/invoice_details.tpl" : "Templates/invoice_details.tpl"
        }
      } 
    
                  
    Important:

    You must replace the string X.Y.Z with the version of the module in your implementation of SuiteCommerce Advanced.

  4. Open the distro.json file. This is located in your root directory.

  5. Add your custom modules to the modules object.

    Your code should look similar to the following example:

                    {
        "name": "SuiteCommerce Advanced Vinson Release",
        "version": "2.0",
        "buildToolsVersion": "1.2.1",
        "folders": {
            "modules": "Modules",
            "suitecommerceModules": "Modules/suitecommerce",
            "thirdPartyModules": "Modules/third_parties",
            "distribution": "LocalDistribution",
            "deploy": "DeployDistribution"
        },
        "modules": {
            "extensions/Invoice.Extension": "1.0.0",
            "suitecommerce/Account": "2.2.0",            ... 
    
                  

    This ensures that the Gulp tasks include your module when you deploy. In this example, the custom modules are added at the beginning of the list of modules. However, you can add the modules anywhere in the modules object. The order of precedence in this list does not matter.

  6. Save the distro.json file.

Step 3: Test and Deploy Your Customization

  1. Test your source code customizations on a local server (see Test SCA Customizations on a Local Server) or deploy them to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.

  2. Confirm your results.

    Upon successful deployment, Invoice records under My Account contain a Request a Return button .

Related Topics

SCA Patches

General Notices