Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MERGE][IMP] im_livechat: random assignation of conversation #29888

Conversation

Projects
None yet
5 participants
@awa-odoo
Copy link
Contributor

awa-odoo commented Jan 3, 2019

Purpose
The assignation method should always give the new conversation to the operator who
has the less active conversation.
If two operators have the same amount of active conversation, it should chose one of
them randomly.
We also want the visitor to get the same operator (if available) from its last visit.

Specifications
The method 'get_mail_channel' on the 'im_livechat.channel' model used a simple random.choice in
the available users to select the operator.
It was improved to select the operator that has the lowest number of open livechat sessions. If multiple
operators share the same number (lowest) of open livechat sessions, it selects randomly between those.

For the visitor to get the same operator as during its last visit, we save that information in a cookie (1 week lifetime), and give this optional parameter to the server when asking for the livechat session.

To make the code clearer, some methods were reorganize and convert from api.model to api.multi (ensure_one) to be more API-compliant.

Task-1919871

@awa-odoo awa-odoo added the RD label Jan 3, 2019

@robodoo robodoo added the CI 🤖 label Jan 3, 2019

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch Jan 4, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 4, 2019

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch Jan 8, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 8, 2019

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch Jan 9, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 9, 2019

@dbeguin
Copy link
Contributor

dbeguin left a comment

Sound gooood ! It will be nice to have all that merged.
Good job ! 👍
I just had fun with your get_random_operator method :)
Just update the 30min condition in docstring and commit and you'll have aaaall my gratitude.
Bisous !

Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch Mar 7, 2019

@robodoo robodoo removed the CI 🤖 label Mar 7, 2019

@dbeguin
Copy link
Contributor

dbeguin left a comment

Just a little last thing and it'll be all good for me!

Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated

@robodoo robodoo added the CI 🤖 label Mar 7, 2019

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch to 76aa3ac Mar 8, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 8, 2019

@dbeguin

dbeguin approved these changes Mar 8, 2019

@dbeguin dbeguin requested a review from tde-banana-odoo Mar 8, 2019

@jem-odoo
Copy link
Contributor

jem-odoo left a comment

Revieeewwwww

Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/tests/test_get_mail_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/tests/test_get_mail_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/tests/test_get_mail_channel.py

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch from 76aa3ac to 99b1662 Mar 21, 2019

@robodoo robodoo removed the CI 🤖 label Mar 21, 2019

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch 3 times, most recently from b8d366f to 3b7413f Mar 21, 2019

@robodoo robodoo added the CI 🤖 label Mar 21, 2019

@jem-odoo
Copy link
Contributor

jem-odoo left a comment

small remarks

Show resolved Hide resolved addons/im_livechat/models/im_livechat_channel.py Outdated
Show resolved Hide resolved addons/im_livechat/tests/test_get_mail_channel.py Outdated

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch from 3b7413f to e9bfb53 Mar 26, 2019

robodoo added a commit that referenced this pull request Mar 27, 2019

[MERGE][IMP] im_livechat: random assignation of conversation
Purpose
The assignation method should always give the new conversation to the operator who
has the less active conversation.
If two operators have the same amount of active conversation, it should chose one of
them randomly.
We also want the visitor to get the same operator (if available) from its last visit.

Specifications
The method 'get_mail_channel' on the 'im_livechat.channel' model used a simple random.choice in
the available users to select the operator.
It was improved to select the operator that has the lowest number of open livechat sessions. If multiple
operators share the same number (lowest) of open livechat sessions, it selects randomly between those.

For the visitor to get the same operator as during its last visit, we save that information in a cookie (1 week lifetime), and give this optional parameter to the server when asking for the livechat session.

To make the code clearer, some methods were reorganize and convert from `api.model` to `api.multi` (ensure_one) to be more API-compliant.

Task-1919871

closes #29888

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>

@robodoo robodoo added the r+ 👌 label Mar 27, 2019

@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Mar 27, 2019

Merge method set to rebase and merge, using the PR as merge commit message

@jem-odoo

This comment has been minimized.

Copy link
Contributor

jem-odoo commented Mar 27, 2019

@robodoo r- as the livechat is not testable for now :/

@awa-odoo awa-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch from e9bfb53 to 327f266 Mar 28, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Mar 28, 2019

@tde-banana-odoo
Copy link
Contributor

tde-banana-odoo left a comment

Sudo review: some things are a bit louche and questions arise

