Browse Source

Port crm_phone to v9

Code cleanup, fixes, small enhancements
The code to extract the calling party number from the list of channels is now inheritable
pull/88/head
Alexis de Lattre 9 years ago
parent
commit
42e34dfdcd
  1. 52
      asterisk_click2dial/asterisk_click2dial.py
  2. 5
      asterisk_click2dial/asterisk_server_view.xml
  3. 4
      asterisk_click2dial/res_users_view.xml
  4. 4
      asterisk_click2dial/static/src/js/asterisk_click2dial.js
  5. 21
      asterisk_click2dial_crm/__init__.py
  6. 48
      asterisk_click2dial_crm/__openerp__.py
  7. 9
      base_phone/res_company_view.xml
  8. 11
      base_phone/res_partner_view.xml
  9. 9
      base_phone/res_users_view.xml
  10. 9
      base_phone/web_phone.xml
  11. 12
      base_phone/wizard/number_not_found.py
  12. 11
      base_phone/wizard/number_not_found_view.xml
  13. 30
      crm_phone/__openerp__.py
  14. 38
      crm_phone/crm_phone.py
  15. 39
      crm_phone/crm_view.xml
  16. 9
      crm_phone/res_users_view.xml
  17. 19
      crm_phone/wizard/__init__.py
  18. 32
      crm_phone/wizard/create_crm_phonecall.py
  19. 99
      crm_phone/wizard/number_not_found.py
  20. 14
      crm_phone/wizard/number_not_found_view.xml

52
asterisk_click2dial/asterisk_click2dial.py

