from odoo import api, fields, models,_ from odoo.exceptions import UserError,Warning class DonationRecurringTemplateLetter(models.Model): _inherit = "donation.donation" template_pa_id=fields.Many2one('opendons.template_pa_letter', '(e)mail to send') html_content=fields.Html('html content',compute='pa_html_content') html_content_print=fields.Html('html content print') def action_send_pa(self): self.ensure_one() if not self.partner_id.email: raise UserError( _("Missing email on partner '%s'.") % self.partner_id.display_name ) self.partner_id.display_name template = self.env.ref("opendons.donation_recurring_email_template") compose_form = self.env.ref("mail.email_compose_message_wizard_form") ctx = dict( default_model="donation.donation", default_res_id=self.id, default_use_template=bool(template), default_template_id=template.id, default_composition_mode="comment", default_body_html='dddd' ) action = { "name": _("Compose Email"), "type": "ir.actions.act_window", "view_mode": "form", "res_model": "mail.compose.message", "view_id": compose_form.id, "target": "new", "context": ctx, } return action def pa_html_content(self): self.html_content=self.template_pa_id.html_content class opendons_template_pa(models.Model): _name = 'opendons.template_pa_letter' _description = 'manage pa html template' name=fields.Char('name') description=fields.Text('description') active=fields.Boolean('active') html_content=fields.Html('Html content') def action_update_pa(self): pa=self.env['donation.donation'].search([('template_pa_id','=',int(self.id))]) for p in pa: p.html_content=self.html_content