Show resolved Hide resolved addons/im_livechat/views/im_livechat_channel_templates.xml Outdated
Show resolved Hide resolved addons/im_livechat/controllers/main.py Outdated
if previous_operator_id:
previous_operator_id = int(previous_operator_id)

return request.env["im_livechat.channel"].with_context(lang=False).sudo().browse(channel_id)._get_mail_channel(anonymous_name, previous_operator_id, user_id, country_id)

This comment has been minimized.

Copy link
@tde-banana-odoo

tde-banana-odoo Mar 28, 2019

Contributor

Just be sure this sudo as no side effect (notably: security, leak, multi company)

@robodoo robodoo removed the CI 🤖 label Mar 28, 2019

@jem-odoo jem-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch from f77a0b6 to dc4ed58 Mar 28, 2019

@robodoo robodoo added the CI 🤖 label Mar 28, 2019

awa-odoo and others added some commits Jan 3, 2019

[REF] im_livechat: rework some 'im_livechat.channel' model methods
Purpose
=======

Several methods of the 'im_livechat.channel' model were passed a 'channel_id' to work on.
This has been changed so that the caller can use those methods on an instance of this model instead.

Some methods have also been switched to private because they had no apparent reasons to be public.

This is a preliminary cleaning for task #1919871

Specicial note for the "loader" template:
To load the livechat assets in a website page, the 'loader' template of livechat
is directly called (instead of being returned through a controller) in order
to avoid a new call to server.
As this commit moves 'sudo' to make method callable on the record directly, it
still needs to be sudo. First solution was to add the 'sudo' in the template, which
is a bad practise.
This commit creates a proxy method on website model returning the livechat info
with 'sudo'. This avoid having the 'sudo' done in template. Like always, explicit
is better than implicit.

Task-1919871
[IMP] im_livechat: improve random assignation of conversations
Task #1919871

Purpose
=======
The method 'get_mail_channel' in the 'im_livechat.channel' model used a simple random.choice in
the available users to select the operator.

It was improved to select the operator that has the lowest number of active livechats. If multiple
operators share the same number (lowest) of active livechats, it selects randomly between those.

A livechat is considered 'active' if it has at least one message within the last hour.

Spec
=======
The assignation method should always give the new conversation to the operator who
has the less active conversation.

If two operators have the same amout of active conversation, it should chose one of
them randomly.
[IMP] im_livechat: ensure that visitors always gets the same operator
Task #1919871

Purpose
=======

If a visitor comes on the website and launches a livechat, it will be randomly assigned operator A.
If he comes the next day and opens a livechat again, we want him to have the same operator if he's available.

To handle that use case, we added a cookie that stores the "previous operator id" information for 7 days.
[FIX] im_livechat: missing js files in assets
Like every changes in web client, and in the assets composition, "some
people" forget to update the specific assets of livechat.
Specific livechat assets allow to load a small part of odoo js
framework in order to be embedded on external website.

Task-1919871

@jem-odoo jem-odoo force-pushed the odoo-dev:master-improve-livechat-random-assignation-awa branch from dc4ed58 to 3d4297b Apr 1, 2019

@robodoo robodoo removed the CI 🤖 label Apr 1, 2019

@jem-odoo

This comment has been minimized.

Copy link
Contributor

jem-odoo commented Apr 1, 2019

@robodoo rebase-merge r+

@robodoo robodoo added the r+ 👌 label Apr 1, 2019

@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Apr 1, 2019

Merge method set to rebase and merge, using the PR as merge commit message

robodoo added a commit that referenced this pull request Apr 1, 2019

[MERGE][IMP] im_livechat: random assignation of conversation
Purpose
The assignation method should always give the new conversation to the operator who
has the less active conversation.
If two operators have the same amount of active conversation, it should chose one of
them randomly.
We also want the visitor to get the same operator (if available) from its last visit.

Specifications
The method 'get_mail_channel' on the 'im_livechat.channel' model used a simple random.choice in
the available users to select the operator.
It was improved to select the operator that has the lowest number of open livechat sessions. If multiple
operators share the same number (lowest) of open livechat sessions, it selects randomly between those.

For the visitor to get the same operator as during its last visit, we save that information in a cookie (1 week lifetime), and give this optional parameter to the server when asking for the livechat session.

To make the code clearer, some methods were reorganize and convert from `api.model` to `api.multi` (ensure_one) to be more API-compliant.

Task-1919871

closes #29888

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Apr 1, 2019

Merged, thanks!

@robodoo robodoo closed this Apr 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.