Skip to content

Commit

Permalink
[IMP][crm_phonecall] Add utm.mixin fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Sep 18, 2017
1 parent 519445e commit c7f7593
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions crm_phonecall/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Contributors

* Odoo S.A.
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>

Maintainer
----------
Expand Down
4 changes: 2 additions & 2 deletions crm_phonecall/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

{
"name": "CRM Phone Calls",
"version": "9.0.1.0.0",
"version": "9.0.1.1.0",
"category": "Customer Relationship Management",
"author": "Odoo S.A., "
"Tecnativa, "
"Odoo Community Association (OCA)",
"website": "http://www.tecnativa.com",
"website": "https://www.tecnativa.com",
"license": "AGPL-3",
"contributors": [
"Vicent Cubells <vicent.cubells@tecnativa.com>",
Expand Down
8 changes: 7 additions & 1 deletion crm_phonecall/models/crm_phonecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CrmPhonecall(models.Model):
_name = "crm.phonecall"
_description = "Phonecall"
_order = "id desc"
_inherit = ['mail.thread']
_inherit = ['mail.thread', 'utm.mixin']

date_action_last = fields.Datetime(
string='Last Action',
Expand Down Expand Up @@ -159,6 +159,9 @@ def schedule_another_phonecall(self, schedule_time, call_summary,
'partner_mobile': call.partner_mobile,
'priority': call.priority,
'opportunity_id': call.opportunity_id.id or False,
'campaign_id': call.campaign_id.id,
'source_id': call.source_id.id,
'medium_id': call.medium_id.id,
}
if tag_id:
values.update({'tag_ids': [(6, 0, [tag_id])]})
Expand Down Expand Up @@ -229,6 +232,9 @@ def convert_opportunity(self, opportunity_summary=False, partner_id=False,
'type': 'opportunity',
'phone': call.partner_phone or False,
'email_from': default_contact and default_contact.email,
'campaign_id': call.campaign_id.id,
'source_id': call.source_id.id,
'medium_id': call.medium_id.id,
})
vals = {
'partner_id': partner_id,
Expand Down
34 changes: 27 additions & 7 deletions crm_phonecall/tests/test_crm_phonecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def setUpClass(cls):
super(TestCrmPhoneCall, cls).setUpClass()
cls.company = cls.env.ref('base.main_company')
partner_obj = cls.env['res.partner']
cls.campaign1 = cls.env['utm.campaign'].create({
"name": "campaign 1",
})
cls.source1 = cls.env['utm.source'].create({
"name": "source 1",
})
cls.medium1 = cls.env['utm.medium'].create({
"name": "medium 1",
})
cls.partner1 = partner_obj.create({
'name': 'Partner1',
'phone': '123 456 789',
Expand All @@ -25,6 +34,9 @@ def setUpClass(cls):
cls.phonecall1 = cls.env['crm.phonecall'].create({
'name': 'Call #1 for test',
'partner_id': cls.partner1.id,
'campaign_id': cls.campaign1.id,
'source_id': cls.source1.id,
'medium_id': cls.medium1.id,
})
cls.opportunity1 = cls.env['crm.lead'].create({
'name': 'Opportunity #1',
Expand Down Expand Up @@ -53,24 +65,28 @@ def test_on_change_partner(self):
self.assertEqual(self.phonecall1.duration, 0.0)

def test_schedule_another_phonecall(self):
self.phonecall2 = self.phonecall1.schedule_another_phonecall(
phonecall2 = self.phonecall1.schedule_another_phonecall(
schedule_time=False,
call_summary='Test schedule method',
action='schedule',
tag_id=self.tag.id,
)[self.phonecall1.id]
self.assertEqual(self.phonecall2.id, self.phonecall1.id + 1)
self.assertNotEqual(phonecall2.id, self.phonecall1.id)
self.assertEqual(self.phonecall1.state, 'open')
self.phonecall3 = self.phonecall1.schedule_another_phonecall(
phonecall3 = self.phonecall1.schedule_another_phonecall(
schedule_time='2017-12-31 00:00:00',
call_summary='Test schedule method2',
action='log',
)[self.phonecall1.id]
self.assertEqual(self.phonecall3.id, self.phonecall1.id + 2)
self.assertNotEqual(phonecall3.id, self.phonecall1.id)
self.assertNotEqual(phonecall3.id, phonecall2.id)
self.assertEqual(self.phonecall1.state, 'done')

result = self.phonecall2.redirect_phonecall_view()
self.assertEqual(result['res_id'], self.phonecall2.id)
result = phonecall2.redirect_phonecall_view()
self.assertEqual(result['res_id'], phonecall2.id)
for phonecall in (self.phonecall1, phonecall2, phonecall3):
self.assertEqual(phonecall.campaign_id, self.campaign1)
self.assertEqual(phonecall.source_id, self.source1)
self.assertEqual(phonecall.medium_id, self.medium1)

def test_on_change_opportunity(self):
self.phonecall1.opportunity_id = self.opportunity1
Expand All @@ -83,6 +99,10 @@ def test_on_change_opportunity(self):
def test_convert2opportunity(self):
result = self.phonecall1.action_button_convert2opportunity()
self.assertEqual(result['res_model'], 'crm.lead')
lead = self.env["crm.lead"].browse(result["res_id"])
self.assertEqual(lead.campaign_id, self.campaign1)
self.assertEqual(lead.source_id, self.source1)
self.assertEqual(lead.medium_id, self.medium1)

def test_make_meeting(self):
result = self.phonecall1.action_make_meeting()
Expand Down
5 changes: 5 additions & 0 deletions crm_phonecall/views/crm_phonecall_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
<field name="priority" widget="priority"/>
<field name="opportunity_id" context="{'opportunity_id': opportunity_id}"/>
</group>
<group string="Tracking" groups="base.group_multi_company,base.group_no_one" name="categorization">
<field name="campaign_id"/>
<field name="source_id"/>
<field name="medium_id"/>
</group>
<field name="description" placeholder="Description..."/>
</sheet>
<div class="oe_chatter">
Expand Down

0 comments on commit c7f7593

Please sign in to comment.