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)
                            });
                        }
                    });
                }
            });
        }

Parents
  • 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.

Reply
  • 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.

Children
No Data