diff --git a/pos_invoice_send_mail/__init__.py b/pos_invoice_send_mail/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_invoice_send_mail/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_invoice_send_mail/__manifest__.py b/pos_invoice_send_mail/__manifest__.py new file mode 100644 index 00000000..57be5d24 --- /dev/null +++ b/pos_invoice_send_mail/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2019 Druidoo - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + 'name': 'POS Invoice Send by Mail', + 'summary': 'Send invoices by email from the POS', + 'version': '12.0.1.0.0', + 'category': 'Point of Sale', + 'author': 'Druidoo, ' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/pos', + 'license': 'AGPL-3', + 'maintainers': [ + 'ivantodorovich', + ], + 'depends': [ + 'point_of_sale', + 'mail', + ], + 'data': [ + 'views/assets.xml', + 'views/pos_config.xml', + ], + 'qweb': [ + 'static/src/xml/pos.xml', + ], +} diff --git a/pos_invoice_send_mail/i18n/fr.po b/pos_invoice_send_mail/i18n/fr.po new file mode 100644 index 00000000..909c0f6d --- /dev/null +++ b/pos_invoice_send_mail/i18n/fr.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_order_mail +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-07-24 14:27+0000\n" +"PO-Revision-Date: 2019-07-24 14:27+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_invoice_send_mail +#: model_terms:ir.ui.view,arch_db:pos_invoice_send_mail.pos_config_view_form +msgid "Email Template" +msgstr "Modèle de courriel" + +#. module: pos_invoice_send_mail +#: model:ir.model.fields,field_description:pos_invoice_send_mail.field_pos_config__invoice_mail_template_id +#, fuzzy +msgid "Invoice Email Template" +msgstr "Modèle de courriel" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/js/screens.js:48 +#, python-format +msgid "Please fill the customer email" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model,name:pos_invoice_send_mail.model_pos_config +msgid "Point of Sale Configuration" +msgstr "Paramétrage du point de vente" + +#. module: pos_invoice_send_mail +#: model:ir.model,name:pos_invoice_send_mail.model_pos_order +msgid "Point of Sale Orders" +msgstr "Commandes du point de vente" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/xml/pos.xml:8 +#, python-format +msgid "Send Invoice by Email" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model.fields,field_description:pos_invoice_send_mail.field_pos_config__iface_invoice_mail +msgid "Send Invoice by Mail" +msgstr "" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/js/screens.js:49 +#, python-format +msgid "You need to complete the customer email in order to send it." +msgstr "" diff --git a/pos_invoice_send_mail/i18n/pos_invoice_send_mail.pot b/pos_invoice_send_mail/i18n/pos_invoice_send_mail.pot new file mode 100644 index 00000000..c175f0d0 --- /dev/null +++ b/pos_invoice_send_mail/i18n/pos_invoice_send_mail.pot @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_invoice_send_mail +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\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_invoice_send_mail +#: model_terms:ir.ui.view,arch_db:pos_invoice_send_mail.pos_config_view_form +msgid "Email Template" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model.fields,field_description:pos_invoice_send_mail.field_pos_config__invoice_mail_template_id +msgid "Invoice Email Template" +msgstr "" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/js/screens.js:48 +#, python-format +msgid "Please fill the customer email" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model,name:pos_invoice_send_mail.model_pos_config +msgid "Point of Sale Configuration" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model,name:pos_invoice_send_mail.model_pos_order +msgid "Point of Sale Orders" +msgstr "" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/xml/pos.xml:8 +#, python-format +msgid "Send Invoice by Email" +msgstr "" + +#. module: pos_invoice_send_mail +#: model:ir.model.fields,field_description:pos_invoice_send_mail.field_pos_config__iface_invoice_mail +msgid "Send Invoice by Mail" +msgstr "" + +#. module: pos_invoice_send_mail +#. openerp-web +#: code:addons/pos_invoice_send_mail/static/src/js/screens.js:49 +#, python-format +msgid "You need to complete the customer email in order to send it." +msgstr "" + diff --git a/pos_invoice_send_mail/models/__init__.py b/pos_invoice_send_mail/models/__init__.py new file mode 100644 index 00000000..7723e42a --- /dev/null +++ b/pos_invoice_send_mail/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_order +from . import pos_config diff --git a/pos_invoice_send_mail/models/pos_config.py b/pos_invoice_send_mail/models/pos_config.py new file mode 100644 index 00000000..596c6ea2 --- /dev/null +++ b/pos_invoice_send_mail/models/pos_config.py @@ -0,0 +1,21 @@ +# Copyright 2019 Druidoo - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class PosConfig(models.Model): + _inherit = 'pos.config' + + iface_invoice_mail = fields.Boolean('Send Invoice by Mail') + + invoice_mail_template_id = fields.Many2one( + 'mail.template', + string='Invoice Email Template', + domain=[('model', '=', 'account.invoice')], + context=lambda self: { + 'default_model_id': self.ref('account.model_account_invoice').id, + }, + default=lambda self: + self.env.ref('account.email_template_edi_invoice', False), + ) diff --git a/pos_invoice_send_mail/models/pos_order.py b/pos_invoice_send_mail/models/pos_order.py new file mode 100644 index 00000000..0c2de22f --- /dev/null +++ b/pos_invoice_send_mail/models/pos_order.py @@ -0,0 +1,31 @@ +# Copyright 2019 Druidoo - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class PosOrder(models.Model): + _inherit = 'pos.order' + + @api.model + def create_from_ui(self, orders): + """ Inherit method to send by email """ + order_ids = super().create_from_ui(orders) + refs_to_send_mail = [ + o['data']['name'] for o in orders + if o['data'].get('to_send_mail') + ] + # Identify orders to send email + for order in self.browse(order_ids): + if ( + order.config_id.iface_invoice_mail + and order.config_id.invoice_mail_template_id + and order.invoice_id + and not order.invoice_id.sent + and order.pos_reference in refs_to_send_mail + ): + invoice_id = order.invoice_id.with_context( + mark_invoice_as_sent=True) + invoice_id.message_post_with_template( + order.config_id.invoice_mail_template_id.id) + return order_ids diff --git a/pos_invoice_send_mail/readme/CONFIGURE.rst b/pos_invoice_send_mail/readme/CONFIGURE.rst new file mode 100644 index 00000000..37e49f9f --- /dev/null +++ b/pos_invoice_send_mail/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +Go to *Point of Sale > Configuration > Point of Sale* and +enable **Send Invoice by Mail** + +.. image:: ../static/description/invoice-mail-config.png diff --git a/pos_invoice_send_mail/readme/CONTRIBUTORS.rst b/pos_invoice_send_mail/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..7bf6c777 --- /dev/null +++ b/pos_invoice_send_mail/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Druidoo `_: + + * Iván Todorovich diff --git a/pos_invoice_send_mail/readme/DESCRIPTION.rst b/pos_invoice_send_mail/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c4b6ffdb --- /dev/null +++ b/pos_invoice_send_mail/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Allows to send the invoice by email, from the POS. diff --git a/pos_invoice_send_mail/readme/USAGE.rst b/pos_invoice_send_mail/readme/USAGE.rst new file mode 100644 index 00000000..a739b0f3 --- /dev/null +++ b/pos_invoice_send_mail/readme/USAGE.rst @@ -0,0 +1,6 @@ +On the POS payment screen, you'll find a *Send Invoice by Email* button. + +.. image:: ../static/description/invoice-mail-screen.png + +If checked, an email will be send to the customer when the invoice +is validated. diff --git a/pos_invoice_send_mail/static/description/invoice-mail-config.png b/pos_invoice_send_mail/static/description/invoice-mail-config.png new file mode 100644 index 00000000..0c5cf02d Binary files /dev/null and b/pos_invoice_send_mail/static/description/invoice-mail-config.png differ diff --git a/pos_invoice_send_mail/static/description/invoice-mail-screen.png b/pos_invoice_send_mail/static/description/invoice-mail-screen.png new file mode 100644 index 00000000..f5f2ef79 Binary files /dev/null and b/pos_invoice_send_mail/static/description/invoice-mail-screen.png differ diff --git a/pos_invoice_send_mail/static/src/js/models.js b/pos_invoice_send_mail/static/src/js/models.js new file mode 100644 index 00000000..2b5178e3 --- /dev/null +++ b/pos_invoice_send_mail/static/src/js/models.js @@ -0,0 +1,46 @@ +/* Copyright 2019 Druidoo - Iván Todorovich + License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +odoo.define('pos_invoice_send_mail.models', function (require) { + "use strict"; + + var models = require('point_of_sale.models'); + + + var PosModelSuper = models.PosModel.prototype; + models.PosModel = models.PosModel.extend({ + push_and_invoice_order: function(order) { + var client = order.get_client() + if (order.is_to_send_mail() && client && !client.email) { + var res = new $.Deferred(); + res.reject({code:400, message:'Missing Customer Email', data:{}}); + return res; + } + return PosModelSuper.push_and_invoice_order.apply(this, arguments); + }, + }); + + + var OrderSuper = models.Order.prototype; + models.Order = models.Order.extend({ + initialize: function(attributes, options) { + OrderSuper.initialize.apply(this, arguments); + this.to_send_mail = false; + }, + set_to_send_mail: function(to_send_mail) { + this.assert_editable(); + this.to_send_mail = to_send_mail; + }, + is_to_send_mail: function() { + return this.to_send_mail; + }, + // We export to JSON so we can send this to the backend + // without having to reimplement push_and_invoice_order + export_as_JSON: function () { + var res = OrderSuper.export_as_JSON.apply(this, arguments); + res.to_send_mail = this.to_send_mail; + return res; + }, + }); + +}); diff --git a/pos_invoice_send_mail/static/src/js/screens.js b/pos_invoice_send_mail/static/src/js/screens.js new file mode 100644 index 00000000..79868540 --- /dev/null +++ b/pos_invoice_send_mail/static/src/js/screens.js @@ -0,0 +1,60 @@ +/* Copyright 2019 Druidoo - Iván Todorovich + License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */ + +odoo.define('pos_invoice_send_mail.screens', function (require) { + "use strict"; + +var core = require('web.core'); +var screens = require('point_of_sale.screens'); +var _t = core._t; + +screens.PaymentScreenWidget.include({ + renderElement: function() { + var self = this; + this._super(); + this.$('.js_send_mail').click(function(){ + self.click_send_mail(); + }); + }, + click_send_mail: function() { + var order = this.pos.get_order(); + order.set_to_send_mail(!order.is_to_send_mail()); + if (order.is_to_send_mail()) { + this.$('.js_send_mail').addClass('highlight'); + } else { + this.$('.js_send_mail').removeClass('highlight'); + } + if (order.is_to_send_mail() && !order.is_to_invoice()) { + this.click_invoice(); + } + }, + click_invoice: function() { + this._super(); + var order = this.pos.get_order(); + if (!order.is_to_invoice() && order.is_to_send_mail()) { + this.click_send_mail(); + } + }, +}); + +screens.ScreenWidget.include({ + _handleFailedPushForInvoice: function(order, refresh_screen, error) { + var self = this; + order = order || this.pos.get_order(); + this.invoicing = false; + order.finalized = false; + if (error.message === 'Missing Customer Email') { + this.gui.show_popup('confirm', { + 'title': _t('Please fill the customer email'), + 'body': _t('You need to complete the customer email in order to send it.'), + confirm: function(){ + self.gui.show_screen('clientlist', null, refresh_screen); + }, + }); + } else { + return this._super(order, refresh_screen, error); + } + }, +}); + +}); diff --git a/pos_invoice_send_mail/static/src/xml/pos.xml b/pos_invoice_send_mail/static/src/xml/pos.xml new file mode 100644 index 00000000..bd906381 --- /dev/null +++ b/pos_invoice_send_mail/static/src/xml/pos.xml @@ -0,0 +1,14 @@ + + + + + + +
+ Send Invoice by Email +
+
+
+
+ +
diff --git a/pos_invoice_send_mail/views/assets.xml b/pos_invoice_send_mail/views/assets.xml new file mode 100644 index 00000000..5e726a48 --- /dev/null +++ b/pos_invoice_send_mail/views/assets.xml @@ -0,0 +1,11 @@ + + + +