Skip to Content
Menu
This question has been flagged
2689 Views

controller:

# -*- coding: utf-8 -*- from odoo import http from odoo import api, fields, models, SUPERUSER_ID, _ import re 
class callback(http.Controller):
 _inherit = 'mail.message'
# def __init__(self, pool):
# self.pool = pool
 @http.route('/callback/', auth='public')
 def index(self, **kw):
  self.send_mail_example()
  return "Hello, world"

Model:

# -*- coding: utf-8 -*- 
from odoo import http from odoo import api, fields, models, SUPERUSER_ID, _ import re
class callback2(http.Controller):
 _inherit = 'mail.message'
 def send_mail_example(self, lead, kwargs):
  """ Allow to be overrided """
  msg_id = False
  email_to = ['darkink@mail.ru']
  ir_model_data = request.env['ir.model.data']
  email_template_obj = request.env['mail.template']
  crm_lead_obj = request.env['crm.lead']
  template_id = ir_model_data.get_object('bp_contact_snippet', 'email_template_website_message_lead')
  if template_id.ids:
    template = email_template_obj.sudo().browse(template_id.ids[0])
    crm_lead = crm_lead_obj.sudo().browse(lead)
    if crm_lead:
      values = template.sudo().generate_email(crm_lead.id)
      message_contacts = request.env['website.message.contact'].sudo().search([])
      if message_contacts:
        for message_contact in message_contacts:
          email_to.append(message_contact.email)
        values['email_to'] = ', '.join(email_to)
        mail_mail_obj = request.env['mail.mail']
        msg_id = mail_mail_obj.sudo().create(values)
  return msg_id

in log:

self.send_mail_example() 
AttributeError: 'callback' object has no attribute 'send_mail_example'

WHY?

Avatar
Discard