我正在尝试发送包含我从get_record_ids
方法获得的数据的电子邮件。问题是get_record_ids
有时会被调用两次,有时一次,我不知道为什么。
email_template:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record id="email_template_test" model="mail.template">
<field name="name">test</field>
<field name="email_from">xxx@mail.com</field>
<field name="email_to">xxl@mail.com</field>
<field name="subject">test</field>
<field name="model_id" ref="test.model_test"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<p>Hi,</p>This is simple test <br><br>
<table width="771" cellspacing="1" cellpadding="4" border="1" height="73">
<tbody>
<tr>
<td>Number</td>
<td>Name</td>
<td>Result</td>
</tr>
% if object.get_record_ids():
% for values in object.get_record_ids()
<tr>
<td>${values['number']}</td>
<td>${values['name']}</td>
<td>${values['result']}</td>
</tr>
% endfor
% endif
</tbody></table><br>
]]></field>
</record>
</data>
</openerp>
get_record_ids方法
@api.model
def get_record_ids(self):
ticket_ids = self.env['stock.location'].search([('usage','=','view')], limit=5)
records=[]
for ticket_id in ticket_ids:
tickets={}
result = ticket_id.result
ticket_id.result_difference = ticket_id.last_month_result - result
ticket_id.last_month_result = result
if ticket_id.result_difference != 0 and ticket_id:
tickets['number'] = ticket_id.number
tickets['name'] = ticket_id.name
tickets['result'] = ticket_id.result
records.append(tickets)
return records
和
@api.model
def get_data(self):
res_id = 2
template = self.env.ref('test.email_template_test')
self.env['mail.template'].browse(template.id).send_mail(res_id, force_send=True)
ticket_id.result
是计算值。