From 22a09e8e7a299ba67ed6c7f072b1058a704b8cfa Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Thu, 19 Dec 2019 15:05:46 +0100 Subject: [PATCH] !fixup misc --- pos_mail_receipt/models/pos_order.py | 26 +++++++++++++++-------- pos_mail_receipt/static/src/js/screens.js | 1 - 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pos_mail_receipt/models/pos_order.py b/pos_mail_receipt/models/pos_order.py index a45fbcd9..f8cb4bbd 100644 --- a/pos_mail_receipt/models/pos_order.py +++ b/pos_mail_receipt/models/pos_order.py @@ -3,10 +3,14 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging import base64 from odoo import fields, models, api, _ +_logger = logging.getLogger(__name__) + + class PosOrder(models.Model): _inherit = "pos.order" @@ -18,18 +22,23 @@ class PosOrder(models.Model): ): order = self.search([("pos_reference", "=", pos_reference)]) if len(order) < 1: - return _("Error: no order found") + _logger.error(_("Error: no order found")) + return if order.email_receipt_sent: - return _("E-mail already sent") + _logger.info(_("E-mail already sent")) + return if not email and not order.partner_id and not order.partner_id.email: - return _( - "Cannot send the ticket, no email address found for the client" + _logger.error( + _( + "Cannot send the ticket, no email address found for the client" + ) ) mail_template = self.env.ref("pos_mail_receipt.email_send_ticket") + email_values = {} if email: - mail_template.email_to = email + email_values["email_to"] = email else: - mail_template.email_to = order.partner_id.email + email_values["email_to"] = order.partner_id.email base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf( [body_from_ui.encode("utf-16")], landscape=False, @@ -49,10 +58,9 @@ class PosOrder(models.Model): "res_id": order.id, } ) + email_values["attachment_ids"] = [attachment.id] mail_template.send_mail( - order.id, - force_send=force, - email_values={"attachment_ids": [attachment.id]}, + order.id, force_send=force, email_values=email_values, ) order.email_receipt_sent = True diff --git a/pos_mail_receipt/static/src/js/screens.js b/pos_mail_receipt/static/src/js/screens.js index a5675f00..6990f56d 100644 --- a/pos_mail_receipt/static/src/js/screens.js +++ b/pos_mail_receipt/static/src/js/screens.js @@ -54,7 +54,6 @@ odoo.define("pos_mail_receipt.screens", function (require) { timeout: timeout, }) .then(function (result) { - console.log(result); return true }).fail(function (type, error){ var connection_problem = true;