[FIX] purchase: don't send preview email when PO not saved
When PO not saved, no mail can be send. Sending a reminder preview will get traceback. In this commit, we check if the PO is saved before sending the mail. Also clean some useless code in the send_reminder_preview() and fix the issue when no json object is return to the widget because of on mail send. Task 2339431 PR #57961 closes odoo/odoo#59399 X-original-commit: 83f2cac4b8ba101d6a7736a8ff408a3fdb5422fe Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
committed by
William Henrotin
parent
89a597761f
commit
6424025b65
@@ -663,18 +663,18 @@ class PurchaseOrder(models.Model):
|
||||
order.with_context(is_reminder=True).message_post_with_template(template.id, email_layout_xmlid="mail.mail_notification_paynow", composition_mode='comment')
|
||||
|
||||
def send_reminder_preview(self):
|
||||
if not self.user_has_groups('purchase.group_send_reminder') and not self.receipt_reminder_email:
|
||||
self.ensure_one()
|
||||
if not self.user_has_groups('purchase.group_send_reminder'):
|
||||
return
|
||||
|
||||
template = self.env.ref('purchase.email_template_edi_purchase_reminder', raise_if_not_found=False)
|
||||
if template and self.env.user.email:
|
||||
for order in self:
|
||||
template.with_context(is_reminder=True).send_mail(
|
||||
order.id,
|
||||
force_send=True,
|
||||
raise_exception=False,
|
||||
email_values={'email_to': self.env.user.email, 'recipient_ids': []},
|
||||
notif_layout="mail.mail_notification_paynow")
|
||||
if template and self.env.user.email and self.id:
|
||||
template.with_context(is_reminder=True).send_mail(
|
||||
self.id,
|
||||
force_send=True,
|
||||
raise_exception=False,
|
||||
email_values={'email_to': self.env.user.email, 'recipient_ids': []},
|
||||
notif_layout="mail.mail_notification_paynow")
|
||||
return {'toast_message': _("A sample email has been sent to %s.") % self.env.user.email}
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -29,7 +29,9 @@ odoo.define('purchase.ToasterButton', function (require) {
|
||||
model: this.model,
|
||||
args: [[this.id]],
|
||||
}).then(res => {
|
||||
this.do_notify(false, res.toast_message);
|
||||
if (res) {
|
||||
this.do_notify(false, res.toast_message);
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user