|
@ -3,10 +3,14 @@ |
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import logging |
|
|
import base64 |
|
|
import base64 |
|
|
from odoo import fields, models, api, _ |
|
|
from odoo import fields, models, api, _ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PosOrder(models.Model): |
|
|
class PosOrder(models.Model): |
|
|
_inherit = "pos.order" |
|
|
_inherit = "pos.order" |
|
|
|
|
|
|
|
@ -18,18 +22,23 @@ class PosOrder(models.Model): |
|
|
): |
|
|
): |
|
|
order = self.search([("pos_reference", "=", pos_reference)]) |
|
|
order = self.search([("pos_reference", "=", pos_reference)]) |
|
|
if len(order) < 1: |
|
|
if len(order) < 1: |
|
|
return _("Error: no order found") |
|
|
|
|
|
|
|
|
_logger.error(_("Error: no order found")) |
|
|
|
|
|
return |
|
|
if order.email_receipt_sent: |
|
|
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: |
|
|
if not email and not order.partner_id and not order.partner_id.email: |
|
|
return _( |
|
|
|
|
|
|
|
|
_logger.error( |
|
|
|
|
|
_( |
|
|
"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") |
|
|
mail_template = self.env.ref("pos_mail_receipt.email_send_ticket") |
|
|
|
|
|
email_values = {} |
|
|
if email: |
|
|
if email: |
|
|
mail_template.email_to = email |
|
|
|
|
|
|
|
|
email_values["email_to"] = email |
|
|
else: |
|
|
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( |
|
|
base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf( |
|
|
[body_from_ui.encode("utf-16")], |
|
|
[body_from_ui.encode("utf-16")], |
|
|
landscape=False, |
|
|
landscape=False, |
|
@ -49,10 +58,9 @@ class PosOrder(models.Model): |
|
|
"res_id": order.id, |
|
|
"res_id": order.id, |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
email_values["attachment_ids"] = [attachment.id] |
|
|
mail_template.send_mail( |
|
|
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 |
|
|
order.email_receipt_sent = True |
|
|
|
|
|
|
|
|