On a visualforce page, I am creating an opportunity and I am adding an OpportunityLineItem (opportunity product) to it.
The product2 linked to the opportunity product has a field called Maximum_Discount_in_percent_EUR__c, which is a percent field and specify the maximun discount possible.
When adding the opportunity product on the visualforce page, you can enter a discount in % (standard Discount field) or a net price (Net_Price_Discount__c). There is a validation rule preventing you for entering both.
The opportunity product has a validation rule checking if the discount is not superior to the authorized discount. Here is the rule's formula:
AND( NOT($User.ByPass_VR__c), OR( AND( Product2.Maximum_Discount_in_percent_EUR__c <> 0, IF(ISBLANK(Discount) || ISNULL(Discount), (ListPrice - (Product2.Maximum_Discount_in_percent_EUR__c * ListPrice)) >= Net_Price_Discount__c, Product2.Maximum_Discount_in_percent_EUR__c < Discount)) ) )
I have tested the NOT($User.ByPass_VR__c) line, and it is not giving me any problems.
When I enter a discount in the Discount field superior the authorized one, the validation rule worked fine and I get my error message. But when I enter e net price in Net_Price_Discount__c inferior to the authorized one, then it doesn't work and I can save the opportunity product.
Is the problem in my formula or can it be somewhere else? Thank you for your help