Hi Team,
I have developed a quotes payment app where I have created a customized quotes templates and provide the payment options. Now i want to validate the quotes creations whenerver the Subtotal amount is less than discount same like stipe is work. and it need to work only for our quoes templates it’s not to be affect other quotes templates.
Hi Team,
I have developed a quotes payment app where I have created a customized quotes templates and provide the payment options. Now i want to validate the quotes creations whenerver the Subtotal amount is less than discount same like stipe is work. and it need to work only for our quoes templates it’s not to be affect other quotes templates.
Here’s the code to disable quote creation when the subtotal is less than the discount, applied only to specific quote templates in your custom quotes payment app:
def validate_quote(subtotal, discount, template_id “”" This function validates quote creation based on subtotal, discount, and template ID. Args: subtotal: The subtotal amount of the quote. discount: The discount amount applied to the quote. template_id: The unique identifier of the quote template. Returns: True if quote creation is valid, False otherwise. “”" # Define a list of allowed template IDs for the discount validation allowed_templates = [1, 2, 3] # Replace with your actual allowed template IDs # Check if the subtotal is less than the discount if subtotal < discount: # If the template ID is not in the allowed list, disallow quote creation if template_id not in allowed_templates: return False # Quote creation is valid return True # Example usage (assuming you have subtotal, discount, and template_id values) subtotal = 100 discount = 120 template_id = 2 if validate_quote(subtotal, discount, template_id): print(“Quote creation is valid.”) else: print(“Quote creation is not valid: Subtotal cannot be less than discount for this template.”)
Explanation:
validate_quote function: This function takes three arguments: subtotal, discount, and template_id.
allowed_templates list: This list stores the IDs of the templates where you want to enforce the “subtotal less than discount” validation. Replace the placeholder values with your actual template IDs.
Discount Validation: The code checks if the subtotal is less than the discount.
Template ID Check: If the validation fails (subtotal < discount), the code verifies if the template_id is present in the allowed_templates list.
Return Value: The function returns True if quote creation is valid (subtotal is not less than discount for allowed templates) and False otherwise.