我正在进行odoo
项目,我需要每天上午10点自动发送电子邮件。我已经创建了预定的操作,但我遇到了问题。这是我用来执行发送操作的方法
@api.model
def send_mails(self):
domain = [['name', 'like', 'Production Report']]
template = self.env['email.template'].search(domain)[0]
template.send_mail(self.id, True)
执行该方法后,它会提供此追溯
2016-11-03 17:35:15,158 4912 ERROR sintramdb openerp.addons.base.ir.ir_cron: Call of self.pool.get('production.ouvrages').send_mails(cr, uid, *()) failed in Job 9 Traceback (most recent call last): File "C:\Program Files (x86)\Odoo 8.0-20160929\server\openerp\addons\base\ir\ir_cron.py", line 138, in _callback File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 268, in wrapper File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 372, in old_api File "C:\Users\3D SKILLS\AppData\Local\OpenERP S.A.\Odoo\addons\8.0\production\models.py", line 347, in send_mails File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 266, in wrapper File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 549, in new_api File "C:\Program Files (x86)\Odoo 8.0-20160929\server\openerp\addons\email_template\email_template.py", line 558, in send_mail File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 268, in wrapper File "C:\Program Files (x86)\Odoo 8.0-20160929\server\openerp\addons\email_template\email_template.py", line 595, in generate_email File "C:\Program Files (x86)\Odoo 8.0-20160929\server\.\openerp\api.py", line 268, in wrapper File "C:\Program Files (x86)\Odoo 8.0-20160929\server\openerp\addons\email_template\email_template.py", line 484, in generate_email_batch AttributeError: 'bool' object has no attribute 'lang'
如果我用@ api.one或@ api.multi替换@ api.model我会收到以下错误
TypeError: old_api() takes at least 4 arguments (3 given)
注意:使用@ api.one或@ api.multi注释,如果我使用单击按钮来调用该方法,它就会完美无缺。
答案 0 :(得分:1)
首先感谢你们的快速回复!!
在我尝试修复后,我仍然无法解决问题。所以我决定深入研究email_template插件中的email_template.py文件,在遇到一些错误之后我终于有了一些工作。贝娄是我的解决方案(当然是旧的api风格)
def send_mails(self, cr, uid, *args, **kwargs): domain = [['name', 'like', 'Production Report']] template_id = self.pool.get('email.template').search(cr, uid,domain,offset=0, limit=None, order=None, context=None, count=False)[0] template_obj = self.pool.get('email.template').browse(cr, uid, template_id) template_obj.send_mail(3, True, None)
我希望它会帮助别人
答案 1 :(得分:0)
试试这个
x = afile.AClass()
如果不起作用,请尝试此解决方案。
@api.v8
@api.model
def send_mails(self):
domain = [['name', 'like', 'Production Report']]
template = self.env['email.template'].search(domain)[0]
template.send_mail(self.id, True)