From 3d0a714f5fc30de96e3b7baf127e2d7a12975859 Mon Sep 17 00:00:00 2001 From: RaghuGadam Date: Thu, 12 Sep 2019 11:50:03 +0200 Subject: [PATCH 01/13] [MIG]Migration to 12.0: email_pos_receipt --- pos_ticket_send_by_mail/README.rst | 34 ++ pos_ticket_send_by_mail/__init__.py | 6 + pos_ticket_send_by_mail/__manifest__.py | 27 ++ .../data/email_template_data.xml | 25 ++ pos_ticket_send_by_mail/data/ir_cron_data.xml | 16 + .../i18n/email_pos_receipt.pot | 105 ++++++ pos_ticket_send_by_mail/i18n/fr.po | 96 +++++ pos_ticket_send_by_mail/models/__init__.py | 8 + pos_ticket_send_by_mail/models/pos_order.py | 47 +++ .../models/res_config_settings.py | 45 +++ pos_ticket_send_by_mail/models/res_partner.py | 16 + .../security/ir.model.access.csv | 1 + .../static/src/js/pos_model.js | 24 ++ .../static/src/js/receipt_screen_widget.js | 47 +++ .../static/src/xml/templates.xml | 13 + pos_ticket_send_by_mail/tests/__init__.py | 2 + .../tests/test_pos_ticket_mail.py | 327 ++++++++++++++++++ .../views/report_paperformat.xml | 20 ++ .../views/report_receipt.xml | 105 ++++++ .../views/view_pos_config_settings.xml | 39 +++ .../views/view_res_partner.xml | 15 + 21 files changed, 1018 insertions(+) create mode 100644 pos_ticket_send_by_mail/README.rst create mode 100644 pos_ticket_send_by_mail/__init__.py create mode 100644 pos_ticket_send_by_mail/__manifest__.py create mode 100644 pos_ticket_send_by_mail/data/email_template_data.xml create mode 100644 pos_ticket_send_by_mail/data/ir_cron_data.xml create mode 100644 pos_ticket_send_by_mail/i18n/email_pos_receipt.pot create mode 100644 pos_ticket_send_by_mail/i18n/fr.po create mode 100644 pos_ticket_send_by_mail/models/__init__.py create mode 100644 pos_ticket_send_by_mail/models/pos_order.py create mode 100644 pos_ticket_send_by_mail/models/res_config_settings.py create mode 100644 pos_ticket_send_by_mail/models/res_partner.py create mode 100644 pos_ticket_send_by_mail/security/ir.model.access.csv create mode 100644 pos_ticket_send_by_mail/static/src/js/pos_model.js create mode 100644 pos_ticket_send_by_mail/static/src/js/receipt_screen_widget.js create mode 100644 pos_ticket_send_by_mail/static/src/xml/templates.xml create mode 100644 pos_ticket_send_by_mail/tests/__init__.py create mode 100644 pos_ticket_send_by_mail/tests/test_pos_ticket_mail.py create mode 100755 pos_ticket_send_by_mail/views/report_paperformat.xml create mode 100755 pos_ticket_send_by_mail/views/report_receipt.xml create mode 100644 pos_ticket_send_by_mail/views/view_pos_config_settings.xml create mode 100644 pos_ticket_send_by_mail/views/view_res_partner.xml diff --git a/pos_ticket_send_by_mail/README.rst b/pos_ticket_send_by_mail/README.rst new file mode 100644 index 0000000000..433d8c493c --- /dev/null +++ b/pos_ticket_send_by_mail/README.rst @@ -0,0 +1,34 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================= +POS Ticket Send By Mail +======================= + +This module allow to send the mail to customer from point of sale +base on configuration. + +Credits +======= + +Authors +~~~~~~~ + +* Druidoo + +Contributors +~~~~~~~~~~~~ + +* Iván Todorovich + +Maintainers +~~~~~~~~~~~ + +.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px + :target: https://github.com/ivantodorovich + :alt: ivantodorovich + +Current maintainer: + +|maintainer-ivantodorovich| diff --git a/pos_ticket_send_by_mail/__init__.py b/pos_ticket_send_by_mail/__init__.py new file mode 100644 index 0000000000..11e0198d26 --- /dev/null +++ b/pos_ticket_send_by_mail/__init__.py @@ -0,0 +1,6 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +from . import models diff --git a/pos_ticket_send_by_mail/__manifest__.py b/pos_ticket_send_by_mail/__manifest__.py new file mode 100644 index 0000000000..6eff25f9fa --- /dev/null +++ b/pos_ticket_send_by_mail/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +{ + 'name': 'POS Receipt By Email', + 'version': '12.0.1.0.0', + 'category': 'Custom', + 'author': 'Druidoo', + 'website': 'https://www.druidoo.io', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/report_paperformat.xml', + 'views/view_pos_config_settings.xml', + 'data/email_template_data.xml', + 'data/ir_cron_data.xml', + 'views/view_res_partner.xml', + 'views/report_receipt.xml', + 'static/src/xml/templates.xml', + ], + 'installable': True, +} diff --git a/pos_ticket_send_by_mail/data/email_template_data.xml b/pos_ticket_send_by_mail/data/email_template_data.xml new file mode 100644 index 0000000000..8d08912d32 --- /dev/null +++ b/pos_ticket_send_by_mail/data/email_template_data.xml @@ -0,0 +1,25 @@ + + + + + + Send Received + ticket@${object.user_id.company_id.email.split('@')[1] or ''|safe} + ${object.user_id.company_id.name} Received ${object.pos_reference.split(' ')[1]} + ${object.partner_id.id} + + + + Ticket ${object.pos_reference} + ${object.partner_id.lang} + Thank you for your visit !

