Skip to content

[15.0][IMP] mail_post_defer: consider force_send context#1855

Open
smorita7749 wants to merge 1 commit into
OCA:15.0from
qrtl:15.0-imp-mail_post_defer
Open

[15.0][IMP] mail_post_defer: consider force_send context#1855
smorita7749 wants to merge 1 commit into
OCA:15.0from
qrtl:15.0-imp-mail_post_defer

Conversation

@smorita7749
Copy link
Copy Markdown

Standard Odoo modules (e.g. sale.order) use with_context(force_send=True) to request immediate email delivery. However, mail_post_defer was not checking force_send in context, causing these emails to be deferred unexpectedly. This change adds the context check so that force_send=True in context is properly considered.

@qrtl QT6282

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @yajo,
some modules you are maintaining are being modified, check this out!

@smorita7749
Copy link
Copy Markdown
Author

Pre-commit error may be caused by #1856

Copy link
Copy Markdown

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Choose a reason for hiding this comment

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

Code Review: LG 👍

Copy link
Copy Markdown
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

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

Thanks, good catch!

or kwargs.get("force_send", False)
)
kwargs.setdefault("force_send", force_send)
if not force_send:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: instead of the above change, just add this:

Suggested change
if not force_send:
if not force_send or self.env.context.get("force_send"):

Explanation: The context is already kept in sub-calls. We just need to honor the context if present, but we don't need to alter the kwarg.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review!

I believe this change is necessary.

_notify_record_by_email reads context only for
mail_notify_force_send, not force_send:

force_send = self.env.context.get('mail_notify_force_send', force_send)

This PR reads force_send from context early so that
kwargs.setdefault propagates True to
_notify_record_by_email, and emails.send() is
actually called.

Please let me know if my understanding is correct.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suppose @yajo meant if not force_send and not self.env.context.get("force_send"):, but it still doesn't look like it would work in _notify_record_by_email, since the force_send kwarg would be set to False and would prevail. I think the approach of this PR is correct.

Copy link
Copy Markdown
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

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

LGTM.

or kwargs.get("force_send", False)
)
kwargs.setdefault("force_send", force_send)
if not force_send:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suppose @yajo meant if not force_send and not self.env.context.get("force_send"):, but it still doesn't look like it would work in _notify_record_by_email, since the force_send kwarg would be set to False and would prevail. I think the approach of this PR is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants