Browse Source

Merge 0db5ba89bb into 45a15ac568

pull/428/merge
Pierrick Brun (Akretion) 4 years ago
committed by GitHub
parent
commit
8ebf3602c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .travis.yml
  2. 86
      pos_mail_receipt/README.rst
  3. 1
      pos_mail_receipt/__init__.py
  4. 14
      pos_mail_receipt/__manifest__.py
  5. 19
      pos_mail_receipt/data/email.xml
  6. 131
      pos_mail_receipt/i18n/fr.po
  7. 122
      pos_mail_receipt/i18n/pos_mail_receipt.pot
  8. 1
      pos_mail_receipt/models/__init__.py
  9. 86
      pos_mail_receipt/models/pos_order.py
  10. 3
      pos_mail_receipt/readme/CONTRIBUTORS.rst
  11. 5
      pos_mail_receipt/readme/DESCRIPTION.rst
  12. 3
      pos_mail_receipt/readme/USAGE.rst
  13. BIN
      pos_mail_receipt/static/description/icon.png
  14. 434
      pos_mail_receipt/static/description/index.html
  15. 3
      pos_mail_receipt/static/src/css/pos.css
  16. 129
      pos_mail_receipt/static/src/css/print.css
  17. 102
      pos_mail_receipt/static/src/js/screens.js
  18. 13
      pos_mail_receipt/static/src/xml/pos.xml
  19. 20
      pos_mail_receipt/templates/assets.xml
  20. 1
      pos_mail_receipt/tests/__init__.py
  21. 104
      pos_mail_receipt/tests/test_module.py

1
.travis.yml

@ -13,6 +13,7 @@ addons:
apt:
packages:
- expect-dev # provides unbuffer utility
- wkhtmltopdf
env:
global:

86
pos_mail_receipt/README.rst

@ -0,0 +1,86 @@
================
Pos Mail Receipt
================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github
:target: https://github.com/OCA/pos/tree/12.0/pos_mail_receipt
:alt: OCA/pos
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_mail_receipt
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/184/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This modules allows you to send the PoS receipt by e-mail.
Instead of printing the ticket you can choose to send it be e-mail.
If you know the customer's e-mail, it will use it.
If not you will be prompted for it.
**Table of contents**
.. contents::
:local:
Usage
=====
#. Open a new PoS session.
#. Make an order and validate it.
#. You should see the company logo in the receipt preview.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pos/issues/new?body=module:%20pos_mail_receipt%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Coop IT Easy SCRLfs
Contributors
~~~~~~~~~~~~
* `Coop IT Easy SCRLfs <https://coopiteasy.be>`_:
* Pierrick Brun
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/pos <https://github.com/OCA/pos/tree/12.0/pos_mail_receipt>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

1
pos_mail_receipt/__init__.py

@ -0,0 +1 @@
from . import models

14
pos_mail_receipt/__manifest__.py

@ -0,0 +1,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Pos Mail Receipt",
"category": "Point Of Sale",
"version": "12.0.1.0.0",
"author": "Coop IT Easy SCRLfs, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
"depends": ["point_of_sale"],
"data": ["templates/assets.xml", "data/email.xml"],
"qweb": ["static/src/xml/pos.xml"],
"installable": True,
}

19
pos_mail_receipt/data/email.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">
<!--Email template -->
<record id="email_send_ticket" model="mail.template">
<field name="name">Send Receipt</field>
<field name="email_from">${(object.user_id.email and '%s &lt;%s&gt;' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
<field name="subject">${object.pos_reference}</field>
<field name="model_id" ref="point_of_sale.model_pos_order" />
<field name="auto_delete" eval="True" />
<field name="lang">${object.partner_id.lang}</field>
<field name="body_html"><![CDATA[
Your Ticket ${object.pos_reference}
]]></field>
</record>
</data>
</odoo>

131
pos_mail_receipt/i18n/fr.po

@ -0,0 +1,131 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_mail_receipt
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-17 14:32+0000\n"
"PO-Revision-Date: 2019-12-17 15:38+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 2.2.4\n"
"Last-Translator: \n"
"Language: fr\n"
#. module: pos_mail_receipt
#: model:mail.template,subject:pos_mail_receipt.email_send_ticket
msgid "${object.pos_reference}"
msgstr ""
#. module: pos_mail_receipt
#: model:mail.template,body_html:pos_mail_receipt.email_send_ticket
msgid ""
"<p style=\"margin:0px 0 1rem 0;font-size:13px;font-family:&quot;Lucida "
"Grande&quot;, Helvetica, Verdana, Arial, sans-serif;\">\n"
"Your Ticket ${object.pos_reference}\n"
" </p>"
msgstr ""
"<p style=\"margin:0px 0 1rem 0;font-size:13px;font-family:&quot;Lucida "
"Grande&quot;, Helvetica, Verdana, Arial, sans-serif;\">\n"
"Votre Ticket ${object.pos_reference}\n"
" </p>"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:25
#, python-format
msgid "Cancel"
msgstr "Annuler"
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:25
#, python-format
msgid "Cannot send the ticket, no email address found for the client"
msgstr ""
"Impossible d'envoyer le ticket, pas d'adresse mail trouvée pour le "
"client"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:82
#, python-format
msgid "Check your internet connection and try again."
msgstr "Vérifiez votre connexion internet et essayez à nouveau."
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:22
#, python-format
msgid "Confirm"
msgstr "Confirmer"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:28
#, python-format
msgid "E-mail address to use"
msgstr "Adresse mail à utiliser"
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:23
#, python-format
msgid "E-mail already sent"
msgstr "E-mail déjà envoyé"
#. module: pos_mail_receipt
#: model:ir.model.fields,field_description:pos_mail_receipt.field_pos_order__email_receipt_sent
msgid "Email Receipt Sent"
msgstr "Reçu envoyé"
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:21
#, python-format
msgid "Error: no order found"
msgstr "Erreur: pas de commande trouvée"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:19
#, python-format
msgid "Mail"
msgstr "Mail"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:8
#, python-format
msgid "Mail Receipt"
msgstr "Reçu"
#. module: pos_mail_receipt
#: model:ir.model,name:pos_mail_receipt.model_pos_order
msgid "Point of Sale Orders"
msgstr "Commandes du point de vente"
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:44
#, python-format
msgid "Receipt_{}.pdf"
msgstr "Recu_{}.pdf"
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:81
#, python-format
msgid "The e-mail could not be sent"
msgstr "L'e-mail n'a pas pu être envoyé"
#. module: pos_mail_receipt
#: model:mail.template,report_name:pos_mail_receipt.email_send_ticket
msgid "Ticket ${object.pos_reference}"
msgstr "Ticket ${object.pos_reference}"
#. module: pos_mail_receipt
#: model:ir.model,name:pos_mail_receipt.model_report_pos_mail_receipt_pos_receipt_report
msgid "report.pos_mail_receipt.pos_receipt_report"
msgstr ""

122
pos_mail_receipt/i18n/pos_mail_receipt.pot

@ -0,0 +1,122 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_mail_receipt
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-17 14:32+0000\n"
"PO-Revision-Date: 2019-12-17 14:32+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: pos_mail_receipt
#: model:mail.template,subject:pos_mail_receipt.email_send_ticket
msgid "${object.pos_reference}"
msgstr ""
#. module: pos_mail_receipt
#: model:mail.template,body_html:pos_mail_receipt.email_send_ticket
msgid "<p style=\"margin:0px 0 1rem 0;font-size:13px;font-family:&quot;Lucida Grande&quot;, Helvetica, Verdana, Arial, sans-serif;\">\n"
"Your Ticket ${object.pos_reference}\n"
" </p>"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:25
#, python-format
msgid "Cancel"
msgstr ""
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:25
#, python-format
msgid "Cannot send the ticket, no email address found for the client"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:82
#, python-format
msgid "Check your internet connection and try again."
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:22
#, python-format
msgid "Confirm"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:28
#, python-format
msgid "E-mail address to use"
msgstr ""
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:23
#, python-format
msgid "E-mail already sent"
msgstr ""
#. module: pos_mail_receipt
#: model:ir.model.fields,field_description:pos_mail_receipt.field_pos_order__email_receipt_sent
msgid "Email Receipt Sent"
msgstr ""
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:21
#, python-format
msgid "Error: no order found"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:19
#, python-format
msgid "Mail"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/xml/pos.xml:8
#, python-format
msgid "Mail Receipt"
msgstr ""
#. module: pos_mail_receipt
#: model:ir.model,name:pos_mail_receipt.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_mail_receipt
#: code:addons/pos_mail_receipt/models/pos_order.py:44
#, python-format
msgid "Receipt_{}.pdf"
msgstr ""
#. module: pos_mail_receipt
#. openerp-web
#: code:addons/pos_mail_receipt/static/src/js/screens.js:81
#, python-format
msgid "The e-mail could not be sent"
msgstr ""
#. module: pos_mail_receipt
#: model:mail.template,report_name:pos_mail_receipt.email_send_ticket
msgid "Ticket ${object.pos_reference}"
msgstr ""
#. module: pos_mail_receipt
#: model:ir.model,name:pos_mail_receipt.model_report_pos_mail_receipt_pos_receipt_report
msgid "report.pos_mail_receipt.pos_receipt_report"
msgstr ""

1
pos_mail_receipt/models/__init__.py

@ -0,0 +1 @@
from . import pos_order

86
pos_mail_receipt/models/pos_order.py

@ -0,0 +1,86 @@
# Copyright 2019 Coop IT Easy SCRLfs
# @author Pierrick Brun <pierrick.brun@akretion.com>
# 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"
email_receipt_sent = fields.Boolean()
@api.model
def send_mail_receipt(
self, pos_reference, email, body_from_ui, force=True
):
order = self.search([("pos_reference", "=", pos_reference)])
if len(order) < 1:
_logger.error(_("Error: no order found"))
return
if order.email_receipt_sent:
_logger.info(_("E-mail already sent"))
return
if not email and not order.partner_id and not order.partner_id.email:
_logger.error(
_(
"Cannot send the ticket, "
"no email address found for the client"
)
)
email_values = {}
if email:
email_values["email_to"] = email
else:
email_values["email_to"] = order.partner_id.email
receipt = (
"<main><div class='article'><div class='pos'>"
"<div class='pos-receipt-container'>"
"{}</div></div></div></main>".format(body_from_ui)
)
bodies, html_ids, header, footer, specific_paperformat_args = self.env[
"ir.actions.report"
]._prepare_html(receipt)
base64_pdf = self.env["ir.actions.report"]._run_wkhtmltopdf(
bodies,
landscape=False,
specific_paperformat_args=specific_paperformat_args,
)
attachment = self.env["ir.attachment"].create(
{
"name": pos_reference,
"datas_fname": _("Receipt_{}.pdf".format(pos_reference)),
"type": "binary",
"mimetype": "application/x-pdf",
"db_datas": base64.encodestring(base64_pdf),
"res_model": "pos.order",
"res_id": order.id,
}
)
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,
)
order.email_receipt_sent = True
@api.model
def create_from_ui(self, orders):
res = super(PosOrder, self).create_from_ui(orders)
for order in orders:
if "email" in order["data"]:
self.send_mail_receipt(
order["data"]["name"],
order["data"]["email"],
order["data"]["body_from_ui"],
force=False,
)
return res

3
pos_mail_receipt/readme/CONTRIBUTORS.rst

@ -0,0 +1,3 @@
* `Coop IT Easy SCRLfs <https://coopiteasy.be>`_:
* Pierrick Brun

5
pos_mail_receipt/readme/DESCRIPTION.rst

@ -0,0 +1,5 @@
This modules allows you to send the PoS receipt by e-mail.
Instead of printing the ticket you can choose to send it be e-mail.
If you know the customer's e-mail, it will use it.
If not you will be prompted for it.

3
pos_mail_receipt/readme/USAGE.rst

@ -0,0 +1,3 @@
#. Open a new PoS session.
#. Make an order and validate it.
#. You should see the company logo in the receipt preview.

BIN
pos_mail_receipt/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.3 KiB

434
pos_mail_receipt/static/description/index.html

@ -0,0 +1,434 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Pos Mail Receipt</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="pos-mail-receipt">
<h1 class="title">Pos Mail Receipt</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pos/tree/12.0/pos_mail_receipt"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_mail_receipt"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/184/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This modules allows you to send the PoS receipt by e-mail.</p>
<p>Instead of printing the ticket you can choose to send it be e-mail.
If you know the customer’s e-mail, it will use it.
If not you will be prompted for it.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<ol class="arabic simple">
<li>Open a new PoS session.</li>
<li>Make an order and validate it.</li>
<li>You should see the company logo in the receipt preview.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pos/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/pos/issues/new?body=module:%20pos_mail_receipt%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://coopiteasy.be">Coop IT Easy SCRLfs</a>:<ul>
<li>Pierrick Brun</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pos/tree/12.0/pos_mail_receipt">OCA/pos</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

3
pos_mail_receipt/static/src/css/pos.css

@ -0,0 +1,3 @@
.pos .modal-dialog .popup-textinput input{
margin-left: 10%
}

129
pos_mail_receipt/static/src/css/print.css

@ -0,0 +1,129 @@
/* This is a copy of the pos receipt screen CSS
* This allows to use it in the backend */
.pos .receipt-screen .centered-content .button {
line-height: 40px;
padding: 3px 13px;
font-size: 20px;
text-align: center;
background: rgb(230, 230, 230);
margin: 16px;
margin-bottom: 0px;
border-radius: 3px;
border: solid 1px rgb(209, 209, 209);
cursor: pointer;
}
.pos .pos-receipt-container {
font-size: 0.75em;
text-align: center;
direction: ltr;
}
.pos .pos-sale-ticket {
text-align: left;
width: 300px;
background-color: white;
margin: 20px;
padding: 15px;
font-size: 14px;
padding-bottom:30px;
display: inline-block;
font-family: "Inconsolata";
border: solid 1px rgb(220,220,220);
border-radius: 3px;
overflow: hidden;
}
.pos .pos-sale-ticket pre{
font-family: "Inconsolata";
}
.pos .pos-sale-ticket .emph{
font-size: 20px;
margin:5px;
}
.pos .pos-sale-ticket table {
width: 100%;
border: 0;
table-layout: fixed;
}
.pos .pos-sale-ticket table td {
border: 0;
word-wrap: break-word;
}
@page {
margin: 0;
}
@media print {
* {
color: black !important;
}
body {
margin: 0;
color: white !important;
/* avoid black background if backgrounds are printed */
background: initial;
}
.oe_leftbar,
.oe_loading,
.pos .pos-topheader,
.pos .pos-leftpane,
.pos .keyboard_frame,
.pos .receipt-screen header,
.pos .receipt-screen .top-content,
.pos .receipt-screen .centered-content .button {
display: none !important;
}
.pos,
.pos .pos-content,
.pos .rightpane,
.pos .screen,
.pos .window,
.pos .window .subwindow,
.pos .subwindow .subwindow-container{
display: block;
position: static;
height: auto;
}
.pos{
background: white !important;
}
.pos .rightpane {
left: 0px !important;
background-color: white;
}
.pos .receipt-screen {
text-align: left;
}
.pos .receipt-screen .centered-content{
position: static;
border: none;
}
.pos .pos-receipt-container {
text-align: left;
}
.pos-actionbar {
display: none !important;
}
.debug-widget{
display: none !important;
}
.pos *{
text-shadow: none !important;
box-shadow: none !important;
background: transparent !important;
}
.pos .pos-sale-ticket{
margin: 0;
margin-left: auto !important;
margin-right: auto !important;
border: none !important;
font-size: 13px !important;
width: 266px !important;
}
.o_debug_manager {
display: none !important;
}
.o_chat_window {
display: none !important;
}
}

102
pos_mail_receipt/static/src/js/screens.js

@ -0,0 +1,102 @@
/* License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
odoo.define("pos_mail_receipt.screens", function (require) {
"use strict";
var screens = require('point_of_sale.screens');
var rpc = require('web.rpc');
var core = require('web.core');
var _t = core._t;
var ReceiptScreenWidget = screens.ReceiptScreenWidget.include({
renderElement: function() {
this._super();
var self = this;
this.$('.button.email').click(function(){
if (!self._locked) {
self.email();
}
});
},
click_next: function() {
this._super();
this.$('.button.email').removeClass("highlight");
},
email: function() {
var self = this;
var email = false;
var body_from_ui = this.$('.pos-receipt-container').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});
} else {
this.gui.show_popup('textinput', {
'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});
}
});
}
},
// ask the server to send the ticket as e-mail
// available options:
// - timeout: timeout for the rpc call in ms
// - email: email to use instead of the partner's
// returns a deferred
_send_email_server: async function (order, options) {
var self = this;
options = options || {};
var timeout = typeof options.timeout === 'number' ? options.timeout : 7500;
this.$('.button.email').addClass("highlight");
while (self.pos.get("synch").state == "connecting") {
await sleep(1000);
}
return rpc.query({
model: 'pos.order',
method: 'send_mail_receipt',
args: [order, options["email"], options["body_from_ui"]],
}, {
timeout: timeout,
})
.then(function (result) {
return true
}).fail(function (type, error){
var connection_problem = true;
for (var i = 0; i < self.pos.db.get_orders().length; i++) {
if (order == self.pos.db.get_orders()[i].data.name) {
self.pos.db.get_orders()[i].data["email"] = options["email"] || false;
self.pos.db.get_orders()[i].data["body_from_ui"] = options["body_from_ui"] || false;
connection_problem = false;
}
}
if(error.code === 200 ){
// Business Logic Error, not a connection problem
//if warning do not need to display traceback!!
if (error.data.exception_type == 'warning') {
delete error.data.debug;
}
self.gui.show_popup('error-traceback',{
'title': error.data.message,
'body': error.data.debug
});
self.$('.button.email').removeClass("highlight");
}
if(connection_problem){
self.gui.show_popup('error',{
'title': _t('The e-mail could not be sent'),
'body': _t('The e-mail could not be sent to ') + options["email"] + _t('. Check your internet connection and try again.'),
});
self.$('.button.email').removeClass("highlight");
}
});
},
});
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

13
pos_mail_receipt/static/src/xml/pos.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ReceiptScreenWidget">
<t t-jquery=".button.print" t-operation="after">
<div class="button email">
<i class='fa fa-at'></i> Mail Receipt
</div>
</t>
</t>
</templates>

20
pos_mail_receipt/templates/assets.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr=".">
<link href="/pos_mail_receipt/static/src/css/pos.css" rel="stylesheet"/>
<script
type="text/javascript"
src="/pos_mail_receipt/static/src/js/screens.js"/>
</xpath>
</template>
<template id="report_assets_pdf" inherit_id="web.report_assets_pdf">
<xpath expr=".">
<link href="/pos_mail_receipt/static/src/css/print.css" rel="stylesheet"/>
</xpath>
</template>
</odoo>

1
pos_mail_receipt/tests/__init__.py

@ -0,0 +1 @@
from . import test_module

104
pos_mail_receipt/tests/test_module.py

@ -0,0 +1,104 @@
# Copyright 2019 Akretion (https://www.akretion.com).
# @author Pierrick Brun <pierrick.brun@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests.common import TransactionCase
class TestModule(TransactionCase):
def setUp(self):
super(TestModule, self).setUp()
self.PosOrder = self.env["pos.order"]
self.pos_product = self.env.ref("point_of_sale.whiteboard_pen")
self.pricelist = self.env.ref("product.list0")
# Create a new pos config and open it
self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
self.pos_config.open_session_cb()
def test_mail_before_order(self):
order = self._create_order(email="test_mail@example.org.tst")
self.assertSent(order)
def test_mail_after_order(self):
order = self._create_order()
self.env["pos.order"].send_mail_receipt(
order.pos_reference,
"test_mail@example.org.tst",
"<p>Receipt's HTML</p>",
force=False,
)
self.assertSent(order)
self.env["pos.order"].send_mail_receipt(
order.pos_reference,
"test_mail@example.org.tst",
"<p>Receipt's HTML</p>",
force=False,
)
self.assertSent(order)
def assertSent(self, order):
mail = self.env["mail.mail"].search(
[("model", "=", "pos.order"), ("res_id", "=", order.id)]
)
self.assertEqual(1, len(mail))
self.assertEqual("test_mail@example.org.tst", mail.email_to)
self.assertEqual(1, len(mail.attachment_ids))
def _create_order(self, email=False):
# Create order
account = self.env.user.partner_id.property_account_receivable_id
statement_ids = self.pos_config.current_session_id.statement_ids
order_data = {
"id": u"0006-001-0010",
"to_invoice": False,
"data": {
"pricelist_id": self.pricelist.id,
"user_id": 1,
"name": "Order 0006-001-0010",
"partner_id": False,
"amount_paid": 0.9,
"pos_session_id": self.pos_config.current_session_id.id,
"lines": [
[
0,
0,
{
"product_id": self.pos_product.id,
"price_unit": self.pos_product.list_price,
"qty": 10,
"price_subtotal": 18.0,
"price_subtotal_incl": 18.0,
},
]
],
"statement_ids": [
[
0,
0,
{
"journal_id": self.pos_config.journal_ids[0].id,
"amount": 18.0,
"name": fields.Datetime.now(),
"account_id": account.id,
"statement_id": statement_ids[0].id,
},
]
],
"creation_date": u"2018-09-27 15:51:03",
"amount_tax": 0,
"fiscal_position_id": False,
"uid": u"00001-001-0001",
"amount_return": 0,
"sequence_number": 1,
"amount_total": 18.0,
},
}
if email:
order_data["data"]["email"] = email
order_data["data"]["body_from_ui"] = "<p>Receipt's HTML</p>"
result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
return order
Loading…
Cancel
Save