+

You will find your receipt ${object.pos_reference.split(' ')[1]} attached.

+

Sincerely,

+

The team of the cooperative

+ ]]> +
+
+ +
+ diff --git a/pos_ticket_send_by_mail/data/ir_cron_data.xml b/pos_ticket_send_by_mail/data/ir_cron_data.xml new file mode 100644 index 0000000000..18d0c06cea --- /dev/null +++ b/pos_ticket_send_by_mail/data/ir_cron_data.xml @@ -0,0 +1,16 @@ + + + + + Send Reciept via Email + 1 + minutes + -1 + + + model._send_order_cron() + code + + + + diff --git a/pos_ticket_send_by_mail/i18n/email_pos_receipt.pot b/pos_ticket_send_by_mail/i18n/email_pos_receipt.pot new file mode 100644 index 0000000000..bfb61e15ef --- /dev/null +++ b/pos_ticket_send_by_mail/i18n/email_pos_receipt.pot @@ -0,0 +1,105 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_ticket_send_by_mail +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \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_ticket_send_by_mail +#: model:mail.template,body_html:pos_ticket_send_by_mail.email_send_pos_receipt +msgid "\n" +"

Thank you for your visit !

\n" +"

You will find your receipt ${object.pos_reference.split(' ')[1]} attached.

\n" +"

Sincerely,

\n" +"

The team of the cooperative

\n" +" " +msgstr "\n" +"

Merci de votre visite !

\n" +"

Vous trouverez votre reçu ${object.pos_reference.split(' ')[1]} en pièce-jointe.

\n" +"

Amicalement,

\n" +"

L'équipe de la coopérative

