我创建了一个模块,它将向用户发送电子邮件,这是我的template.xml但我无法制作python方法。我看了Sale模块的电子邮件方法,但它对我不起作用。我现在正在筹码。我应该遵循哪种方式?你能帮帮我吗?
<record id="email_template_exp_prod_tag_cycle_report" model="mail.template">
<field name="name">Life Cycle Report</field>
<field name="email_from">>${(object.user_id.email and '%s <%s>' %
(object.user_id.name, object.user_id.email) or '')|safe}</field>
<field name="subject">Life Cycle Report</field>
<field name="email_recipients" />
<field name="model_id" ref="product.model_product_product" />
<field name="auto_delete" eval="True" />
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p>Hello,</p>
<p>Kindly find Report in attachment.</p>
<div style="width: 347px; margin: 0px; padding: 5px 14px; line-height: 16px; background-color: #F2F2F2;">
<span style="color: #222; margin-bottom: 5px; display: block; ">
% if object.company_id.street:
${object.company_id.street}<br/>
% endif
% if object.company_id.street2:
${object.company_id.street2}<br/>
% endif
% if object.company_id.city or object.company_id.zip:
${object.company_id.zip} ${object.company_id.city}<br/>
% endif
% if object.company_id.country_id:
${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}<br/>
% endif
</span>
% if object.company_id.phone:
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
Phone: ${object.company_id.phone}
</div>
% endif
% if object.company_id.website:
<div>
Web : <a href="${object.company_id.website}">${object.company_id.website}</a>
</div>
%endif
<p></p>
</div>
</div>
]]></field>
</record>
这是我的不工作代码,
def generate_send_mail(self,product_ids):
for p in product_ids:
print p["id"].name
ir_model_data = self.env['ir.model.data']
template_id = ir_model_data.get_object_reference('product_modules', 'email_template_exp_prod_tag_cycle_report')[1]
subject = 'Product Expiry Life Cycle Report'
report_name = 'expired.life.cycle.report'
if template_id and product_ids:
ir_actions_report = self.pool.get('ir.actions.report.xml')
matching_reports = ir_actions_report.search([('report_name', '=', report_name)])
if matching_reports:
report = ir_actions_report.browse(matching_reports[0])
report_service = 'report.' + report.report_name
service = netsvc.LocalService(report_service)
(result, format) = service.create(product_ids, {'model': 'product.product'})
result = base64.b64encode(result)
file_name = subject + ".pdf"
return True
我在代码上尝试了很多东西,这就是为什么它如此复杂。
答案 0 :(得分:1)
使用模板发送邮件,请尝试以下代码
AggregateIterable<Document> output = collection.aggregate(
Arrays.asList(
new Document(
"$project", new Document(
"x", new Document(
"$objectToArray", "$$CURRENT"
)
)
),
new Document("$unwind", "$x"),
new Document(
"$match", new Document(
"x.k", new Document(
"$in", new BasicDBObject("$regex", "^(ISBN(-10)?:? )?([-0-9xX ]{13}|[0-9X]{10})$")
)
)
)
)
);
希望它会对你有所帮助。