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

Parents
  • You are missing a quote after $discount_price but I'm not sure that will address your problem.

    I'm not sure you can use variables like we do in sugar logic.

    All the examples I have seen of range have hardcoded numbers.

    The validations that use another field are all dates and have a compareto parameter to get the field value, for example in Meetings the date_start has the following:

          'validation' =>

          array (

            'type' => 'isbefore',

            'compareto' => 'date_end',

            'blank' => false,

          ),

    Perhaps you could put a validation on the total_amount field to check that it's greater than -1, which is greater than or equal to zero (if the discount is higher than the unit price you'll get a negative total_amount).

          'validation' =>

          array (

            'type' => 'range',

            'greaterthan' => -1,

          ),

    HTH

    FrancescaS

  • Thanks for your reply FrancescaS. Actually I am not missed the quote. Is there any other way to achieve this.

    Thanks

  • Besides the validation suggested for the total_amount, the only other thing I can think of right now is to add some logic to onSaveRowEdit in your ProductBundlesQuoteDataGroupListView to check the discount, there you can abort the save and alert the user if the discount is higher than the unit price.

     

    The controller would be in:

    custom/modules/ProductBundles/clients/base/views/quote-data-group-list/quote-data-group-list.js

     

    FrancescaS

Reply
  • Besides the validation suggested for the total_amount, the only other thing I can think of right now is to add some logic to onSaveRowEdit in your ProductBundlesQuoteDataGroupListView to check the discount, there you can abort the save and alert the user if the discount is higher than the unit price.

     

    The controller would be in:

    custom/modules/ProductBundles/clients/base/views/quote-data-group-list/quote-data-group-list.js

     

    FrancescaS

Children
  • Hi FrancescaS,

    Thanks once again.

    If I add the below code 

    if(parseInt(rowModel.attributes.discount_amount) > parseInt(rowModel.attributes.discount_price)) {
    app.alert.show('closed_confirmation', {
    level: 'error',
    messages: app.lang.get('LBL_DISCOUNT_ERROR', 'Quotes'),
    autoClose: false
    });
    return false;
    }

    It shows the expected error message. But the save and cancel button of Quote line item is disappeared once I click tick icon of quote line item. Any idea please