From 4e9bef3919f4fd0fc666aa027778a014f5851a54 Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Mon, 30 Dec 2019 17:04:09 +0100 Subject: [PATCH] !fixup Use XmlReceipt instead of Html Receipt --- pos_mail_receipt/models/pos_order.py | 9 +++++---- pos_mail_receipt/static/src/js/screens.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pos_mail_receipt/models/pos_order.py b/pos_mail_receipt/models/pos_order.py index f8cb4bbd..8608f7e7 100644 --- a/pos_mail_receipt/models/pos_order.py +++ b/pos_mail_receipt/models/pos_order.py @@ -18,7 +18,7 @@ class PosOrder(models.Model): @api.model def send_mail_receipt( - self, pos_reference, email, body_from_ui, force=True + self, pos_reference, email, receipt, force=True ): order = self.search([("pos_reference", "=", pos_reference)]) if len(order) < 1: @@ -33,14 +33,14 @@ class PosOrder(models.Model): "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: email_values["email_to"] = email else: email_values["email_to"] = order.partner_id.email + base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf( - [body_from_ui.encode("utf-16")], + [receipt.encode("utf-16")], landscape=False, specific_paperformat_args={ "data-report-margin-top": 10, @@ -59,6 +59,7 @@ class PosOrder(models.Model): } ) email_values["attachment_ids"] = [attachment.id] + mail_template = self.env.ref("pos_mail_receipt.email_send_ticket") mail_template.send_mail( order.id, force_send=force, email_values=email_values, ) @@ -72,7 +73,7 @@ class PosOrder(models.Model): self.send_mail_receipt( order["data"]["name"], order["data"]["email"], - order["data"]["body_from_ui"], + order["data"]["receipt"], force=False, ) return res diff --git a/pos_mail_receipt/static/src/js/screens.js b/pos_mail_receipt/static/src/js/screens.js index a5002adf..334df0fd 100644 --- a/pos_mail_receipt/static/src/js/screens.js +++ b/pos_mail_receipt/static/src/js/screens.js @@ -6,6 +6,8 @@ odoo.define("pos_mail_receipt.screens", function (require) { var screens = require('point_of_sale.screens'); var rpc = require('web.rpc'); + var core = require('web.core'); + var QWeb = core.qweb; var ReceiptScreenWidget = screens.ReceiptScreenWidget.include({ renderElement: function() { @@ -24,15 +26,14 @@ odoo.define("pos_mail_receipt.screens", function (require) { email: function() { var self = this; var email = false; - var body_from_ui = this.$('.pos-sale-ticket').html() if( this.pos.get_order().get_client() && this.pos.get_order().get_client().email ) { - self._send_email_server(this.pos.get_order().name, {"email": this.pos.get_order().get_client().email, "body_from_ui": body_from_ui}); + self._send_email_server(this.pos.get_order(), {"email": this.pos.get_order().get_client().email}); } else { this.gui.show_popup('textarea', { 'title':_t('E-mail address to use'), 'value': '', 'confirm': function(value) { - self._send_email_server(self.pos.get_order().name, {"email": value, "body_from_ui": body_from_ui}); + self._send_email_server(self.pos.get_order(), {"email": value}); } }); } @@ -50,11 +51,12 @@ odoo.define("pos_mail_receipt.screens", function (require) { while (self.pos.get("synch").state == "connecting") { await sleep(1000); } + var receipt = QWeb.render('XmlReceipt', this.get_receipt_render_env()); return rpc.query({ model: 'pos.order', method: 'send_mail_receipt', - args: [order, options["email"], options["body_from_ui"]], + args: [order.name, options["email"], receipt], }, { timeout: timeout, }) @@ -79,12 +81,14 @@ odoo.define("pos_mail_receipt.screens", function (require) { 'title': error.data.message, 'body': error.data.debug }); + this.$('.button.email').removeClass("highlight"); } if(connection_problem){ self.gui.show_popup('error',{ 'title': _t('The e-mail could not be sent'), 'body': _t('Check your internet connection and try again.'), }); + this.$('.button.email').removeClass("highlight"); } }); },