This question has been flagged
4 Replies
18617 Views

I set up a default parameter to load, when i email a quotation. I see it added in my users default parameters, but it still picks nr 5 (portal template) as the default, instead of id:=4.


Any idea on how i can solve this?

Avatar
Discard

users default parameters? Where do you find it?

ok! I fave found users default parameters in Settings->Actions->User-Defined defaults Thanks

Best Answer

Here is a working and cleaner solution, I think.

Check out addons/portal_sale/portal_sale.py and search the function action_invoice_sent in the account_invoice class.

If the module portal_sale is installed, this function makes sure the portal version of the email.template for invoices is set dy default.

I just copy pasted this function/class in my module and changed the reference call to point towards my own version.

Hope that helps soemone.

Avatar
Discard

this is a more logical solution, but didn't work for me. The invoice template introduced by the portal_sale module remains the default selected. I even specified a "sequence: 90" directive in the manifest, to make sure that my custom module got loaded after the portal_sale, but nothing changed.

Best Answer

Here is our solution to change the default mail template when we click on « send by email » in the sale order form.

  • I have changed the view sale.order.form to modify the « send by email » button. I have changed action for action_quotation_send_pt.

  • I had created a new method with a new name action_quotation_send_pt method. This method is still in the class sale_order (we inherit sale_order). This method is almost the same than the original action_quotation_send but we will change it soon.

import pdb
from openerp.osv import osv
import openerp.pooler
class sale_order(osv.osv):
    _inherit = 'sale.order'

    def action_quotation_send_pt(self, cr, uid, ids, context=None):

        assert len(ids) == 1, 'This option should only be used for a single id at a time.'
        irmodeldataaa = self.pool.get('ir.model.data')
        try:
            template_id = irmodeldataaa.get_object_reference(cr, uid, 'sale', 'email_template_edi_sale')[1]
        except ValueError:
            template_id = False
        try:
            compose_form_id = irmodeldataaa.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
        except ValueError:
            compose_form_id = False        ctx = dict()

        ctx.update({
            'default_model': 'sale.order',
            'default_res_id': ids[0],
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
            'mark_so_as_sent': True
        })
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }

  • We search for the ID of the mail template that we want by default. Here is 24.
  • We have changed external identifier record id in sale.email_template_edi_sale. The new record ID is now 24. The id of our default mail template that we want.

 

  • Now, you can see the new « Devis - par courriel », by default, in the « use template » field. It is great!

We are happy!

 

Avatar
Discard

this solved for me

I didn't have the external identifier. I just created as explained above and it solved my problem