Skip to Content
Menu
This question has been flagged
1 Reply
6253 Views

I want to render a mail.template, but getting this following error:


Error:
Odoo Server Error
Traceback (most recent call last):
  File "/opt/odoo/odoo12/odoo/http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo12/odoo/http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo12/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo/odoo12/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo12/odoo/http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo12/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo12/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo12/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo12/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo12/addons/web/controllers/main.py", line 966, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo12/odoo/api.py", line 759, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo12/odoo/api.py", line 746, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/odoo12/custom-addons/vit_dotmatrix/model/models.py", line 20, in generate_printer_data
    data = tpl.render_template(tpl.body_html, 'account.invoice', self.id, post_process=False)
AttributeError: 'mail.template' object has no attribute 'render_template'


In this is my models.py


from odoo import api, fields, models, _
import time
from odoo.exceptions import UserError
import logging
_logger = logging.getLogger(__name__)




class invoice(models.Model):
  _name = 'account.invoice'

_inherit = 'account.invoice'


printer_data = fields.Text(string="Printer Data"required=False)


@api.multi

def generate_printer_data(self):
tpl self.env['mail.template'].search([('name''=''Dot Matrix Invoice')]).
  data = tpl.render_template(tpl.body_html, 'account.invoice'self.id, post_process=False)

self.printer_data = data
@api.multi

def action_invoice_cancel(self):
self.printer_data = ''

return super(invoice, self).action_cancel()


@api.multi

def action_invoice_open(self):
  res = super(invoice, self).action_invoice_open()

self.generate_printer_data()

return res

So, what's wrong with that code ?, any help would be very appreciated :)

Avatar
Discard
Best Answer

Hi,

Try _render_template instead of render_template

Sample:

bodies = self.env['mail.template']._render_template(self.body, self.model, res_ids, post_process=True)


Thanks

Avatar
Discard
Author

Thanks a lots Man, you have saved my time :)

The "_" underscore before the render template is the key to solve this case.

_render_template

Related Posts Replies Views Activity
2
Feb 24
12653
4
May 20
2655
1
Dec 19
6729
0
Nov 19
4284
1
Jul 19
2607