Automatically Change Letterhead / Footer when selecting Company

Hi All

I wonder if i am doing something wrong here or if this system does not load a letterhead and footer automaticalaly once selecting a company.??

I have setup different companies on the system and also separate letterheads and footers for each individual company and have also set these settings for each company,

example; Company A, Letterhead A , Company B , Letterhead B and so on…

When creating a Purchase Order or anything else, and selecting Company A, it does not automatically pick up the letterhead that is associated with it, and i have to go to the bottom of the page, print settings and change it manually every time…

Is there a way of automating this, as this can be quite time consuming, but also very easily get missed or left out by users or members of staff…

Please if anyone can help it would be appreciated.

Thanks in advance

@ermalc
Add custom field Letter Head in Company master,
Then fetch Letter Head when you change Company in transaction.

Hi Kolate @kolate_sambhaji

I am using the latest version and this already has the Default Letter Head field in company form - that has been set for each company to pick up the relevant letter head, but it is not doing that, it is not picking it up automatically on company name change, it is currently a manual process…

If you set Company A Letter Head as default then that becomes default for all companies, but i do not want this, as all companies are different, so they have to pick up the different letterheads automatically, which is not happening at this moment…

thanks

@ermalc You are right, this is not happening at the moment.

Please write this script in all your custom script where you want to fetch default letter head from company.

cur_frm.add_fetch('company','default_letter_head','letter_head');
1 Like

@kolate_sambhaji

Thanks, the script works to pull the letter head , “but only” if the user changes company name (manually triggering). Lets say i’m creating a purchase order as a normal employee, by default when creating a PO the system picks up the company i belong to, but it does not automatically pick up the letterhead, being this with the script or without the script.

The script in this case works only IF employee changes company name, from company a to company b, and then back to company a in order to pick up the right letter head…

Would be nice so when clicking on create PO or any other transaction, the company name is picked up which it does, but the script should automatically have picked up the letterhead without being on a manual trigger to change…

problem with this is that users or employees will often or in most cases forget to change this if it is not done automatically, or go in an out of a different company so it picks up the right letterhead and then ending up with wrong letterheads , business details, etc…

hope this explains…

@ermalc

Following script will change letter head when you clicking on Create New Sales Order

frappe.ui.form.on("Sales Order", "onload", function(frm) { 
  frappe.call({
           method: "frappe.client.get_value",
           args: {
               doctype: "Company",
               fieldname: "default_letter_head",
               filters: { name: cur_frm.doc.company },
           },
              callback: function(res){
                 if (res && res.message){
                         cur_frm.doc.letter_head = res.message.default_letter_head
                          refresh_field("letter_head");
                  }
              }      
       });
}); 

Also use add_fetch to fetch letter head after changing company name
cur_frm.add_fetch(‘company’,‘default_letter_head’,‘letter_head’);

6 Likes

@kolate_sambhaji

You are a genius! Thank you very much for this, this works great.

I appreciate your help!

Thank you

It should fetch all default values of selected company like cost center, warehouse, accounts etc…not just letter head. I don’t understand the reason behind… all these are done manually from users side …

Exactly, There should be a way to link those .

Any idea how to loan letter heads cost center wise,
Sales person cost center wise etc…

This is what I did for automatic printing of specific Letterhead for different companies.

  1. I attached the logo to the Company Master Record. This is the same immage I used as the letterhead. If a different image is desired, Customize the Doctype Company by adding another Attach Image field, maybe named Company Letterhead where you can attach the Letterhead.

  2. Customize the Doctype where you want the Company Letterhead will be printed, by adding the Field Company Letterhead. Everytime a new document is added, the link is automatically copied from the Doctype Company. Refer to this post=
    Attach Image on Save

  3. Customize the Form to include now the Letterhead. I had to take out the Heading and added the section containing the Letterhead and the Document Name and ID.

  4. When printing, don’t select Letterhead. Also, Doctype Letterhead is no longer needed.

Solved for me. Hope you can have a simpler solution to this. For me, this works already.