[FIX] crm: fix rainbowman message display conditions

This commit fixes the display of the rainbowman message when leads go through
the "won" stage.

Currently, some flows don't show the message when they are supposed to or show
the message when they are NOT supposed to.
This is because the case when the form is saved through the regular "Save"
button is not handled at all.

The CRM form controller extension was completed with the missing use case and
fixed.
An additional QUnit test ensures the correct behavior.

Task-2418294

closes odoo/odoo#63599

X-original-commit: c5cbb9975897935e9ed4e1bce80335207758fa24
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Aurélien Warnon
2020-12-18 16:52:14 +00:00
parent 5cb543651e
commit 6316dd76d4
2 changed files with 79 additions and 17 deletions
+55 -17
View File
@@ -15,27 +15,65 @@ odoo.define("crm.crm_form", function (require) {
var CrmFormController = FormController.extend({
/**
* After data are saved we display a possible rainbowman
* message when the stage is won.
* Main method used when saving the record hitting the "Save" button.
* We check if the stage_id field was altered and if we need to display a rainbowman
* message.
*
* @override
*/
_applyChanges: async function (dataPointID, changes, event) {
var result = await this._super(...arguments);
if ('stage_id' in changes) {
const message = await this._rpc({
model: 'crm.lead',
method : 'get_rainbowman_message',
args: [[parseInt(event.target.res_id)]],
});
if (message) {
this.trigger_up('show_effect', {
message: message,
type: 'rainbow_man',
});
saveRecord: function () {
return this._super(...arguments).then((modifiedFields) => {
if (modifiedFields.indexOf('stage_id') !== -1) {
this._checkRainbowmanMessage(this.renderer.state.res_id)
}
}
return result;
});
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Apply change may be called with 'event.data.force_save' set to True.
* This typically happens when directly clicking in the statusbar widget on a new stage.
* If it's the case, we check for a modified stage_id field and if we need to display a
* rainbowman message.
*
* @param {string} dataPointID
* @param {Object} changes
* @param {OdooEvent} event
* @override
* @private
*/
_applyChanges: function (dataPointID, changes, event) {
return this._super(...arguments).then(() => {
if (event.data.force_save && 'stage_id' in changes) {
this._checkRainbowmanMessage(parseInt(event.target.res_id));
}
});
},
/**
* When updating a crm.lead, through direct use of the status bar or when saving the
* record, we check for a rainbowman message to display.
*
* (see Widget docstring for more information).
*
* @param {integer} recordId
*/
_checkRainbowmanMessage: async function(recordId) {
const message = await this._rpc({
model: 'crm.lead',
method : 'get_rainbowman_message',
args: [[recordId]],
});
if (message) {
this.trigger_up('show_effect', {
message: message,
type: 'rainbow_man',
});
}
}
});
var CrmFormView = FormView.extend({
@@ -114,6 +114,30 @@ odoo.define('crm.form_rainbowman_tests', function (require) {
form.destroy();
});
QUnit.test("first lead won, click on statusbar in edit mode then save", async function (assert) {
assert.expect(3);
const form = await createView(_.extend(this.testFormView, {
res_id: 6,
mockRPC: async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
},
viewOptions: {mode: 'edit'}
}));
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps([]); // no message displayed yet
await testUtils.form.clickSave(form);
assert.verifySteps(['Go, go, go! Congrats for your first deal.']);
form.destroy();
});
QUnit.test("team record 30 days, click on statusbar", async function (assert) {
assert.expect(2);