Browse Source

!fixup Use XmlReceipt instead of Html Receipt

pull/428/head
Pierrick Brun 5 years ago
parent
commit
4e9bef3919
  1. 9
      pos_mail_receipt/models/pos_order.py
  2. 12
      pos_mail_receipt/static/src/js/screens.js

9
pos_mail_receipt/models/pos_order.py

@ -18,7 +18,7 @@ class PosOrder(models.Model):
@api.model @api.model
def send_mail_receipt( 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)]) order = self.search([("pos_reference", "=", pos_reference)])
if len(order) < 1: if len(order) < 1:
@ -33,14 +33,14 @@ class PosOrder(models.Model):
"Cannot send the ticket, no email address found for the client" "Cannot send the ticket, no email address found for the client"
) )
) )
mail_template = self.env.ref("pos_mail_receipt.email_send_ticket")
email_values = {} email_values = {}
if email: if email:
email_values["email_to"] = email email_values["email_to"] = email
else: else:
email_values["email_to"] = order.partner_id.email email_values["email_to"] = order.partner_id.email
base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf( base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf(
[body_from_ui.encode("utf-16")],
[receipt.encode("utf-16")],
landscape=False, landscape=False,
specific_paperformat_args={ specific_paperformat_args={
"data-report-margin-top": 10, "data-report-margin-top": 10,
@ -59,6 +59,7 @@ class PosOrder(models.Model):
} }
) )
email_values["attachment_ids"] = [attachment.id] email_values["attachment_ids"] = [attachment.id]
mail_template = self.env.ref("pos_mail_receipt.email_send_ticket")
mail_template.send_mail( mail_template.send_mail(
order.id, force_send=force, email_values=email_values, order.id, force_send=force, email_values=email_values,
) )
@ -72,7 +73,7 @@ class PosOrder(models.Model):
self.send_mail_receipt( self.send_mail_receipt(
order["data"]["name"], order["data"]["name"],
order["data"]["email"], order["data"]["email"],
order["data"]["body_from_ui"],
order["data"]["receipt"],
force=False, force=False,
) )
return res return res

12
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 screens = require('point_of_sale.screens');
var rpc = require('web.rpc'); var rpc = require('web.rpc');
var core = require('web.core');
var QWeb = core.qweb;
var ReceiptScreenWidget = screens.ReceiptScreenWidget.include({ var ReceiptScreenWidget = screens.ReceiptScreenWidget.include({
renderElement: function() { renderElement: function() {
@ -24,15 +26,14 @@ odoo.define("pos_mail_receipt.screens", function (require) {
email: function() { email: function() {
var self = this; var self = this;
var email = false; 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 ) { 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 { } else {
this.gui.show_popup('textarea', { this.gui.show_popup('textarea', {
'title':_t('E-mail address to use'), 'title':_t('E-mail address to use'),
'value': '', 'value': '',
'confirm': function(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") { while (self.pos.get("synch").state == "connecting") {
await sleep(1000); await sleep(1000);
} }
var receipt = QWeb.render('XmlReceipt', this.get_receipt_render_env());
return rpc.query({ return rpc.query({
model: 'pos.order', model: 'pos.order',
method: 'send_mail_receipt', method: 'send_mail_receipt',
args: [order, options["email"], options["body_from_ui"]],
args: [order.name, options["email"], receipt],
}, { }, {
timeout: timeout, timeout: timeout,
}) })
@ -79,12 +81,14 @@ odoo.define("pos_mail_receipt.screens", function (require) {
'title': error.data.message, 'title': error.data.message,
'body': error.data.debug 'body': error.data.debug
}); });
this.$('.button.email').removeClass("highlight");
} }
if(connection_problem){ if(connection_problem){
self.gui.show_popup('error',{ self.gui.show_popup('error',{
'title': _t('The e-mail could not be sent'), 'title': _t('The e-mail could not be sent'),
'body': _t('Check your internet connection and try again.'), 'body': _t('Check your internet connection and try again.'),
}); });
this.$('.button.email').removeClass("highlight");
} }
}); });
}, },

Loading…
Cancel
Save