Пользовательский модуль отправки электронной почты Odoo 10
Я создал модуль, который будет отправлять электронную почту пользователю, и вот мой template.xml, но я не смог сделать метод python. Я посмотрел метод продажи модулей по электронной почте, но он не работает для меня. Я сейчас в стеке. Какой путь я должен следовать? Не могли бы вы мне помочь?
<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
Я пробовал так много вещей в своем коде, поэтому он такой сложный.
1 ответ
Чтобы отправить письмо используя шаблон, попробуйте код ниже
@api.multi
def _alert_product_expiry(self):
for data in self:
template_id = self.env.ref('module_name.email_template_exp_prod_tag_cycle_report')
send = template_id.send_mail(data.id, force_send=True)
Надеюсь, это поможет вам.