Validate Discount amount with Unit price in Quote line items

Hi,

I am using sugar 7.9 version. I am trying to validate the quote line item based on the below criteria.

If Discount amount is greater than Unit price then I need to show a error message like `Total Discount amount should be less than or equal to the Unit price`.

I tried to achieve this using

'validation' => array(
'type' => 'range',
'min' => '0',
'max' => '$discount_price,
),

It's not working as expected. 

But both the fields are in currency datatype. So I am not sure How to achieve this validation.

Thanks in advance

  • Hi Vijayakumar S, 

    I'm just wondering if you had any luck resolving this problem. I seem to have a similar issue, I'm trying to apply some custom validation before my Quoted Line Item is saved. However the QLI row seems to be saved no matter what, even if my code does not even run default saving function. i.e. 

    Hi Francesca Shiekh, have you come across this problem since this post? Thanks. 

    My code is :

    ({
      extendsFrom: 'ProductBundlesQuoteDataGroupListView',
      initialize: function(options){
        this._super('initialize' ,[options]);
      },
      onSaveRowEdit: function(rowModel) {
        this.checkQuantity(rowModel);

      },

      checkQuantity: function(rowModel){

        app.alert.show('message-id', {
          level: 'confirmation',
          messages: 'Do you want to save the Row?',
          autoClose: false,
          onConfirm: function(){
            //continue to save
            this._super('onSaveRowEdit', [rowModel]);
          },
          onCancel: function(){
            //cancel the save
            this.onCancelRowEdit(rowModel);
          }
        });
      },

      _dispose: function() {
        this._super('_dispose');
      },
    })
  • I have not but I'm not using it in this way.

    I would recommend going through the original code at modules/ProductBundles/clients/base/views/quote-data-group-list/quote-data-group-list.js and seeing what you might be able to deduce.

    Sorry I'm not more help,

    FrancescaS

  • This method inside such view is responsible for saving all items in a new Quote, that means, it is not triggered on editing/saving a single existing Item.

    For this purpose you need to customize the modules/ProductBundles/clients/base/fields/quote-data-editablelistbutton/quote-data-editablelistbutton.js in order to override the method _save.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Dear all,

    I'm facing nearly the same problematic. 

    I want to validate the amount of the discount set by the user against a value configured in the Product Catalog.

    Could it be possible to add an event on change for the field discount_amout ? How should I proceed ? 

    The  method proposed by Francesca works only if I'm modifying an existing QLI, not a new one (or I'm wrongly understanding some things ?).

    Many thanks in advance.

    Best regards,

    Enes

  • Hi ,

    I just tried to do the method you proposed, but the code isn't fired, even if I have the correct camel cased field name for the extension:

    // File path
    // custom\modules\ProductBundles\clients\base\fields\quote-data-editablelistbutton\quote-data-editablelistbutton.js
    
    ({
        extendsFrom: 'ProductBundlesQuoteDataEditablelistbuttonField',
    
        _saveRowModel: function() {
        	
    
        	console.log("ON PASsE ICI");
        }
    })

    It doesn't work even if I override the _save method. Do you have an idea of what it is wrong ?

    Thanks a lot.

    Best regards,

    Enes

  • My bad! The correct js controller is located in the Products module instead!

    modules/Products/clients/base/fields/quote-data-editablelistbutton/quote-data-editablelistbutton.js

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hello ,

    I find by myself before your post, thanks for the trick, it's working very well. We can use the validation tasks for a Quoted Line Item, it's working like a charm !

    Here is an example of code for the other developers who are facing the same problem :

    ({
        extendsFrom: 'ProductsQuoteDataEditablelistbuttonField',
    
        initialize: function(options) {
            this._super('initialize', [options]);
    
            this.model.addValidationTask('quantity', _.bind(this._doValidateQuantity, this));
            this.model.addValidationTask('discount_amount', _.bind(this._doValidateDiscountAmount, this));
        },
    
        _doValidateQuantity: function(fields, errors, callback) {
            //validate type requirements
            if (this.model.get("quantity") == 0) {
                errors['quantity'] = errors['quantity'] || {};
                errors['quantity'].required = true;
            }
    
            callback(null, fields, errors);
        },
    })

    Hope this will help the other friends !

    Merry christmas every body and stay safe !

    Enes

  • Thanks for this, was exactly what I was looking for.  Just so everyone who also needs this knows this code goes in the file

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