Print format for a condition

In my case i want in stock entry when i make material transfer to give me specific Letter Head and a specific print format.
For the letter head it works but how can i make it for print format?
Any help?

this is my code:
frappe.ui.form.on(‘Stock Entry’, ‘validate’, function(frm){
if( frm.doc.purpose == ‘Material Transfer’){
frm.set_value(“letter_head”, “Purchase Order Header and Footer”);
}
})

Open your doctype in customize form and there is one field Default Print Format.

image

But you can’t change it dynamically.

hi @Sangram,
yes i know i can do it like this, but i want this print format only for Material Transfer not for all the stock entry.
Anyway to do it?

  1. Add New Your Custom Print Format.

  2. conf in hook.py
    fixtures = [{
    “doctype”: “Print Format”,
    “filters”: [[ “name”, “in”, (“YOUR_PRINT_FORMAT_NAME”) ]]
    }]
    and run this command 'bench export-fixtures'

  3. write this code in js file:
    frappe.ui.form.on(‘Stock Entry’, {
    refresh: function (frm, cdt, cdn) {
    $(document).off(‘click’,‘i.fa-print’).on(‘click’,‘i.fa-print’,function(){
    if(frm.doc.stock_entry_type == ‘Material Transfer’){
    $(‘select.print-preview-select’).val(‘YOUR_PRINT_FORMAT_NAME’).change();
    } else {
    $(‘select.print-preview-select’).val(‘Standard’).change();
    }
    });
    }
    });

1 Like