@ -5,6 +5,7 @@
from openerp import models, fields, api, _
from openerp.exceptions import UserError, ValidationError
import logging
from pprint import pformat
try:
# pip install py-Asterisk
@ -167,37 +168,44 @@ class AsteriskServer(models.Model):
"the Asterisk Manager Interface."))
@api.model
def _get_calling_number(self):
user, ast_server, ast_manager = self._connect_to_asterisk()
calling_party_number = False
try:
list_chan = ast_manager.Status()
# from pprint import pprint
# pprint(list_chan)
_logger.debug("Result of Status AMI request: %s", list_chan)
for chan in list_chan.values():
def _get_calling_number_from_channel(self, chan, user):
'''Method designed to be inherited to work with
very old or very new versions of Asterisk'''
sip_account = user.asterisk_chan_type + '/' + user.resource
internal_number = user.internal_number
# 4 = Ring
if (
chan.get('ChannelState') == '4' and
chan.get('ConnectedLineNum') == user.internal_number):
_logger.debug("Found a matching Event in 'Ring' state")
calling_party_number = chan.get('CallerIDNum')
break
# 6 = Up
if (
chan.get('ChannelState') == '6' and
sip_account in chan.get('BridgedChannel', '')):
_logger.debug("Found a matching Event in 'Up' state")
calling_party_number = chan.get('CallerIDNum')
break
chan.get('ChannelState') in ('4', '6') and (
chan.get('ConnectedLineNum') == internal_number or
chan.get('EffectiveConnectedLineNum') == internal_number or
sip_account in chan.get('BridgedChannel', ''))):
_logger.debug(
"Found a matching Event with channelstate = %s",
chan.get('ChannelState'))
return chan.get('CallerIDNum')
# Compatibility with Asterisk 1.4
if (
chan.get('State') == 'Up' and
sip_account in chan.get('Link', '')):
_logger.debug("Found a matching Event in 'Up' state")
calling_party_number = chan.get('CallerIDNum')
return chan.get('CallerIDNum')
return False
@api.model
def _get_calling_number(self):
user, ast_server, ast_manager = self._connect_to_asterisk()
calling_party_number = False
try:
list_chan = ast_manager.Status()
# from pprint import pprint
# pprint(list_chan)
_logger.debug("Result of Status AMI request:")
_logger.debug(pformat(list_chan))
for chan in list_chan.values():
calling_party_number = self._get_calling_number_from_channel(
chan, user)
if calling_party_number:
break
except Exception, e:
_logger.error(

5
asterisk_click2dial/asterisk_server_view.xml

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial module for Odoo
Copyright (C) 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
The licence is in the file __openerp__.py
© 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>

4
asterisk_click2dial/res_users_view.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
The licence is in the file __openerp__.py
© 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
Inherit res_users view to add the click2dial-related fields
-->

4
asterisk_click2dial/static/src/js/asterisk_click2dial.js

@ -5,12 +5,12 @@
odoo.define('asterisk_click2dial.click2dial', function (require) {
"use strict";
var _t = core._t;
var UserMenu = require('web.UserMenu');
var WebClient = require('web.WebClient');
var web_client = require('web.web_client');
var Widget = require('web.Widget');
var core = require('web.core');
var _t = core._t;
var click2dial = {};
@ -71,7 +71,7 @@ click2dial.OpenCaller = Widget.extend({
this._super.apply(this, arguments);
this.update_promise.then(function() {
var asterisk_button = new click2dial.OpenCaller();
//console.log(this);
// attach the phone logo/button to the systray
asterisk_button.appendTo($('.oe_systray'));
});
},

21
asterisk_click2dial_crm/__init__.py

@ -1,21 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

48
asterisk_click2dial_crm/__openerp__.py

@ -1,48 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Asterisk Click2dial CRM",
"version": "8.0.0.1.0",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "http://www.akretion.com",
"license": "AGPL-3",
"category": "Phone",
"description": """
Asterisk Click2dial CRM
=======================
This module is *EMPTY* ; so you should uninstall it now.
The code that used to be in this module has been moved to the module
*crm_phone* that is available in the same GitHub repository
https://github.com/OCA/connector-telephony
This module will be removed from the repository in the near future.
""",
"depends": [
'asterisk_click2dial',
'crm_phone',
],
"data": [],
'installable': False,
"application": False,
}

9
base_phone/res_company_view.xml

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="view_company_form" model="ir.ui.view">
@ -30,4 +29,4 @@
</data>
</openerp>
</odoo>

11
base_phone/res_partner_view.xml

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Base Phone module for OpenERP
Copyright (C) 2010-2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="view_partner_form" model="ir.ui.view">
@ -31,8 +30,8 @@
</record>
<record id="base.action_partner_form" model="ir.actions.act_window">
<field name="context">{'search_default_customer':1, 'raise_if_phone_parse_fails': True}</field>
<field name="context">{'search_default_customer': 1, 'raise_if_phone_parse_fails': True}</field>
</record>
</data>
</openerp>
</odoo>

9
base_phone/res_users_view.xml

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Base Phone module for OpenERP
Copyright (C) 2010-2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="view_users_form" model="ir.ui.view">
@ -37,4 +36,4 @@
</record>
</data>
</openerp>
</odoo>

9
base_phone/web_phone.xml

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Base Phone module for OpenERP
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
@ -21,4 +20,4 @@
</data>
</openerp>
</odoo>

12
base_phone/wizard/number_not_found.py

@ -59,8 +59,8 @@ class NumberNotFound(models.TransientModel):
if not res:
res = {}
if res.get('calling_number'):
convert = self.env['res.partner']._generic_reformat_phonenumbers(
None, {'phone': res.get('calling_number')})
convert = self.env['res.partner']._reformat_phonenumbers_create(
{'phone': res.get('calling_number')})
parsed_num = phonenumbers.parse(convert.get('phone'))
res['e164_number'] = phonenumbers.format_number(
parsed_num, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
@ -93,13 +93,13 @@ class NumberNotFound(models.TransientModel):
@api.multi
def update_partner(self):
self.ensure_one()
wiz = self[0]
if not wiz.to_update_partner_id:
raise exceptions.Warning(
_('Error'),
_('Select the Partner to Update.'))
self.env['res.partner'].write(
wiz.to_update_partner_id.id,
wiz.to_update_partner_id.write(
{wiz.number_type: wiz.e164_number})
action = {
'name': _('Partner: %s' % wiz.to_update_partner_id.name),
@ -115,5 +115,5 @@ class NumberNotFound(models.TransientModel):
@api.onchange('to_update_partner_id')
def onchange_to_update_partner(self):
self.current_partner_phone = self.to_update_partner.phone or False
self.current_partner_mobile = self.to_update_partner.mobile or False
self.current_partner_phone = self.to_update_partner_id.phone or False
self.current_partner_mobile = self.to_update_partner_id.mobile or False

11
base_phone/wizard/number_not_found_view.xml

@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012-2015 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2012-2016 (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="number_not_found_form" model="ir.ui.view">
<field name="name">number.not.found.form</field>
<field name="model">number.not.found</field>
<field name="arch" type="xml">
<form string="Number Not Found" version="7.0">
<form string="Number Not Found">
<div class="oe_title">
<label string="Number not found:" for="calling_number"/>
<h1>
@ -50,4 +51,4 @@
</data>
</openerp>
</odoo>

30
crm_phone/__openerp__.py

@ -1,28 +1,10 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# CRM Phone module for OpenERP
# Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'CRM Phone',
'version': '8.0.0.1.0',
'version': '9.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers in CRM',
@ -50,8 +32,6 @@ for any help or question about this module.
'wizard/create_crm_phonecall_view.xml',
],
'test': ['test/phonenum.yml'],
'images': [],
'installable': False,
'installable': True,
'auto_install': True,
'active': False,
}

38
crm_phone/crm_phone.py

@ -31,17 +31,15 @@ class CrmLead(models.Model):
_country_field = 'country_id'
_partner_field = None
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, None, vals, context=context)
return super(CrmLead, self).create(
cr, uid, vals_reformated, context=context)
@api.model
def create(self, vals):
vals_reformated = self._reformat_phonenumbers_create(vals)
return super(CrmLead, self).create(vals_reformated)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, ids, vals, context=context)
return super(CrmLead, self).write(
cr, uid, ids, vals_reformated, context=context)
@api.multi
def write(self, vals):
vals_reformated = self._reformat_phonenumbers_write(vals)
return super(CrmLead, self).write(vals_reformated)
def name_get(self, cr, uid, ids, context=None):
if context is None:
@ -66,26 +64,6 @@ class CrmLead(models.Model):
cr, uid, ids, context=context)
class CrmPhonecall(models.Model):
_name = 'crm.phonecall'
_inherit = ['crm.phonecall', 'phone.common']
_phone_fields = ['partner_phone', 'partner_mobile']
_country_field = None
_partner_field = 'partner_id'
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, None, vals, context=context)
return super(CrmPhonecall, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, ids, vals, context=context)
return super(CrmPhonecall, self).write(
cr, uid, ids, vals_reformated, context=context)
class ResUsers(models.Model):
_inherit = "res.users"

39
crm_phone/crm_view.xml

@ -1,20 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="crm_case_form_view_leads" model="ir.ui.view">
<field name="name">crm_phone.crm_lead.form</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<field name="phone" position="attributes">
<attribute name="widget">phone</attribute>
</field>
<field name="mobile" position="attributes">
<attribute name="widget">phone</attribute>
</field>
@ -40,9 +38,6 @@
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<field name="phone" position="attributes">
<attribute name="widget">phone</attribute>
</field>
<field name="mobile" position="attributes">
<attribute name="widget">phone</attribute>
</field>
@ -52,30 +47,6 @@
</field>
</record>
<record id="crm_case_phone_form_view" model="ir.ui.view">
<field name="name">crm_phone.crm_phonecall.form</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_phone_form_view"/>
<field name="arch" type="xml">
<field name="partner_phone" position="attributes">
<attribute name="widget">phone</attribute>
</field>
<field name="partner_mobile" position="attributes">
<attribute name="widget">phone</attribute>
</field>
</field>
</record>
<record id="crm_case_phone_tree_view" model="ir.ui.view">
<field name="name">crm_phone.crm_phonecall.tree</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_phone_tree_view"/>
<field name="arch" type="xml">
<field name="partner_phone" position="attributes">
<attribute name="widget">phone</attribute>
</field>
</field>
</record>
</data>
</openerp>
</odoo>

9
crm_phone/res_users_view.xml

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2012-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<!-- Add option on user form view -->
@ -34,4 +33,4 @@
</record>
</data>
</openerp>
</odoo>

19
crm_phone/wizard/__init__.py

@ -1,23 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# CRM Phone module for OpenERP
# Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import number_not_found
from . import create_crm_phonecall

32
crm_phone/wizard/create_crm_phonecall.py

@ -1,30 +1,14 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# CRM Phone module for Odoo
# Copyright (c) 2012-2015 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2012-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, api, _
import phonenumbers
class wizard_create_crm_phonecall(models.TransientModel):
# TODO : crm.phonecall : doesn't exist any more... what is the replacement ?
class WizardCreateCrmPhonecall(models.TransientModel):
_name = "wizard.create.crm.phonecall"
@api.multi
@ -63,10 +47,10 @@ class wizard_create_crm_phonecall(models.TransientModel):
self.env.context.get('phone_number')
return {
'name': _('Phone Call'),
'domain': domain,
'type': 'ir.actions.act_window',
'res_model': 'crm.phonecall',
'domain': domain,
'view_mode': 'form,tree',
'type': 'ir.actions.act_window',
'nodestroy': False, # close the pop-up wizard after action
'target': 'current',
'context': action_ctx,

99
crm_phone/wizard/number_not_found.py

@ -1,49 +1,29 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# CRM Phone module for Odoo
# Copyright (C) 2010-2015 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2010-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.osv import orm, fields
from openerp.tools.translate import _
from openerp import models, fields, api, _
from openerp.exceptions import UserError
class number_not_found(orm.TransientModel):
class NumberNotFound(models.TransientModel):
_inherit = "number.not.found"
_columns = {
'to_update_lead_id': fields.many2one(
'crm.lead', 'Lead to Update',
to_update_lead_id = fields.Many2one(
'crm.lead', string='Lead to Update',
domain=[('type', '=', 'lead')],
help="Lead on which the phone number will be written"),
'current_lead_phone': fields.related(
'to_update_lead_id', 'phone', type='char',
relation='crm.lead', string='Current Phone', readonly=True),
'current_lead_mobile': fields.related(
'to_update_lead_id', 'mobile', type='char',
relation='crm.lead', string='Current Mobile', readonly=True),
}
help="Lead on which the phone number will be written")
current_lead_phone = fields.Char(
related='to_update_lead_id.phone', string='Current Phone',
readonly=True)
current_lead_mobile = fields.Char(
related='to_update_lead_id.mobile', string='Current Mobile',
readonly=True)
def create_lead(self, cr, uid, ids, context=None):
@api.multi
def create_lead(self):
'''Function called by the related button of the wizard'''
if context is None:
context = {}
wiz = self.browse(cr, uid, ids[0], context=context)
self.ensure_one()
action = {
'name': _('Create New Lead'),
@ -54,7 +34,7 @@ class number_not_found(orm.TransientModel):
'nodestroy': False,
'target': 'current',
'context': {
'default_%s' % wiz.number_type: wiz.e164_number,
'default_%s' % self.number_type: self.e164_number,
'default_type': 'lead',
'stage_type': 'lead',
'needaction_menu_ref': 'crm.menu_crm_opportunities',
@ -62,23 +42,20 @@ class number_not_found(orm.TransientModel):
}
return action
def update_lead(self, cr, uid, ids, context=None):
wiz = self.browse(cr, uid, ids[0], context=context)
if not wiz.to_update_lead_id:
raise orm.except_orm(
_('Error:'),
_("Select the Lead to Update."))
self.pool['crm.lead'].write(
cr, uid, wiz.to_update_lead_id.id,
{wiz.number_type: wiz.e164_number}, context=context)
@api.multi
def update_lead(self):
self.ensure_one()
if not self.to_update_lead_id:
raise UserError(_("Select the Lead to Update."))
self.to_update_lead_id.write({self.number_type: self.e164_number})
action = {
'name': _('Lead: %s' % wiz.to_update_lead_id.name),
'name': _('Lead: %s' % self.to_update_lead_id.name),
'type': 'ir.actions.act_window',
'res_model': 'crm.lead',
'view_mode': 'form,tree',
'nodestroy': False,
'target': 'current',
'res_id': wiz.to_update_lead_id.id,
'res_id': self.to_update_lead_id.id,
'context': {
'stage_type': 'lead',
'needaction_menu_ref': 'crm.menu_crm_opportunities',
@ -86,19 +63,11 @@ class number_not_found(orm.TransientModel):
}
return action
def onchange_to_update_lead(
self, cr, uid, ids, to_update_lead_id, context=None):
res = {'value': {}}
if to_update_lead_id:
to_update_lead = self.pool['crm.lead'].browse(
cr, uid, to_update_lead_id, context=context)
res['value'].update({
'current_lead_phone': to_update_lead.phone,
'current_lead_mobile': to_update_lead.mobile,
})
@api.onchange('to_update_lead_id')
def onchange_to_update_lead(self):
if self.to_update_lead_id:
self.current_lead_phone = self.to_update_lead_id.phone
self.current_lead_mobile = self.to_update_lead_id.mobile
else:
res['value'].update({
'current_lead_phone': False,
'current_lead_mobile': False,
})
return res
self.current_lead_phone = False
self.current_lead_mobile = False

14
crm_phone/wizard/number_not_found_view.xml

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
CRM Phone module for OpenERP
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<odoo>
<data>
<record id="number_not_found_form" model="ir.ui.view">
@ -15,11 +14,10 @@
<field name="arch" type="xml">
<group name="create-update" position="inside">
<group name="lead" string="Create or Update a Lead"
colspan="1" col="2">
colspan="1">
<button name="create_lead" colspan="2"
string="Create Lead with this Number" type="object"/>
<field name="to_update_lead_id"
on_change="onchange_to_update_lead(to_update_lead_id)"/>
<field name="to_update_lead_id"/>
<field name="current_lead_phone" widget="phone"
options="{'dial_button_invisible': True}"/>
<field name="current_lead_mobile" widget="phone"
@ -33,4 +31,4 @@
</data>
</openerp>
</odoo>
Loading…
Cancel
Save