add many2many_tags_email.js file for mail_usability that replaces addons-mail-fix.diff patch

This commit is contained in:
chafique-delli
2017-09-18 15:44:58 +02:00
parent a3844004fb
commit cfb92ec23a
4 changed files with 103 additions and 24 deletions

View File

@@ -42,6 +42,6 @@ Small usability improvements on mails:
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['mail'],
'data': [],
'data': ['views/mail.xml'],
'installable': True,
}

View File

@@ -1,23 +0,0 @@
diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js
index c3985a3..307cc0c 100644
--- a/addons/mail/static/src/js/many2many_tags_email.js
+++ b/addons/mail/static/src/js/many2many_tags_email.js
@@ -17,6 +17,9 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags
this.last_processed_value = [];
this.on("change:value", this, this.on_change_value_check);
+ // Restore pop-up when trying to send to a partner without email
+ // Pending PR on odoo v8 https://github.com/odoo/odoo/pull/19466
+ this.on_change_value_check();
this._super.apply(this, arguments);
},
@@ -41,7 +44,7 @@ instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags
new instance.web.Model('res.partner').call("search", [[
["id", "in", ids],
["email", "=", false],
- ["notify_email", "=", 'always'] ]],
+ ["notify_email", "in", ['always', 'all_except_notification']] ]], // Adapt code for mail_usability module
{context: this.build_context()})
.then(function (record_ids) {
var popups_deferreds = [];

View File

@@ -0,0 +1,91 @@
openerp_FieldMany2ManyTagsEmail = function(instance) {
var _t = instance.web._t;
/**
* Extend of FieldMany2ManyTags widget method.
* When the user add a partner and the partner don't have an email, open a popup to purpose to add an email.
* The user can choose to add an email or cancel and close the popup.
*/
instance.web.form.FieldMany2ManyTagsEmail = instance.web.form.FieldMany2ManyTags.extend({
start: function() {
this.mutex = new openerp.Mutex();
// This widget will indirectly trigger a change:value to it's parent widget
// when setting the value of valid partners. For this reason we have to keep an
// internal state of the last value in order to compute the effective value changes.
this.last_processed_value = [];
this.on("change:value", this, this.on_change_value_check);
this.on_change_value_check();
this._super.apply(this, arguments);
},
on_change_value_check : function () {
var self = this;
var values = this.get('value').slice(0); // Clone the array
// We only validate partners emails in case the value is not empty
// and is different from the last processed value
var effective_change = _.difference(values, self.last_processed_value).length;
if (values.length && effective_change) {
this.mutex.exec(function() {
return self._check_email_popup(values);
});
}
},
_check_email_popup: function (ids) {
var self = this;
var valid_partners;
new instance.web.Model('res.partner').call("search", [[
["id", "in", ids],
["email", "=", false],
["notify_email", "in", ['always', 'all_except_notification']]]],
{context: this.build_context()})
.then(function (record_ids) {
var popups_deferreds = [];
self.valid_partners = _.difference(ids, record_ids);
// Propose the user to correct invalid partners
_.each(record_ids, function (id) {
var popup_def = $.Deferred();
popups_deferreds.push(popup_def);
var pop = new instance.web.form.FormOpenPopup(self);
pop.show_element(
'res.partner',
id,
self.build_context(),
{
title: _t("Please complete partner's informations and Email"),
}
);
pop.on('write_completed', self, function () {
self.valid_partners.push(id);
});
pop.on('closed', self, function () {
popup_def.resolve();
});
});
return $.when.apply($, popups_deferreds).then(function() {
// All popups have been processed for the given ids
// It is now time to set the final value with valid partners ids.
var filtered_value = _.uniq(self.valid_partners);
self.last_processed_value = filtered_value;
self.set({'value': filtered_value});
});
});
},
});
/**
* Registry of form fields
*/
instance.web.form.widgets = instance.web.form.widgets.extend({
'many2many_tags_email' : 'instance.web.form.FieldMany2ManyTagsEmail',
});
};

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="mail usability assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/mail_usability/static/src/js/many2many_tags_email.js"></script>
</xpath>
</template>
</data>
</openerp>