-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[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
base: 18.0
Are you sure you want to change the base?
Conversation
652a1df
to
0e613c1
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing copyright statement
days = int( | ||
self.env["ir.config_parameter"] | ||
.sudo() | ||
.get_param("auto_invoice_email.days", default=0) | ||
) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
invoices = self.search( | ||
[ | ||
("state", "=", "posted"), | ||
("invoice_date", "=", target_date), | ||
("move_type", "in", ("out_invoice", "out_refund")), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be inlined
template.with_context(force_send=True).send_mail( | ||
invoice.id, force_send=True | ||
) |
There was a problem hiding this comment.
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.
0e613c1
to
90f9b11
Compare
The motivation behind this PR:
The behavior before this PR:
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:
invoice_date
is less than the calculatedtarget_date
, allowing pending older invoices to be sent automatically via the scheduled cron job.