Skip to content

[ADD] auto_invoice_email: Auto-send posted invoices older than configured days #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

rvar-odoo
Copy link

The motivation behind this PR:

  • To automate the process of sending posted invoices via email for all invoices older than a configurable number of days. This ensures timely communication with customers without requiring manual intervention.

The behavior before this PR:

  • Only invoices with an exact invoice_date equal to today's date minus the configured number of days (= target_date) were selected. Older invoices were skipped, even if they were still unsent.

The desired behavior after this PR:

  • Now, the system selects all posted invoices where invoice_date is less than the calculated target_date, allowing pending older invoices to be sent automatically via the scheduled cron job.

@robodoo
Copy link

robodoo commented Jul 24, 2025

Pull request status dashboard

@rvar-odoo rvar-odoo force-pushed the 18.0-automated_email_action-rvar branch 3 times, most recently from 652a1df to 0e613c1 Compare July 25, 2025 10:30
Copy link

@maad-odoo maad-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have account as the module that is been added in the PR message?
Also, there is a lot of unnecessary diff in the PR, please remove those please

@@ -0,0 +1 @@
from . import models

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing copyright statement

@@ -0,0 +1,2 @@
from . import res_config_settings

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing copyright statment

@@ -0,0 +1,31 @@
from odoo import models, api

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright statement

Comment on lines 10 to 14
days = int(
self.env["ir.config_parameter"]
.sudo()
.get_param("auto_invoice_email.days", default=0)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be inlined

def _auto_send_invoices(self):
days = int(
self.env["ir.config_parameter"]
.sudo()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it is a good practise to add a small doc string justifying the use of the sudo

Comment on lines 19 to 25
invoices = self.search(
[
("state", "=", "posted"),
("invoice_date", "=", target_date),
("move_type", "in", ("out_invoice", "out_refund")),
]
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be inlined

Comment on lines 28 to 30
template.with_context(force_send=True).send_mail(
invoice.id, force_send=True
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚒️ inlined

…ed days

- Modified the cron logic to generate and attach the invoice PDF when
sending email.
- Ensured the email includes the invoice PDF using QWeb report.
- Posted a message in the chatter with or without attachment, depending
on availability.
- Added fallback logic to handle missing attachments gracefully.
@rvar-odoo rvar-odoo force-pushed the 18.0-automated_email_action-rvar branch from 0e613c1 to 90f9b11 Compare July 28, 2025 04:48
@rvar-odoo rvar-odoo changed the title [ADD] account: Auto-send posted invoices older than configured days [ADD] auto_invoice_email: Auto-send posted invoices older than configured days Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants