Different Email address defaults for different DocTypes

All,

On submit of Quotation, Sales Order and Sales Invoice we trigger emails to customers and attach the relevant Print Format. Is there a way to have a different email address default for each DocType? For example the customer contact who requests the Quotation is often different to the person who needs Sales Order confirmation and VERY OFTEN different to the customer contact who should receive the invoices.

It would be beneficial to have a selection tickbox against customer contacts/emails to determine which receives what doctypes.

Also if there’s a way to default this NOW by using a script or similar please let me know.

Thanks.

1 Like

@monojoker thats a good feature to have. Can you add it to GitHub?

@rmehta I have added to github but in trying to get something going now I have the following custom script written for Sales Invoice:

frappe.ui.form.on('Sales Invoice', 'customer', function(frm){
    frm.call({
        "method": "frappe.client.get",
        "args": {
            "doctype": "Address",
            "filters": {
                "customer": frm.doc.customer,
                "address_type": "Billing",
                "is_primary_address": 1
            } 
        },
       "callback": function(response){
            var pair = {
                email_id: 'contact_email',
            };
            $.each(['address_line_1', 'address_line_2', 'city', 'state', 'country', 'email_id'], function(i, key){
                if (frm.doc.hasOwnProperty(key) && response.message[key]){
                    frappe.model.set_value(
                        frm.doc.doctype,
                        frm.doc.name,
                        pair[key] || key,
                        response.message[key]
                    );
               }
            });
        }
    });
}); 

From the Saved Sales Invoice doc if I run console.log(JSON.stringify(response)); I see:

"email_id":"accounts@berlex.com.au"

But when I Submit the doc, in the Email To field I see:

nathan@berlex.com.au

I can’t see what’s wrong and why it doesn’t email to the correct scripted address.

Anyone got any ideas?

Thanks.

@rmehta I have a somewhat working solution at my end now. But for some reason the behaviour is strange.

This is related to both github issue #3283 and the previously alerted behavior of the frappe.ui.form.trigger passing the first doc value on the next calls - so on the second invoice I generate all details for customer, address, etc is pushing through from the first invoice - incorrectly.

We are using the code in “Sales Invoice.js” Revisions · Addres.js · GitHub.

Please suggest a solution for this?

Fixed?

@rmehta no i’ts still overwriting each subsequent invoice with last invoice’s details. Did you try something to fix?

Please advise, thanks :smile:

@monojoker this is too complicated and there could be many errors.