diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/crm/static/tests/mock_server.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/crm/static/tests/mock_server.js')
| -rw-r--r-- | addons/crm/static/tests/mock_server.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/addons/crm/static/tests/mock_server.js b/addons/crm/static/tests/mock_server.js new file mode 100644 index 00000000..0c6c0fbb --- /dev/null +++ b/addons/crm/static/tests/mock_server.js @@ -0,0 +1,56 @@ +odoo.define('crm.MockServer', function (require) { + 'use strict'; + + var MockServer = require('web.MockServer'); + + MockServer.include({ + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + * @private + */ + async _performRpc(route, args) { + if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') { + let message = false; + const records = this.data['crm.lead'].records; + const record = records.find(r => r.id === args.args[0][0]); + const won_stage = this.data['crm.stage'].records.find(s => s.is_won); + if (record.stage_id === won_stage.id && record.user_id && record.team_id && record.planned_revenue > 0) { + const now = moment(); + let query_result = {}; + // Total won + query_result['total_won'] = records.filter(r => r.stage_id === won_stage.id && r.user_id === record.user_id).length; + // Max team 30 days + const recordsTeam30 = records.filter(r => r.stage_id === won_stage.id && r.team_id === record.team_id && (!r.date_closed || moment.duration(now.diff(moment(r.date_closed))).days() <= 30)); + query_result['max_team_30'] = Math.max(...recordsTeam30.map(r => r.planned_revenue)); + // Max team 7 days + const recordsTeam7 = records.filter(r => r.stage_id === won_stage.id && r.team_id === record.team_id && (!r.date_closed || moment.duration(now.diff(moment(r.date_closed))).days() <= 7)); + query_result['max_team_7'] = Math.max(...recordsTeam7.map(r => r.planned_revenue)); + // Max User 30 days + const recordsUser30 = records.filter(r => r.stage_id === won_stage.id && r.user_id === record.user_id && (!r.date_closed || moment.duration(now.diff(moment(r.date_closed))).days() <= 30)); + query_result['max_user_30'] = Math.max(...recordsUser30.map(r => r.planned_revenue)); + // Max User 7 days + const recordsUser7 = records.filter(r => r.stage_id === won_stage.id && r.user_id === record.user_id && (!r.date_closed || moment.duration(now.diff(moment(r.date_closed))).days() <= 7)); + query_result['max_user_7'] = Math.max(...recordsUser7.map(r => r.planned_revenue)); + + if (query_result.total_won === 1) { + message = "Go, go, go! Congrats for your first deal."; + } else if (query_result.max_team_30 === record.planned_revenue) { + message = "Boom! Team record for the past 30 days."; + } else if (query_result.max_team_7 === record.planned_revenue) { + message = "Yeah! Deal of the last 7 days for the team."; + } else if (query_result.max_user_30 === record.planned_revenue) { + message = "You just beat your personal record for the past 30 days."; + } else if (query_result.max_user_7 === record.planned_revenue) { + message = "You just beat your personal record for the past 7 days."; + } + } + return message; + } + return this._super(...arguments); + }, + }); +}); |
