New quotes modules How to update the current QLI based on field change?

Hi All,

We are moving old quote customisation to new quotes module in 7.9.4.

When quantity is changed, we need to update a custom filed for that specific QLI.

How/where to update the specific QLI only, based on the field change?

Any body has any idea how we can achieve that.

Regards,

Usman

Parents
  • I make some field dependent changes in:

    <mysugar>/custom/modules/Products/clients/base/fields/quote-data-relate/quote-data-relate.js

     

    ({
      extendsFrom:'ProductsQuoteDataRelateField',
      initialize: function(options){
        this._super('initialize', [options]);
        this.model.on('change:mft_part_num', this.triggerERPLookup,this); //takes care of user-added/modified lines
      },
      triggerERPLookup: function(){
        //my ERP price lookup updates discount_price when the mft_part_num changes
      },
    })

    Maybe this will work for you too.

    FrancescaS

  • hey Francesca Shiekh,

    really appreciate your generously sharing your knowledge. This is exactly what make the community helpful.

    as you know by default, when quantity / product template / unit price /  discount those fields change, there is already some event triggered to render the page. my question is, do you know what and where is that event ? and how to extend that event to add some custom handling? If i add 

    this.model.on('change:mft_part_num', this.triggerERPLookup,this);

    for each fields, would it override the default event?  I have also found another related article: How/where to detect this change event for product change in new quote module 7.9.4  which seems have totally different solution. however, i could not get it. what do you think about that?

    our user case is, when a product template get picked/changed, we would like to call custom API to calculate the UNIT price and send back to UI. Could you please give any advise? 

    looking forward to hear back from you.

    cheers,

    Rob

  • Hi Rob, 

    It's been a while since I looked at my Quotes code but in my instance I use an ERPLookup API to to look up the unit price on a different system when the mft_part_num changes (which is when the product is selected) and set it as the discount_price (aka unit price) on the Quote Line item.

    The core is what I described above but  let me see if I can explain my process:

    in 

    custom/clients/base/api/ERPLookupApi.php

    I have a custom API that gets the Price from our ERP based on mft_part_num (which is stored in the Sugar product catalog)

    in 

    custom/modules/Products/clients/base/fields/quote-data-relate/quote-data-relate.js

    I look up the ERP price when the mft_part_num changes (notice that the mft_part_num is retrieved when the product changes on the Quoted Line Item)

    ({
      extendsFrom:'ProductsQuoteDataRelateField',
      initialize: function(options){
        this._super('initialize', [options]);
        this.model.on('change:mft_part_num', this.triggerERPLookup,this); //takes care of user-added/modified lines
      },
      triggerERPLookup: function(){
        var attr = this.model.attributes,
              part_num = attr.mft_part_num;
        //use the part_num in the API call
       //use an alert to let the user know it case it takes a little time to get the price back
        app.alert.show('erp_price', {
          level: 'process',
          title: 'Looking up Price in ERP...'
        });
        var self = this,
            price_url = app.api.buildURL('ERPGetPrice/'+part_num);
        app.api.call('GET', price_url, null, {
          success: function (price){
            self.model.set('discount_price', price);
            app.alert.dismiss('erp_price'); //dismiss the alert
          },
          error: function(e){
            app.alert.dismiss('erp_price');
            console.log(e);
          },
        });
      },

    I also have an override for the discount_price readonly dependency in

    custom/modules/Products/metadata/dependencydefs.php

    note that in the original the fields array includes list_price and cost_price which I do not care to have as read-only so I removed them. There may be a better way to do this.

    <?php
    //override discount_price readonly dependency
    $dependencies['Products']['read_only_fields'] = array();

    $fields = array(
        'category_name',
        'tax_class',
        'mft_part_num',
        'weight'
    );

    $dependencies['Products']['read_only_fields'] = array(
        'hooks' => array("edit"),
        //Trigger formula for the dependency. Defaults to 'true'.
        'trigger' => 'true',
        'triggerFields' => array('product_template_id'),
        'onload' => true,
        //Actions is a list of actions to fire when the trigger is true
        'actions' => array(),
    );

    foreach ($fields as $field) {
        $dependencies['Products']['read_only_fields']['actions'][] = array(
            'name' => 'ReadOnly', //Action type
            //The parameters passed in depend on the action type
            'params' => array(
                'target' => $field,
                'label' => $field . '_label', //normally <field>_label
                'value' => 'not(equal($product_template_id,""))', //Formula
            ),
        );
    }

    I think that's all the pieces, there is so much more going on in my Quotes and it's been a while since I worked on this so I may have forgotten something, but it should put you on the right track.

    Which fields are copied from the catalog to the Quoted Line Item fields is determined by the populate_list on the product_template_name field.

     

    You will notice that in 

    modules/Products/vardefs.php

    'product_template_name' includes discount_price in the populate_list, this is what takes the price from the catalog and includes it in the quoted line item. Perhaps you could try to remove that for the fields you don't want populated by the Sugar Product Catalog by extending the vardefs. I honestly don't recall why I did not do that.

     

    To add a custom field to that list, use the dictionary Extension, e.g.:

    in custom/Extension/modules/Products/Ext/Vardefs/vardefs.ext.php

    I added a custom catalog field for available platforms:

    $dictionary['Product']['fields']['product_template_name']['populate_list']['platforms_available_c'] 'platforms_available_c';

    where platforms_available_c is a custom field in ProductTemplates

     

     

    HTH

    FrancescaS

  • thank you very much Francesca! you are the best!!!

    i will try it out and let you know how i go.

    many many thanks!

    Ron (Rob was a typo )

Reply Children
No Data