\n" +" " + +#. module: pos_ticket_send_by_mail +#: model:mail.template,subject:pos_ticket_send_by_mail.email_send_pos_receipt +msgid "${object.user_id.company_id.name} Received ${object.pos_reference.split(' ')[1]}" +msgstr "${object.user_id.company_id.name} Reçu ${object.pos_reference.split(' ')[1]}" + +#. module: pos_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "Do not Send" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Do not send receipt via email" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_res_partner_pos_ticket_send_by_mail +msgid "E-receipt" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Email receipt and print it" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Email receipt and print it unless configured on user that he only receives electronically" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,help:pos_ticket_send_by_mail.field_res_partner_pos_ticket_send_by_mail +msgid "If you tick this box and option 3 is selected for 'Receipt' in point of sale settings, the user will only receive e-receipt" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_res_partner +msgid "Partner" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_pos_order +msgid "Point of Sale" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_config_settings_receipt_options +msgid "Receipt" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_order_email_status +msgid "Send Status" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "Sent" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:mail.template,report_name:pos_ticket_send_by_mail.email_send_pos_receipt +msgid "Ticket ${object.pos_reference}" +msgstr "Billet ${object.pos_reference}" + +#. module: pos_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "To send" +msgstr "" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_pos_config_settings +msgid "pos.config.settings" +msgstr "" + diff --git a/pos_ticket_send_by_mail/i18n/fr.po b/pos_ticket_send_by_mail/i18n/fr.po new file mode 100644 index 0000000000..23e6847f7e --- /dev/null +++ b/pos_ticket_send_by_mail/i18n/fr.po @@ -0,0 +1,96 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_ticket_send_by_mail +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-08-17 09:04+0000\n" +"PO-Revision-Date: 2018-08-17 09:04+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_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "Do not Send" +msgstr "Do not Send" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_res_partner +msgid "Partner" +msgstr "Partenaire" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_pos_order +msgid "Point of Sale" +msgstr "Point de vente" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_config_is_print_receipt +msgid "Print receipt when not sent email" +msgstr "Ne pas imprimer de ticket s’il est envoyé par par email" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_order_email_status +msgid "Send Status" +msgstr "Send Status" + +#. module: pos_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "Sent" +msgstr "Sent" + +#. module: pos_ticket_send_by_mail +#: model:mail.template,report_name:pos_ticket_send_by_mail.email_send_pos_receipt +msgid "Ticket ${object.pos_reference}" +msgstr "Billet ${object.pos_reference}" + +#. module: pos_ticket_send_by_mail +#: selection:pos.order,email_status:0 +msgid "To send" +msgstr "To send" + +#. module: pos_ticket_send_by_mail +#: model:ir.model,name:pos_ticket_send_by_mail.model_pos_config +msgid "pos.config" +msgstr "pos.config" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_config_is_print_receipt +msgid "Print receipt when not sent email" +msgstr "Ne pas imprimer de ticket s’il est envoyé par par email" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_pos_config_settings_receipt_options +msgid "Receipt" +msgstr "Reçu" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Do not send receipt via email" +msgstr "Ne pas envoyer le reçu par email" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Email receipt and print it" +msgstr "Envoyer le reçu par email et l'imprimer" + +#. module: pos_ticket_send_by_mail +#: selection:pos.config.settings,receipt_options:0 +msgid "Email receipt and print it unless configured on user that he only receives electronically" +msgstr "Envoyer le reçu par email et l'imprimer sauf si ce partenaire est configuré pour recevoir uniquement le reçu électronique" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,help:pos_ticket_send_by_mail.field_res_partner_pos_ticket_send_by_mail +msgid "If you tick this box and option 3 is selected for 'Receipt' in point of sale settings, the user will only receive e-receipt" +msgstr "Si vous cochez cette case et que l'option 3 est sélectionnée dans la configuration générale du point de vente, ce partenaire recevra uniquement le reçu électronique" + +#. module: pos_ticket_send_by_mail +#: model:ir.model.fields,field_description:pos_ticket_send_by_mail.field_res_partner_pos_ticket_send_by_mail +msgid "E-receipt" +msgstr "Reçu électronique" diff --git a/pos_ticket_send_by_mail/models/__init__.py b/pos_ticket_send_by_mail/models/__init__.py new file mode 100644 index 0000000000..37a95e46ac --- /dev/null +++ b/pos_ticket_send_by_mail/models/__init__.py @@ -0,0 +1,8 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +from . import res_partner +from . import pos_order +from . import res_config_settings diff --git a/pos_ticket_send_by_mail/models/pos_order.py b/pos_ticket_send_by_mail/models/pos_order.py new file mode 100644 index 0000000000..e8b2080133 --- /dev/null +++ b/pos_ticket_send_by_mail/models/pos_order.py @@ -0,0 +1,47 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +from odoo import models, fields, api +import logging +_logger = logging.getLogger(__name__) + + +class PosOrder(models.Model): + + _inherit = 'pos.order' + + email_status = fields.Selection([ + ('no_send', 'Do not Send'), + ('to_send', 'To send'), + ('sent', 'Sent')], + default="no_send", string="Send Status") + + @api.model + def _send_order_cron(self): + _logger.info("------------------------------------------------------") + mail_template = self.env.ref( + "pos_ticket_send_by_mail.email_send_pos_receipt") + _logger.info("Start to send ticket") + for order in self.search([('email_status', '=', 'to_send')]): + mail_template.send_mail(order.id, force_send=True) + order.email_status = 'sent' + # Make sure we commit the change to not send ticket twice + self.env.cr.commit() + + @api.multi + def action_pos_order_paid(self): + # Send e-receipt for the partner. + # It depends on value of the field `receipt_option` + # that we config in pos.config.settings + # receipt_option = 1: Don't send e-receipt + # receipt_option = 2 or 3: Send e-receipt + res = super(PosOrder, self).action_pos_order_paid() + icp_sudo = self.env['ir.config_parameter'].sudo() + receipt_options = icp_sudo.get_param('point_of_sale.receipt_options') + receipt_options = receipt_options and int(receipt_options) or False + for order in self: + if receipt_options in [2, 3] and order.partner_id.email: + order.email_status = 'to_send' + return res diff --git a/pos_ticket_send_by_mail/models/res_config_settings.py b/pos_ticket_send_by_mail/models/res_config_settings.py new file mode 100644 index 0000000000..0d98727eaa --- /dev/null +++ b/pos_ticket_send_by_mail/models/res_config_settings.py @@ -0,0 +1,45 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +from odoo import models, fields, api + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + receipt_options = fields.Selection( + [ + ('1', 'Do not send receipt via email'), + ('2', 'Email receipt and print it'), + ('3', 'Email receipt and print it unless configured on user that \ + he only receives electronically') + ], string="Receipt", + config_parameter='point_of_sale.receipt_options' + ) + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + icp_sudo = self.env['ir.config_parameter'].sudo() + receipt_options = icp_sudo.get_param('point_of_sale.receipt_options') + res.update( + receipt_options=receipt_options + ) + return res + + @api.model + def get_default_receipt_options(self): + receipt_options = self.env['ir.values'].get_default( + 'res.config.settings', 'receipt_options') + return { + 'receipt_options': receipt_options, + } + + @api.multi + def set_default_receipt_options(self): + self.ensure_one() + return self.env['ir.values'].sudo().set_default( + 'res.config.settings', 'receipt_options', + self.receipt_options or None) diff --git a/pos_ticket_send_by_mail/models/res_partner.py b/pos_ticket_send_by_mail/models/res_partner.py new file mode 100644 index 0000000000..d913468c25 --- /dev/null +++ b/pos_ticket_send_by_mail/models/res_partner.py @@ -0,0 +1,16 @@ +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + email_pos_receipt = fields.Boolean( + string="E-receipt", + default=False, + help="If you tick this box and option 3 is selected for 'Receipt'\ + in point of sale settings, the user will only receive e-receipt ") diff --git a/pos_ticket_send_by_mail/security/ir.model.access.csv b/pos_ticket_send_by_mail/security/ir.model.access.csv new file mode 100644 index 0000000000..97dd8b917b --- /dev/null +++ b/pos_ticket_send_by_mail/security/ir.model.access.csv @@ -0,0 +1 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink diff --git a/pos_ticket_send_by_mail/static/src/js/pos_model.js b/pos_ticket_send_by_mail/static/src/js/pos_model.js new file mode 100644 index 0000000000..82e76384e8 --- /dev/null +++ b/pos_ticket_send_by_mail/static/src/js/pos_model.js @@ -0,0 +1,24 @@ +/* +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +*/ + +odoo.define('pos_ticket_send_by_mail.pos_model', function (require) { + "use strict"; + var pos_model = require('point_of_sale.models'); + pos_model.load_fields("res.partner", "email_pos_receipt"); + pos_model.load_models([{ + model: "res.config.settings", + fields: ["receipt_options"], + loaded: function(self, config_settings){ + const config_setting = config_settings.length > 0 ? config_settings.reduce(function(prev, current) { + return (prev.id > current.id) ? prev : current + }) : false; //returns object + self.config_settings = config_setting; + } + }]); + +}); diff --git a/pos_ticket_send_by_mail/static/src/js/receipt_screen_widget.js b/pos_ticket_send_by_mail/static/src/js/receipt_screen_widget.js new file mode 100644 index 0000000000..6fa0622394 --- /dev/null +++ b/pos_ticket_send_by_mail/static/src/js/receipt_screen_widget.js @@ -0,0 +1,47 @@ +/* + +# Copyright (C) 2016-Today: La Louve () +# Copyright (C) 2019-Today: Druidoo () +# @author: La Louve +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html + +*/ + +odoo.define('pos_ticket_send_by_mail.receipt_screen_widget', function (require) { + + "use strict"; + var models = require('point_of_sale.models'); + var screens = require('point_of_sale.screens'); + var core = require('web.core'); + var gui = require('point_of_sale.gui'); + var _t = core._t; + + screens.ReceiptScreenWidget.include({ + + print_web: function() { + var client = this.pos.get_client(); + var email_pos_receipt = client ? client.email_pos_receipt: false; + var receipt_options = this.pos.config_settings ? this.pos.config_settings.receipt_options : false; + if (receipt_options && receipt_options == '3' && email_pos_receipt) { + console.log("Skip print receipt by web"); + return + } else { + console.log("1 print receipt by web"); + return this._super(); + } + }, + + print_xml: function() { + var client = this.pos.get_client(); + var email_pos_receipt = client ? client.email_pos_receipt: false; + var receipt_options = this.pos.config_settings ? this.pos.config_settings.receipt_options : false; + if (receipt_options && receipt_options == '3' && email_pos_receipt) { + console.log("Skip print receipt by web"); + return + } else { + console.log(" print receipt by web"); + return this._super(); + } + }, + }); +}); diff --git a/pos_ticket_send_by_mail/static/src/xml/templates.xml b/pos_ticket_send_by_mail/static/src/xml/templates.xml new file mode 100644 index 0000000000..50bcca4be7 --- /dev/null +++ b/pos_ticket_send_by_mail/static/src/xml/templates.xml @@ -0,0 +1,13 @@ + + + +