How to Implementing Custom Logic in Frappe Print Formats

Hello Frappe community,

I’m currently working on a custom print format for sales invoices in my Frappe application.

Here’s what I’m trying to achieve:

  1. Requirement: If the grand total of the sales invoice is greater than 50,000, an E-Waybill number is required. When using my custom print format, I need to check if the grand total exceeds 50,000. If it does, the E-Waybill number should be in. If the E-Waybill number is not provided, an error message should be displayed to the user, and the print option should be disabled.

I would appreciate any insights, suggestions, or code snippets on how to implement this functionality effectively within a Frappe custom print format. Thank you in advance for your help!

It seems what you are trying to do has to be done on the form on validate event.

This way, if the total sales exceeds 50000, the form will not save without the ewaybill number.

A simple search on this forum will come up with ways to validate on either client side or server side.

On the print format, you can do something like

{% if doc.total_sales > 50000 %} doc.ewaybill_number {% endif %}

This way, the ewaybill number will be displayed because the total sales exceeds 50000.

Hope this helps

Thank you for your suggestion. However, I should clarify that my inquiry pertains specifically to implementing logic not in the Jinja template

To elaborate, I’m utilizing the Frappe ‘India compliance’ app, which already includes logic for auto-creating an E-Waybill if the sales invoice total exceeds 50,000. If certain details, such as the vehicle number, are not provided, the auto-creation process is halted, requiring manual creation of the E-Waybill.

My concern arises when users utilize my custom Jinja template for printing sales invoices exceeding 50,000. At this point, I need to ensure that the E-Waybill number is linked. If it’s not linked, I want to prevent the printing of the document and display a message instead