Skip to content

Commit 2871e29

Browse files
committed
[ADD] send_invoice: add send invoice automatically by email module
In this task, add module which send invoice by email automatically. in settings fill field enter the number of days to send email after the invoice date. the purpose of the task is that do not need to send invoice by manually it will automatically send by email depend upon how many days will be selected.
1 parent fbf9ee9 commit 2871e29

File tree

7 files changed

+93
-0
lines changed

7 files changed

+93
-0
lines changed

send_invoice/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import models

send_invoice/__manifest__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "send invoice via mail",
3+
"version": "1.0",
4+
"author": "gasa",
5+
"license": "LGPL-3",
6+
"depends": ["account"],
7+
"application": True,
8+
"installable": True,
9+
"data": [
10+
"views/res_config_settings.xml"
11+
]
12+
}

send_invoice/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import res_config_settings
4+
from . import send_email
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import fields, models
2+
3+
4+
class ResConfigSettings(models.TransientModel):
5+
_inherit = "res.config.settings"
6+
7+
send_invoice_via_email = fields.Integer(String="send invoice by email", config_parameter="send_invoice.send_invoice_via_email"
8+
)

send_invoice/models/send_email.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
from odoo import models, fields
3+
from datetime import timedelta
4+
5+
6+
class SendEmail(models.Model):
7+
_inherit = "account.move"
8+
9+
def _send_email_invoice(self):
10+
"""
11+
Use sudo() to bypass access rights when reading system parameters.
12+
Using sudo ensures the method can always retrieve the configuration
13+
value regardless of the user's permissions.
14+
"""
15+
hour = self.env['ir.config_parameter'].sudo().get_param('send_invoice.send_invoice_via_email')
16+
if not hour:
17+
return
18+
19+
try:
20+
hour = int(hour)
21+
except ValueError:
22+
return
23+
24+
target_date = fields.Datetime.now() - timedelta(hours=hour)
25+
invoices = self.search([
26+
('invoice_date', '=', target_date),
27+
('payment_state', '!=', 'paid'),
28+
('state', '=', 'posted')
29+
])
30+
template = self.env.ref('account.email_template_edi_invoice', raise_if_not_found=False)
31+
if not template:
32+
return
33+
34+
for invoice in invoices:
35+
template.send_mail(invoice.id, force_send=True)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<odoo>
2+
<record id="ir_cron_send_email_invoice" model="ir.cron">
3+
<field name="name">Send Invoice Email</field>
4+
<field name="model_id" ref="account.model_account_move" />
5+
<field name="state">code</field>
6+
<field name="code">model._send_email_invoice()</field>
7+
<field name="interval_number">6</field>
8+
<field name="interval_type">hours</field>
9+
<field name="active" eval="True" />
10+
</record>
11+
</odoo>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="res_config_settings_view" model="ir.ui.view">
4+
<field name="name">res.config.settings.inherit.view.form</field>
5+
<field name="model">res.config.settings</field>
6+
<field name="inherit_id" ref="account.res_config_settings_view_form" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//block//setting[@id='total_amount_words']"
9+
position="after">
10+
<setting id="automatic_send_invoice" >
11+
<label for="send_invoice_via_email" />
12+
<div>
13+
<field name="send_invoice_via_email" class="oe_inline" />
14+
<span>hours</span>
15+
</div>
16+
</setting>
17+
</xpath>
18+
</field>
19+
</record>
20+
</odoo>

0 commit comments

Comments
 (0)