Reputation: 611
I want to send mail with attachment of PDF report generated through cron. the model : "stock.warehouse.orderpoint".
I want to send mail with report PDF containing the information of model "stock.warehouse.orderpoint", when trying this code , I got many mail with each report of stock orderpoint in a mail. But I want one mail with one report.
//the cron :
<record id="ir_cron_auto_send_mail_quantity_notifier" model="ir.cron">
<field name="name">Quantity Notifier</field>
<field name="model_id" ref="stock.model_stock_warehouse_orderpoint"/>
<field name="state">code</field>
<field name="code">
for stock in env['stock.warehouse.orderpoint'].search([]):
try:
stock.send_reminder_mail()
env.cr.commit()
except Exception as e:
pass
</field>
<field name="active" eval="True"/>
<field name="user_id" ref="base.user_root"/>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>
//mail function:
class StockWarehouseOrderpoint(models.Model): _inherit = "stock.warehouse.orderpoint"
def send_reminder_mail(self, force_send=True):
template_id = self.env.ref("my_module.email_template_quantity_reminder")
if template_id:
template_id.send_mail(self.id, force_send=force_send, email_values={"email_to": "[email protected]"},)
return True
//report template:
<template id="report_quantity_notifier">
<t t-call="web.html_container">
<div class="page">
<table border="1">
<thead>
<tr>
<th>
<strong>Article</strong>
</th>
<th>
<strong>Emplacement</strong>
</th>
<th>
<strong>Qty Alert</strong>
</th>
<th>
<strong>Qty disponible</strong>
</th>
</tr>
</thead>
<tbody>
<tr style="font-size:20px" t-foreach="docs" t-as="doc">
<td>
<span t-field="doc.product_id"/>
</td>
<td>
<span t-field="doc.location_id"/>
</td>
<td>
<span t-field="doc.product_min_qty"/>
</td>
<td>
<span t-field="doc.qty_on_hand"/>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</template>
<record id="quantity_report" model="ir.actions.report">
<field name="name">Quantity</field>
<field name="model">stock.warehouse.orderpoint</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">my_module.report_quantity_notifier</field>
<field name="report_file">my_module.report_quantity_notifier</field>
<field name="binding_model_id" ref="stock.model_stock_warehouse_orderpoint"/>
<field name="binding_type">report</field>
</record>
How to do it , any help please? Thanks
Upvotes: 2
Views: 147