Browse Source

[9.0][ADD] website_livechat_firstname: Only show employee’s first name in Live Chat (#148)

* [ADD] website_livechat_firstname: Add module.

* [IMP] website_livechat_firstname: Fix models. Add tests.
* Add res partner demo
* Fix mail_channel channel_info method
* Add tests for mail channel firstnames
* Fix bug when partner firstname is not available

* [FIX] website_livechat_firstname: Fix readme, manifest.
* Fix usage section in readme
* Add laslabs to authors in manifest

* [IMP] website_livechat_firstname: Change to LGPL.
pull/93/merge
Kelly Lougheed 8 years ago
committed by Dave Lasley
parent
commit
0550661f25
  1. 1
      oca_dependencies.txt
  2. 62
      website_livechat_firstname/README.rst
  3. 5
      website_livechat_firstname/__init__.py
  4. 25
      website_livechat_firstname/__openerp__.py
  5. 21
      website_livechat_firstname/demo/res_partner_demo.xml
  6. 5
      website_livechat_firstname/models/__init__.py
  7. 39
      website_livechat_firstname/models/mail_channel.py
  8. BIN
      website_livechat_firstname/static/description/icon.png
  9. 5
      website_livechat_firstname/tests/__init__.py
  10. 70
      website_livechat_firstname/tests/test_mail_channel.py
  11. 14
      website_livechat_firstname/views/website_livechat_firstname_view.xml

1
oca_dependencies.txt

@ -1 +1,2 @@
partner-contact
server-tools

62
website_livechat_firstname/README.rst

@ -0,0 +1,62 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/LGPL-3.0-standalone.html
:alt: License: LGPL-3
===============================
Website Live Chat - First Name
===============================
This module shows only the first name of an employee in Live Chat.
Usage
=====
To use this module, you need to:
#. Install the module.
#. Go to the website.
#. Initiate a Live Chat at the bottom right-hand corner of the screen.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/9.0
Known Issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Kelly Lougheed <kelly@smdrugstore.com>
* Brett Wood <bwood@laslabs.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
website_livechat_firstname/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import models

25
website_livechat_firstname/__openerp__.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Website Live Chat - First Name",
"summary": "Shows only the first name of the operator in the website",
"version": "9.0.1.0.0",
"category": "Social",
"website": "https://github.com/OCA/social",
"author": "SMDrugstore, LasLabs, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"partner_firstname",
"website_livechat",
],
"data": [
"views/website_livechat_firstname_view.xml",
],
"demo": [
"demo/res_partner_demo.xml",
],
}

21
website_livechat_firstname/demo/res_partner_demo.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Specialty Medical Drugstore
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<record id="res_partner_1" model="res.partner">
<field name="firstname">Mitchell</field>
<field name="lastname">Vangrey</field>
<field name="city">Las Vegas</field>
<field name="state_id" ref="base.state_us_23" />
<field name="country_id" ref="base.us" />
<field name="zip">89119</field>
<field name="street">111 Example Way</field>
<field name="email">mvangrey@example.com</field>
<field name="phone">+1 (702) 111-2222</field>
<field name="parent_id" ref="base.partner_demo" />
<field name="ref">680-36-6978</field>
</record>
</odoo>

5
website_livechat_firstname/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import mail_channel

39
website_livechat_firstname/models/mail_channel.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp import api, models
class MailChannel(models.Model):
_inherit = 'mail.channel'
@api.multi
def channel_info(self, extra_info=False):
channel_infos = super(MailChannel, self).channel_info(extra_info)
partner_mod = self.env['res.partner']
operator_id = self.env.context.get('im_livechat_operator_partner_id')
for channel_info in channel_infos:
if operator_id and channel_info['public'] == 'public':
operator = partner_mod.browse(operator_id)
if operator.firstname:
operator_name = operator.firstname
else:
operator_name = operator.name
channel_info['operator_pid'] = \
(operator.id, u'%s' % operator_name)
# channel name format:
# 'customer name, operator/employee name'
channel_name = channel_info['name'].split(', ')
new_channel_name = '%s, %s' % \
(channel_name[0], operator_name)
channel_info['name'] = new_channel_name
return channel_infos

BIN
website_livechat_firstname/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

5
website_livechat_firstname/tests/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import test_mail_channel

70
website_livechat_firstname/tests/test_mail_channel.py

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Specialty Medical Drugstore, LLC.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp.tests.common import TransactionCase
class TestMailChannel(TransactionCase):
def setUp(self):
super(TestMailChannel, self).setUp()
self.operator = self.env.ref(
'website_livechat_firstname.res_partner_1'
)
self.customer_name = 'Billy Joe'
self.channel_vals = {
'name': '%s, %s' % (self.customer_name, self.operator.name),
'public': 'public',
}
self.mail_mod = self.env['mail.channel']
self.test_context = {
'im_livechat_operator_partner_id': self.operator.id,
}
def test_channel_info_operator_pid_full_name(self):
""" Test get operator name correct when full name """
channel = self.mail_mod.create(self.channel_vals)
res = channel.with_context(self.test_context).channel_info()
self.assertEquals(
res[0]['operator_pid'],
(self.operator.id, u'%s' % self.operator.firstname),
)
def test_channel_info_operator_pid_last_name_only(self):
""" Test get operator name correct if only lastname """
self.operator.firstname = None
channel = self.mail_mod.create(self.channel_vals)
res = channel.with_context(self.test_context).channel_info()
self.assertEquals(
res[0]['operator_pid'],
(self.operator.id, u'%s' % self.operator.name),
)
def test_channel_info_name(self):
""" Test operator name shortened correctly in channel name """
channel = self.mail_mod.create(self.channel_vals)
res = channel.with_context(self.test_context).channel_info()
self.assertEquals(
res[0]['name'],
'%s, %s' % (self.customer_name, self.operator.firstname),
)
def test_channel_info_no_context(self):
""" Test channel_name same if no context passsed """
channel = self.mail_mod.create(self.channel_vals)
res = channel.channel_info()
self.assertEquals(
res[0]['name'],
'%s, %s' % (self.customer_name, self.operator.name),
)
def test_channel_info_not_public(self):
""" Test channel info unchanged if not public channel """
self.channel_vals['public'] = 'private'
channel = self.mail_mod.create(self.channel_vals)
res = channel.with_context(self.test_context).channel_info()
self.assertEquals(
res[0]['name'],
'%s, %s' % (self.customer_name, self.operator.name),
)

14
website_livechat_firstname/views/website_livechat_firstname_view.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Specialty Medical Drugstore
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="channel_page" inherit_id="website_livechat.channel_page" >
<xpath expr="//div[@class='media-body']/h5/t" position="replace">
<t t-if="user.partner_id.firstname" t-esc="user.partner_id.firstname" />
<t t-else="" t-esc="user.partner_id.name" />
</xpath>
</template>
</odoo>
Loading…
Cancel
Save