summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-09-01 12:17:11 +0200
committerAaron Bohy <aab@odoo.com>2017-09-01 14:29:55 +0200
commit0694caabfbb81df7c4956bd2b49e747271714305 (patch)
tree5834dfb19b0d8f764c44bc55b5b675cdfe3d9ae7
parenta980376bfa58ef82d3055fd906258a00e6d2986b (diff)
[FIX] mail: FieldMany2ManyTagsEmail: apply changes
The FieldMany2ManyTagsEmail requires that the records in the relation have an email address set. However, it didn't take into account the changes that might have been done on the field's value (i.e. the check wasn't applied on subrecords that just had been added to the relation).
-rw-r--r--addons/mail/static/src/js/many2many_tags_email.js2
-rw-r--r--addons/mail/static/tests/chatter_tests.js60
2 files changed, 61 insertions, 1 deletions
diff --git a/addons/mail/static/src/js/many2many_tags_email.js b/addons/mail/static/src/js/many2many_tags_email.js
index 382efabbd35..c566d2a4706 100644
--- a/addons/mail/static/src/js/many2many_tags_email.js
+++ b/addons/mail/static/src/js/many2many_tags_email.js
@@ -28,7 +28,7 @@ BasicModel.include({
var localID = (record._changes && fieldName in record._changes) ?
record._changes[fieldName] :
record.data[fieldName];
- var list = this.localData[localID];
+ var list = this._applyX2ManyOperations(this.localData[localID]);
var invalidPartnerIds = [];
_.each(list.data, function (id) {
var record = self.localData[id];
diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js
index b5d7feab56e..c650f8c10c9 100644
--- a/addons/mail/static/tests/chatter_tests.js
+++ b/addons/mail/static/tests/chatter_tests.js
@@ -1064,5 +1064,65 @@ QUnit.test('fieldmany2many tags email', function (assert) {
$('.modal-footer .btn-primary').click();
});
+QUnit.test('fieldmany2many tags email (edition)', function (assert) {
+ assert.expect(15);
+
+ this.data.partner.records[0].timmy = [12];
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ res_id: 1,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="display_name"/>' +
+ '<field name="timmy" widget="many2many_tags_email"/>' +
+ '</sheet>' +
+ '</form>',
+ viewOptions: {
+ mode: 'edit',
+ },
+ mockRPC: function (route, args) {
+ if (args.method ==='read' && args.model === 'partner_type') {
+ assert.step(args.args[0]);
+ assert.deepEqual(args.args[1] , ['display_name', 'email'], "should read the email");
+ }
+ return this._super.apply(this, arguments);
+ },
+ archs: {
+ 'partner_type,false,form': '<form string="Types"><field name="display_name"/><field name="email"/></form>',
+ },
+ });
+
+ assert.verifySteps([[12]]);
+ assert.strictEqual(form.$('.o_field_many2manytags[name="timmy"] span.o_tag_color_10').length, 1,
+ "should contain one tag");
+
+ // add an other existing tag
+ var $input = form.$('.o_field_many2manytags input');
+ $input.click(); // opens the dropdown
+ $input.autocomplete('widget').find('li:first').click(); // add 'silver'
+
+ assert.strictEqual($('.modal-body.o_act_window').length, 1,
+ "there should be one modal opened to edit the empty email");
+ assert.strictEqual($('.modal-body.o_act_window input[name="display_name"]').val(), "silver",
+ "the opened modal should be a form view dialog with the partner_type 14");
+ assert.strictEqual($('.modal-body.o_act_window input[name="email"]').length, 1,
+ "there should be an email field in the modal");
+
+ // set the email and save the modal (will rerender the form view)
+ $('.modal-body.o_act_window input[name="email"]').val('coucou@petite.perruche').trigger('input');
+ $('.modal-footer .btn-primary').click();
+
+ assert.strictEqual(form.$('.o_field_many2manytags[name="timmy"] span.o_tag_color_10').length, 2,
+ "should contain the second tag");
+ // should have read [14] three times: when opening the dropdown, when opening the modal, and
+ // after the save
+ assert.verifySteps([[12], [14], [14], [14]]);
+
+ form.destroy();
+});
+
});
});