diff --git a/send_invoice_by_email/__init__.py b/send_invoice_by_email/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/send_invoice_by_email/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/send_invoice_by_email/__manifest__.py b/send_invoice_by_email/__manifest__.py new file mode 100644 index 00000000000..b90dc63983e --- /dev/null +++ b/send_invoice_by_email/__manifest__.py @@ -0,0 +1,15 @@ +{ + 'name': 'Send Invoice By Email', + 'version': '1.0', + 'summary': 'automated action to send invoice by email', + 'author': 'chirag Gami(chga)', + 'category': 'Invoice', + 'depends': ['base', 'account'], + 'license': 'LGPL-3', + 'data': [ + 'views/res_config_settings_views.xml', + 'views/ir_cron_send_email.xml', + ], + 'installable': True, + 'application': True, +} diff --git a/send_invoice_by_email/models/__init__.py b/send_invoice_by_email/models/__init__.py new file mode 100644 index 00000000000..123c3f25143 --- /dev/null +++ b/send_invoice_by_email/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_config_settings +from . import account_move diff --git a/send_invoice_by_email/models/account_move.py b/send_invoice_by_email/models/account_move.py new file mode 100644 index 00000000000..4d55307c482 --- /dev/null +++ b/send_invoice_by_email/models/account_move.py @@ -0,0 +1,33 @@ +from odoo import models, fields +from datetime import timedelta + + +# Extend account.move class to add cron method and custom email send methods +class AccountMove(models.Model): + _inherit = 'account.move' + + # custom email send method + def action_send_invoice_email_custom(self): + for invoice in self: + template = self.env.ref('account.email_template_edi_invoice', raise_if_not_found=False) + if template: + template.send_mail(invoice.id, force_send=True) + + # To check which invoice will sent today, call by ir.cron + def cron_send_invoice_emails(self): + param = self.env['ir.config_parameter'].sudo() + days = param.get_param('send_invoice_by_email.send_email_days') + + if not days: + return + + days = int(days) + target_date = fields.Date.today() - timedelta(days=days) + + invoices = self.search([ + ('invoice_date', '=', target_date), + ('state', '=', 'posted'), + ]) + + for invoice in invoices: + invoice.action_send_invoice_email_custom() diff --git a/send_invoice_by_email/models/res_config_settings.py b/send_invoice_by_email/models/res_config_settings.py new file mode 100644 index 00000000000..a25f8fb1011 --- /dev/null +++ b/send_invoice_by_email/models/res_config_settings.py @@ -0,0 +1,8 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + ''' Add field send_email_days in res.config.settings model to store Days to sand invoice email ''' + _inherit = 'res.config.settings' + + send_email_days = fields.Integer(string="Send invoice by email", config_parameter='send_invoice_by_email.send_email_days') diff --git a/send_invoice_by_email/views/ir_cron_send_email.xml b/send_invoice_by_email/views/ir_cron_send_email.xml new file mode 100644 index 00000000000..da96585336a --- /dev/null +++ b/send_invoice_by_email/views/ir_cron_send_email.xml @@ -0,0 +1,12 @@ + + + + Send Invoice Emails After given Days + + code + model.cron_send_invoice_emails() + 1 + days + True + + diff --git a/send_invoice_by_email/views/res_config_settings_views.xml b/send_invoice_by_email/views/res_config_settings_views.xml new file mode 100644 index 00000000000..c4afc9ea684 --- /dev/null +++ b/send_invoice_by_email/views/res_config_settings_views.xml @@ -0,0 +1,17 @@ + + + + res.config.settings.view.form.add.days + res.config.settings + + + + + + + Days + + + + +