How to make Quoted Line Items Negative based on a dropdown value in the Quote header?

I have an integration with my ERP where Returns/Credits are posted as negative dollar values.  Prior to Sugar 7.8 in the old BWC quotes module I was able to alter cost_price, discount_price and list_price of newly added Product catalog entries in an after save hook.  

Basically it was along the lines of:

If($bean->order_or_return_c == 'return')

{
    //Loop through my products
        // If list price > 0, multiply it by -1
        // If cost_price > 0, multiply it by -1
        // If discount_price > 0, multiply it by -1
        


}

How would I accomplish this in the new sidecar Quotes module?  When an item is added to the quote, if the dropdown = 'return', multiply all its currency fields by -1?

Now that QLI's are a seperate part of the view, I dont know how to cross the threshold with JS to affect one based on the other.  

Parents
  • I swear I've been working on this on and off for a month.  Kept coming back to it and finally figured it out.  It's actually VERY simple to do in sidecar.  Finding the correct controller (there's so many for QLI's..... WHY Sugar WHY?!?!) and a trigger field was the trick.   

    I placed my code in custom/modules/Products/clients/base/fields/quote-data-relate/quote-data-relate.js

    I then decided to trigger off a change in cost_price.  Every time a new item is added, the cost_price changes no matter what

    Here's the code to do it

    ({
    	extendsFrom: 'ProductsQuoteDataRelateField',
    
    	initialize: function(options){
    		this._super('initialize', [options]);
    		this.model.on('change:cost_price', this.checkRA,this); // detects if a new line is added
    	  },
    	  checkRA: function()
    	  {
    		  
    		quoteObject = this.context.parent.get('model');  // Get a reference to the parent Quote
    		quote_order_c = quoteObject.get('quote_order_c');  // Pull in the Quote header field which has a value of 'quote' 'order' 'credit'
    		
    		console.log('Quote Type = ' + quote_order_c);
    		
    		if(quote_order_c == 'credit')  // This is a Return/Credit
    		{
    			var cost_price = this.model.get('cost_price');
    			var discount_price = this.model.get('discount_price');
    			var list_price = this.model.get('list_price');
    			
    			//Check Cost, List and Sale price.  If any are positive, multiply by -1
    			if(cost_price > 0)
    			{
    				this.model.set('cost_price', cost_price * -1);
    			}
    			if(discount_price > 0)
    			{
    				this.model.set('discount_price', discount_price * -1);
    			}
    			if(list_price > 0)
    			{
    				this.model.set('list_price', list_price * -1);
    			}
    		}
    	  },
        
    
    });

Reply Children
No Data