From f8bf66b6def30b5738d91da564fda0a8eb8eeead Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 7 Nov 2017 11:03:52 +0100 Subject: [PATCH 1/2] [FIX] website_crm_partner_assign: assign opportunity to the commercial_partner_id Before this commit, an opp created from a contact via the portal was assign to himself instead of the commercial_partner_id. So the saleperson was not assigned to the opportunity, and the opp created was not for the company but for the contact only. That make sense to share the opp to the company and assign the saleman directly. Thanks to GBR for the reporting. --- addons/website_crm_partner_assign/models/crm_lead.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website_crm_partner_assign/models/crm_lead.py b/addons/website_crm_partner_assign/models/crm_lead.py index 424919b05ab..bed1447a050 100644 --- a/addons/website_crm_partner_assign/models/crm_lead.py +++ b/addons/website_crm_partner_assign/models/crm_lead.py @@ -267,7 +267,7 @@ class CrmLead(models.Model): 'name': values['title'], 'description': values['description'], 'priority': '2', - 'partner_assigned_id': user.partner_id.id, + 'partner_assigned_id': user.commercial_partner_id.id, } if tag_own: values['tag_ids'] = [(4, tag_own.id, False)] From 255478acbd66f01daf32422636f09f2014ebc9f8 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Thu, 2 Nov 2017 16:00:58 +0100 Subject: [PATCH 2/2] [FIX] web: clear m2o input at creation cancel After entering a value in a many2one, if one clicks somewhere else, a popup is opened to suggest the user to create (or not) a new record with the entered value. Before this rev, closing this popup resulted in an unclear situation where the input was still set with the entered value but the new record hadn't been created. This commit fixes this by clearing the input value if the record is not created. See task#36055 --- .../static/src/js/fields/relational_fields.js | 30 +++++++++++++++- .../tests/fields/relational_fields_tests.js | 34 +++++++++++++++---- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index d7b4368036d..19f2728a3ae 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -46,7 +46,7 @@ var M2ODialog = Dialog.extend({ click: function () { if (this.$("input").val() !== ''){ this.trigger_up('quick_create', { value: this.$('input').val() }); - this.close(); + this.close(true); } else { this.$("input").focus(); } @@ -71,12 +71,30 @@ var M2ODialog = Dialog.extend({ this.$("p").text(_.str.sprintf(_t("You are creating a new %s, are you sure it does not exist yet?"), this.name)); this.$("input").val(this.value); }, + /** + * @override + * @param {boolean} isSet + */ + close: function (isSet) { + this.isSet = isSet; + this._super.apply(this, arguments); + }, + /** + * @override + */ + destroy: function () { + if (!this.isSet) { + this.trigger_up('closed_unset'); + } + this._super.apply(this, arguments); + }, }); var FieldMany2One = AbstractField.extend({ supportedFieldTypes: ['many2one'], template: 'FieldMany2One', custom_events: _.extend({}, AbstractField.prototype.custom_events, { + 'closed_unset': '_onDialogClosedUnset', 'quick_create': '_onQuickCreate', 'search_create_popup': '_onSearchCreatePopup', }), @@ -450,6 +468,16 @@ var FieldMany2One = AbstractField.extend({ }); } }, + + /** + * Reset the input as dialog has been closed without m2o creation. + * + * @private + */ + _onDialogClosedUnset: function () { + this.floating = false; + this._render(); + }, /** * @private */ diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 3cdd4b89138..07b58764e30 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -1395,7 +1395,7 @@ QUnit.module('relational_fields', { }); QUnit.test('slow create on a many2one', function (assert) { - assert.expect(1); + assert.expect(7); var form = createView({ View: FormView, @@ -1415,12 +1415,34 @@ QUnit.module('relational_fields', { }, }); + // cancel the many2one creation with Cancel button + form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); + assert.strictEqual($('.modal').length, 1, "there should be one opened modal"); + $('.modal .modal-footer .btn:contains(Cancel)').click(); + assert.strictEqual(form.$('.o_field_many2one input').val(), "", + 'the many2one should not set a value as its creation has been cancelled (with Cancel button)'); + + // cancel the many2one creation with Close button + form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); + $('.modal .modal-header button').click(); + assert.strictEqual(form.$('.o_field_many2one input').val(), "", + 'the many2one should not set a value as its creation has been cancelled (with Close button)'); + + // select a new value then cancel the creation of the new one --> restore the previous + form.$('.o_field_many2one input').click(); + form.$('.o_field_many2one input').autocomplete('widget').find('a').first().click(); + assert.strictEqual(form.$('input').val(), "xphone", "should have selected xphone"); + form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur'); + assert.strictEqual($('.modal').length, 1, "there should be one opened modal"); + $('.modal .modal-footer .btn:contains(Cancel)').click(); + assert.strictEqual(form.$('.o_field_many2one input').val(), "xphone", + 'should have restored the many2one with its previous selected value (xphone)'); + + // confirm the many2one creation form.$('.o_field_many2one input').focus(); - form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('focusout'); - - $('.modal .modal-footer .btn-primary').first().click(); - - assert.strictEqual($('.modal:visible:last .o_form_view').length, 1, + form.$('.o_field_many2one input').val('new partner').trigger('keyup').trigger('blur'); + $('.modal .modal-footer .btn-primary').click(); + assert.strictEqual($('.modal .o_form_view').length, 1, 'a new modal should be opened and contain a form view'); form.destroy();