Browse Source

[ADD] pos_invoice_send_mail

pull/468/head
Iván Todorovich 5 years ago
parent
commit
fcd2fd8d75
  1. 1
      pos_invoice_send_mail/__init__.py
  2. 27
      pos_invoice_send_mail/__manifest__.py
  3. 64
      pos_invoice_send_mail/i18n/fr.po
  4. 61
      pos_invoice_send_mail/i18n/pos_invoice_send_mail.pot
  5. 2
      pos_invoice_send_mail/models/__init__.py
  6. 21
      pos_invoice_send_mail/models/pos_config.py
  7. 31
      pos_invoice_send_mail/models/pos_order.py
  8. 4
      pos_invoice_send_mail/readme/CONFIGURE.rst
  9. 3
      pos_invoice_send_mail/readme/CONTRIBUTORS.rst
  10. 1
      pos_invoice_send_mail/readme/DESCRIPTION.rst
  11. 6
      pos_invoice_send_mail/readme/USAGE.rst
  12. BIN
      pos_invoice_send_mail/static/description/invoice-mail-config.png
  13. BIN
      pos_invoice_send_mail/static/description/invoice-mail-screen.png
  14. 46
      pos_invoice_send_mail/static/src/js/models.js
  15. 60
      pos_invoice_send_mail/static/src/js/screens.js
  16. 14
      pos_invoice_send_mail/static/src/xml/pos.xml
  17. 11
      pos_invoice_send_mail/views/assets.xml
  18. 21
      pos_invoice_send_mail/views/pos_config.xml

1
pos_invoice_send_mail/__init__.py

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

27
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',
],
}

64
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 ""

61
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 ""

2
pos_invoice_send_mail/models/__init__.py

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

21
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),
)

31
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

4
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

3
pos_invoice_send_mail/readme/CONTRIBUTORS.rst

@ -0,0 +1,3 @@
* `Druidoo <https://www.druidoo.io>`_:
* Iván Todorovich <ivan.todorovich@druidoo.io>

1
pos_invoice_send_mail/readme/DESCRIPTION.rst

@ -0,0 +1 @@
Allows to send the invoice by email, from the POS.

6
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.

BIN
pos_invoice_send_mail/static/description/invoice-mail-config.png

After

Width: 564  |  Height: 190  |  Size: 14 KiB

BIN
pos_invoice_send_mail/static/description/invoice-mail-screen.png

After

Width: 1068  |  Height: 599  |  Size: 51 KiB

46
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;
},
});
});

60
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);
}
},
});
});

14
pos_invoice_send_mail/static/src/xml/pos.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PaymentScreenWidget">
<t t-jquery="t[t-if='widget.pos.config.module_account'] t[t-if='widget.pos.get_order()']" t-operation="append">
<t t-if="widget.pos.config.iface_invoice_mail and widget.pos.config.invoice_mail_template_id">
<div t-attf-class='button js_send_mail #{ widget.pos.get_order().is_to_send_mail() ? "highlight" : ""} '>
<i class='fa fa-envelope-open-o' /> Send Invoice by Email
</div>
</t>
</t>
</t>
</templates>

11
pos_invoice_send_mail/views/assets.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_invoice_send_mail/static/src/js/models.js"/>
<script type="text/javascript" src="/pos_invoice_send_mail/static/src/js/screens.js"/>
</xpath>
</template>
</odoo>

21
pos_invoice_send_mail/views/pos_config.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="pos_config_view_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_journal_id']/parent::div" position="after">
<div class="row">
<label for="iface_invoice_mail" class="col-lg-3 o_light_label"/>
<field name="iface_invoice_mail"/>
</div>
<div class="row" attrs="{'invisible': [('iface_invoice_mail', '=', False)]}">
<label string="Email Template" for="invoice_mail_template_id" class="col-lg-3 o_light_label"/>
<field name="invoice_mail_template_id" attrs="{'required': [('iface_invoice_mail', '=', True)]}"/>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save