Copy quote make fields editable / update calculated fields

Hi,

for a customer who uses the quotes module a lot we want to be able to copy an existing quote and update the products on the copy with new data from the producttemplate ( they change prices etc on the producttemplate, they don't create new templates..). I got it working so far that when I click the duplicate button the lines are copied and the data is being updated using a ajax request for the various templates. This does work by validating in the create.js if we have a copy context and if so we copy all the data needed from the producttemplates. 

I currently have two issues left: 

- When I copy a quote the productbundle items are copied but the calculated fields are not updated until I save the quote

- Certain fields are readonly. 

Could someone point me into the right direction so I can solve both issues? 

if(options.context.get('copy') === true && !_.isEmpty(options.context.get("relatedRecords"))){
            _.each(options.context.get("relatedRecords"), function(entry){
                if(entry._module  === "ProductBundles"){
                    _.each(entry.product_bundle_items,function(bundleItem){
                        var productTemplateId = bundleItem.get("product_template_id");
                        if(!_.isEmpty(productTemplateId)){

                            var url = app.api.buildURL('ProductTemplates/'+productTemplateId, '', {}, {});
                            app.api.call('read',url,{},{
                                success: _.bind(function(bundleItem,response){
                                    console.log('succesfully retrieved data from template??');
                                    bundleItem.set('name',response.name);
                                    bundleItem.set('category_id',response.category_id);
                                    bundleItem.set('category_name',response.category_name);
                                    bundleItem.set('mft_part_num',response.mft_part_num);
                                    bundleItem.set('list_price',response.list_price);
                                    bundleItem.set('cost_price',response.cost_price);
                                    bundleItem.set('discount_price',response.discount_price);
                                    bundleItem.set('list_usdollar',response.list_usdollar);
                                    bundleItem.set('cost_usdollar',response.cost_usdollar);
                                    bundleItem.set('discount_usdollar',response.discount_usdollar);
                                    bundleItem.set('tax_class',response.tax_class);
                                    bundleItem.set('weight',response.weight);
                                    bundleItem.set('type_id',response.type_id);
                                    bundleItem.set('type_name',response.type_name);
                                    bundleItem.set('manufacturer_id',response.manufacturer_id);
                                    bundleItem.set('manufacturer_name',response.manufacturer_name);
                                    bundleItem.set('currency_id',response.currency_id);
                                    bundleItem.set('base_rate',response.base_rate);
                                    bundleItem.set('isCopied',false);
                                },this,bundleItem)
                            });
                        }
                    });
                }
            });
        }

  • Hi Jeroen,

    Regarding your first question:

    It is the desired behavior in Sugar. Whenever we added a calculated field in Sugar or modify the existing calculating field then it is the limitation to perform save click action to recalculate it. But this is a time-consuming operation for a large number of records. So you can do the following steps if you are an administrator or have developer-level access:

    1. Navigate to the Quote's list view and select those you wish to update.
    2. From the Actions menu, choose to Recalculate Value.
    This will trigger a recalculation of all calculated fields in the selected record. 
    For your second question:
    There is a need to look into the code implementation. Maybe there is some dependency apply to these fields. You can contact my Sugar certified team at support@rolustech.com for further assistance. You can also check out our SugarCRM e-book for more insight on your current problem.
    Hopefully, this will help you sort out your issue!
  • Hi 

    thanks for the answer but this does not really answer my questions. I wonder if someone else has found how the various fields in the product bundle list are set readonly. I can't seem to find a dependency of some sort 

  • I vaguely remember running into something like this with Quotes so here might be something to look into. SugarLogic (sidecarExpressionContext.js) has a listener for 'list:editrow:fire' and i think in a couple places in Quotes (and Opps/RLI create supanel-list-create.js) we specifically trigger the 'list:editrow:fire' event on the context to trigger SugarLogic to run manually. I've had hit-or-miss success with that in the past but I think if you can find the right combination of contexts to trigger the event on, and passing in the right model, you may get SL to re-run on the right model to trigger rollups and dependencies. Sorry this isn't a step-by-step guide but hopefully something there gets you pointed in the right direction.

  • Hi

    We faced a similar issue at a customer's instance, maybe our solutions may help you:

    file: custom/modules/ProductBundles/clients/base/views/quote-data-group-list/quote-data-group-list.js, method onAddNewItemToGroup.


    Add the lines

            this.qliListMetadata = app.metadata.getView('Products', 'quote-data-group-list');
            this._fields = _.flatten(_.pluck(this.qliListMetadata.panels, 'fields'));
    

    between variable declarations

    		var relatedModel = app.data.createRelatedBean(this.model, null, linkName);
    		var quoteModel = this.context.get('parentModel');
    		var maxPositionModel;
    		var position = 0;
    		var $relatedRow;
    		var moduleName = linkName === 'products' ? 'Products' : 'ProductBundleNotes';
    		var modelData = {};
    		var groupLineNumObj;
    		// these quoteModel values will be overwritten if prepopulateData
    		// already has currency_id or base_rate already set
    		var currencyId = quoteModel.get('currency_id');
    		var baseRate = quoteModel.get('base_rate');
    		var newLineNum;
    

    and line

    		prepopulateData = prepopulateData || {};
    

    This workaround fix dependencies issues in lines after first one.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hey André just curious, we run that code during initialize. What changes between initialize and onAddNewItemToGroup that you need to run those again or why did you guys find that fixes the issue?

    Thanks!

  • Hi

    In some specific situations, I can not remember exactly which ones, dependencies configured in some fields get lost on adding additional items.

    André Lopes
    Lampada Global
    Skype: andre.lampada