Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4190 Vistas

Hello,

I want to create schedule action for the button send by email in invoicing for customer every month, How can I do that.


Thanks in advance for any help.

Avatar
Descartar
Mejor respuesta

Hi,

The "Send by Email" button on the invoice opens the default email template (like account.email_template_edi_invoice ) and sends the invoice as a PDF attachment to the customer.

Create a Custom Module

Create a simple custom module (eg, auto_invoice_mailer ) and add the following logic.

__manifest__.py

{ 'name' : 'Auto Invoice Email Sender' , 'version' : '1.0' , 'category' : 'Accounting' , 'depends' : [ 'account' ], 'data' : [ 'data/auto_invoice_cron.xml' , ], }

models/auto_invoice.py

from odoo import models, api from datetime import datetime, timedelta class AutoInvoiceSender (models.Model): _inherit = 'account. move' @api.model def cron_send_invoices_by_email ( self ): # Set your criteria for invoices to send (eg, posted, customer invoice, not already sent) invoices = self. search([ ( 'move_type' , '=' , 'out_invoice' ), ( 'state' , '=' , 'posted' ), ( 'invoice_date' , '>=' , (datetime.today() - timedelta(days= 30 )).date()), ( 'invoice_sent' , '=' , False ), # Make sure it's not already sent ]) template = self.env.ref( 'account.email_template_edi_invoice' , raise_if_not_found= False ) for invoice in invoices: if template: invoice.message_post_with_template( template.id ) invoice.write({ 'invoice_sent' : True }) # Mark as sent

data/auto_invoice_cron.xml

<odoo> <data noupdate = "1"> <record id = "ir_cron_auto_invoice_sender" model = "ir.cron"> <field name = "name" >Send Monthly Customer Invoices by Email </field> <field name = "model_id" ref = "account.model_account_move"/> <field name = "state" >code </field> <field name = "code" >model.cron_send_invoices_by_email() </field> <field name = "user_id" ref = "base.user_admin"/> <field name = "interval_number">1 </field> <field name = "interval_type">months </field> <field name = "numbercall" >-1 </field> <field name = "doall" eval = "False"/> <field name = "active" eval = "True"/> </record> </data> </odoo>

i hope it is usefull

Avatar
Descartar
Mejor respuesta

Hi,


Create schedule action with the button click function.


<data noupdate="1">


     <record id="ir_cron_scheduler_recurring_action" model="ir.cron">


              <field name="name">Recurring Todo Activity</field>


               <field name="model_id" ref="model_mail_activity"/>


               <field name="state">code</field>


                <field name="code">model.action_done()</field>


                <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>

     </record>

</data>



Change the interval type as days/months


For creating email template please go through this blog


https://www.cybrosys.com/blog/creating-email-templates-in-odoo-15


Create python function to send email through button function


def action_done(self):

   mail_template = self.env.ref("module_name.email_template_name")

   mail_template_send_mail(self.id,force_send=True)


Hope it helps




Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 24
7442
2
nov 24
28125
2
may 24
7197
3
mar 24
6627
0
mar 24
1443