Browse Source

Use RFC 2806 : add a fax: URL and convert callto: URLs to tel: URLs

The wizard "Reformat phones numbers" is now extended to objects other than res.partner
Update coding standard
Don't use xpath in inherited views when not necessary
pull/7/head
Alexis de Lattre 11 years ago
parent
commit
ee958d9d31
  1. 4
      asterisk_click2dial/__init__.py
  2. 61
      asterisk_click2dial/asterisk_click2dial.py
  3. 2
      asterisk_click2dial/asterisk_server_view.xml
  4. 3
      asterisk_click2dial/res_partner_view.xml
  5. 31
      asterisk_click2dial/static/src/js/phone_widget.js
  6. 19
      asterisk_click2dial/static/src/xml/phone.xml
  7. 4
      asterisk_click2dial/wizard/__init__.py
  8. 13
      asterisk_click2dial/wizard/open_calling_partner.py
  9. 48
      asterisk_click2dial/wizard/reformat_all_phonenumbers.py
  10. 4
      asterisk_click2dial_crm/__init__.py
  11. 9
      asterisk_click2dial_crm/asterisk_click2dial_crm.py
  12. 24
      asterisk_click2dial_crm/crm_lead_view.xml
  13. 3
      asterisk_click2dial_crm/wizard/__init__.py
  14. 9
      asterisk_click2dial_crm/wizard/create_crm_phonecall.py
  15. 36
      asterisk_click2dial_crm/wizard/reformat_all_phonenumbers.py
  16. 4
      asterisk_click2dial_crm_claim/__init__.py
  17. 4
      asterisk_click2dial_crm_claim/asterisk_click2dial_crm_claim.py
  18. 3
      asterisk_click2dial_crm_claim/wizard/__init__.py
  19. 4
      asterisk_click2dial_crm_claim/wizard/open_calling_partner.py
  20. 36
      asterisk_click2dial_crm_claim/wizard/reformat_all_phonenumbers.py
  21. 4
      asterisk_click2dial_registration/__init__.py
  22. 4
      asterisk_click2dial_registration/asterisk_click2dial_registration.py
  23. 2
      asterisk_click2dial_registration/wizard/__init__.py
  24. 4
      asterisk_click2dial_registration/wizard/open_calling_partner.py

4
asterisk_click2dial/__init__.py

@ -19,5 +19,5 @@
# #
############################################################################## ##############################################################################
import asterisk_click2dial
import wizard
from . import asterisk_click2dial
from . import wizard

61
asterisk_click2dial/asterisk_click2dial.py

@ -19,11 +19,9 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields, orm
# Lib required to print logs
import logging
# Lib to translate error messages
from openerp.osv import fields, orm
from openerp.tools.translate import _ from openerp.tools.translate import _
import logging
# Lib for phone number reformating -> pip install phonenumbers # Lib for phone number reformating -> pip install phonenumbers
import phonenumbers import phonenumbers
# Lib py-asterisk from http://code.google.com/p/py-asterisk/ # Lib py-asterisk from http://code.google.com/p/py-asterisk/
@ -33,7 +31,7 @@ from Asterisk import Manager
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class asterisk_server(osv.osv):
class asterisk_server(orm.Model):
'''Asterisk server object, to store all the parameters of the Asterisk IPBXs''' '''Asterisk server object, to store all the parameters of the Asterisk IPBXs'''
_name = "asterisk.server" _name = "asterisk.server"
_description = "Asterisk Servers" _description = "Asterisk Servers"
@ -90,21 +88,21 @@ class asterisk_server(osv.osv):
for digit_prefix in [country_prefix, international_prefix, out_prefix, national_prefix]: for digit_prefix in [country_prefix, international_prefix, out_prefix, national_prefix]:
if digit_prefix[1] and not digit_prefix[1].isdigit(): if digit_prefix[1] and not digit_prefix[1].isdigit():
raise osv.except_osv(_('Error :'), _("Only use digits for the '%s' on the Asterisk server '%s'" % (digit_prefix[0], server.name)))
raise orm.except_orm(_('Error :'), _("Only use digits for the '%s' on the Asterisk server '%s'" % (digit_prefix[0], server.name)))
if server.wait_time < 1 or server.wait_time > 120: if server.wait_time < 1 or server.wait_time > 120:
raise osv.except_osv(_('Error :'), _("You should set a 'Wait time' value between 1 and 120 seconds for the Asterisk server '%s'" % server.name))
raise orm.except_orm(_('Error :'), _("You should set a 'Wait time' value between 1 and 120 seconds for the Asterisk server '%s'" % server.name))
if server.extension_priority < 1: if server.extension_priority < 1:
raise osv.except_osv(_('Error :'), _("The 'extension priority' must be a positive value for the Asterisk server '%s'" % server.name))
raise orm.except_orm(_('Error :'), _("The 'extension priority' must be a positive value for the Asterisk server '%s'" % server.name))
if server.port > 65535 or server.port < 1: if server.port > 65535 or server.port < 1:
raise osv.except_osv(_('Error :'), _("You should set a TCP port between 1 and 65535 for the Asterisk server '%s'" % server.name))
raise orm.except_orm(_('Error :'), _("You should set a TCP port between 1 and 65535 for the Asterisk server '%s'" % server.name))
if server.number_of_digits_to_match_from_end > 20 or server.number_of_digits_to_match_from_end < 1: if server.number_of_digits_to_match_from_end > 20 or server.number_of_digits_to_match_from_end < 1:
raise osv.except_osv(_('Error :'), _("You should set a 'Number of digits to match from end' between 1 and 20 for the Asterisk server '%s'" % server.name))
raise orm.except_orm(_('Error :'), _("You should set a 'Number of digits to match from end' between 1 and 20 for the Asterisk server '%s'" % server.name))
for check_string in [dialplan_context, alert_info, login, password]: for check_string in [dialplan_context, alert_info, login, password]:
if check_string[1]: if check_string[1]:
try: try:
string = check_string[1].encode('ascii') string = check_string[1].encode('ascii')
except UnicodeEncodeError: except UnicodeEncodeError:
raise osv.except_osv(_('Error :'), _("The '%s' should only have ASCII caracters for the Asterisk server '%s'" % (check_string[0], server.name)))
raise orm.except_orm(_('Error :'), _("The '%s' should only have ASCII caracters for the Asterisk server '%s'" % (check_string[0], server.name)))
return True return True
@ -133,7 +131,7 @@ class asterisk_server(osv.osv):
# Check if empty # Check if empty
if not tmp_number: if not tmp_number:
raise osv.except_osv(error_title_msg, invalid_format_msg)
raise orm.except_orm(error_title_msg, invalid_format_msg)
# Before starting to use prefix, we convert empty prefix whose value # Before starting to use prefix, we convert empty prefix whose value
# is False to an empty string # is False to an empty string
@ -155,7 +153,7 @@ class asterisk_server(osv.osv):
# At this stage, 'tmp_number' should only contain digits # At this stage, 'tmp_number' should only contain digits
if not tmp_number.isdigit(): if not tmp_number.isdigit():
raise osv.except_osv(error_title_msg, invalid_format_msg)
raise orm.except_orm(error_title_msg, invalid_format_msg)
_logger.debug('Country prefix = %s' % country_prefix) _logger.debug('Country prefix = %s' % country_prefix)
if country_prefix == tmp_number[0:len(country_prefix)]: if country_prefix == tmp_number[0:len(country_prefix)]:
@ -202,7 +200,7 @@ class asterisk_server(osv.osv):
asterisk_server_ids = self.search(cr, uid, [('company_id', '=', user.company_id.id)], context=context) asterisk_server_ids = self.search(cr, uid, [('company_id', '=', user.company_id.id)], context=context)
# If no asterisk server is configured on the user, we take the first one # If no asterisk server is configured on the user, we take the first one
if not asterisk_server_ids: if not asterisk_server_ids:
raise osv.except_osv(_('Error :'), _("No Asterisk server configured for the company '%s'.") % user.company_id.name)
raise orm.except_orm(_('Error :'), _("No Asterisk server configured for the company '%s'.") % user.company_id.name)
else: else:
ast_server = self.browse(cr, uid, asterisk_server_ids[0], context=context) ast_server = self.browse(cr, uid, asterisk_server_ids[0], context=context)
return ast_server return ast_server
@ -222,11 +220,11 @@ class asterisk_server(osv.osv):
ast_server = self._get_asterisk_server_from_user(cr, uid, context=context) ast_server = self._get_asterisk_server_from_user(cr, uid, context=context)
# We check if the current user has a chan type # We check if the current user has a chan type
if not user.asterisk_chan_type: if not user.asterisk_chan_type:
raise osv.except_osv(_('Error :'), _('No channel type configured for the current user.'))
raise orm.except_orm(_('Error :'), _('No channel type configured for the current user.'))
# We check if the current user has an internal number # We check if the current user has an internal number
if not user.resource: if not user.resource:
raise osv.except_osv(_('Error :'), _('No resource name configured for the current user'))
raise orm.except_orm(_('Error :'), _('No resource name configured for the current user'))
_logger.debug("User's phone : %s/%s" % (user.asterisk_chan_type, user.resource)) _logger.debug("User's phone : %s/%s" % (user.asterisk_chan_type, user.resource))
@ -238,7 +236,7 @@ class asterisk_server(osv.osv):
except Exception, e: except Exception, e:
_logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address) _logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : %s" % e.strerror) _logger.error("Here is the detail of the error : %s" % e.strerror)
raise osv.except_osv(_('Error :'), _("Problem in the request from OpenERP to Asterisk. Here is the detail of the error: %s." % e.strerror))
raise orm.except_orm(_('Error :'), _("Problem in the request from OpenERP to Asterisk. Here is the detail of the error: %s." % e.strerror))
return False return False
return (user, ast_server, ast_manager) return (user, ast_server, ast_manager)
@ -246,14 +244,14 @@ class asterisk_server(osv.osv):
def _dial_with_asterisk(self, cr, uid, erp_number, context=None): def _dial_with_asterisk(self, cr, uid, erp_number, context=None):
#print "_dial_with_asterisk erp_number=", erp_number #print "_dial_with_asterisk erp_number=", erp_number
if not erp_number: if not erp_number:
raise osv.except_osv(_('Error :'), "Hara kiri : you must call the function with erp_number")
raise orm.except_orm(_('Error :'), "Hara kiri : you must call the function with erp_number")
user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context) user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context)
ast_number = self._reformat_number(cr, uid, erp_number, ast_server, context=context) ast_number = self._reformat_number(cr, uid, erp_number, ast_server, context=context)
# The user should have a CallerID # The user should have a CallerID
if not user.callerid: if not user.callerid:
raise osv.except_osv(_('Error :'), _('No callerID configured for the current user'))
raise orm.except_orm(_('Error :'), _('No callerID configured for the current user'))
variable = [] variable = []
if user.asterisk_chan_type == 'SIP': if user.asterisk_chan_type == 'SIP':
@ -279,7 +277,7 @@ class asterisk_server(osv.osv):
except Exception, e: except Exception, e:
_logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address) _logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : '%s'" % unicode(e)) _logger.error("Here is the detail of the error : '%s'" % unicode(e))
raise osv.except_osv(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e)))
raise orm.except_orm(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e)))
finally: finally:
ast_manager.Logoff() ast_manager.Logoff()
@ -313,7 +311,7 @@ class asterisk_server(osv.osv):
except Exception, e: except Exception, e:
_logger.error("Error in the Status request to Asterisk server %s" % ast_server.ip_address) _logger.error("Error in the Status request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : '%s'" % unicode(e)) _logger.error("Here is the detail of the error : '%s'" % unicode(e))
raise osv.except_osv(_('Error :'), _("Can't get calling number from Asterisk.\nHere is the error: '%s'" % unicode(e)))
raise orm.except_orm(_('Error :'), _("Can't get calling number from Asterisk.\nHere is the error: '%s'" % unicode(e)))
finally: finally:
ast_manager.Logoff() ast_manager.Logoff()
@ -325,7 +323,7 @@ class asterisk_server(osv.osv):
# Parameters specific for each user # Parameters specific for each user
class res_users(osv.osv):
class res_users(orm.Model):
_inherit = "res.users" _inherit = "res.users"
_columns = { _columns = {
@ -371,7 +369,7 @@ class res_users(osv.osv):
try: try:
plom = check_string[1].encode('ascii') plom = check_string[1].encode('ascii')
except UnicodeEncodeError: except UnicodeEncodeError:
raise osv.except_osv(_('Error :'), _("The '%s' for the user '%s' should only have ASCII caracters" % (check_string[0], user.name)))
raise orm.except_orm(_('Error :'), _("The '%s' for the user '%s' should only have ASCII caracters" % (check_string[0], user.name)))
return True return True
_constraints = [ _constraints = [
@ -387,14 +385,14 @@ class asterisk_common(orm.AbstractModel):
if context is None: if context is None:
context = {} context = {}
if not isinstance(context.get('field2dial'), (unicode, str)): if not isinstance(context.get('field2dial'), (unicode, str)):
raise osv.except_osv(_('Error :'), "The function action_dial must be called with a 'field2dial' key in the context containing a string '<phone_field>'.")
raise orm.except_orm(_('Error :'), "The function action_dial must be called with a 'field2dial' key in the context containing a string '<phone_field>'.")
else: else:
phone_field = context.get('field2dial') phone_field = context.get('field2dial')
erp_number_read = self.read(cr, uid, ids[0], [phone_field], context=context) erp_number_read = self.read(cr, uid, ids[0], [phone_field], context=context)
erp_number_e164 = erp_number_read[phone_field] erp_number_e164 = erp_number_read[phone_field]
# Check if the number to dial is not empty # Check if the number to dial is not empty
if not erp_number_e164: if not erp_number_e164:
raise osv.except_osv(_('Error :'), _('There is no phone number !'))
raise orm.except_orm(_('Error :'), _('There is no phone number !'))
return self.pool['asterisk.server']._dial_with_asterisk(cr, uid, erp_number_e164, context=context) return self.pool['asterisk.server']._dial_with_asterisk(cr, uid, erp_number_e164, context=context)
@ -414,7 +412,7 @@ class asterisk_common(orm.AbstractModel):
_logger.error("You should fix this number and run the wizard 'Reformat all phone numbers' from the menu Settings > Configuration > Asterisk") _logger.error("You should fix this number and run the wizard 'Reformat all phone numbers' from the menu Settings > Configuration > Asterisk")
# If I raise an exception here, it won't be possible to install # If I raise an exception here, it won't be possible to install
# the module on a DB with bad phone numbers # the module on a DB with bad phone numbers
#raise osv.except_osv(_('Error :'), _("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (record.get(fromfield), e)))
#raise orm.except_orm(_('Error :'), _("Cannot reformat the phone number '%s' to E.164 format. Error message: %s" % (record.get(fromfield), e)))
res = False res = False
result[record['id']][tofield] = res result[record['id']][tofield] = res
#print "RESULT generic_phonenumber_to_e164", result #print "RESULT generic_phonenumber_to_e164", result
@ -430,21 +428,24 @@ class asterisk_common(orm.AbstractModel):
user_countrycode = user.company_id.country_id.code user_countrycode = user.company_id.country_id.code
else: else:
# We need to raise an exception here because, if we pass None as second arg of phonenumbers.parse(), it will raise an exception when you try to enter a phone number in national format... so it's better to raise the exception here # We need to raise an exception here because, if we pass None as second arg of phonenumbers.parse(), it will raise an exception when you try to enter a phone number in national format... so it's better to raise the exception here
raise osv.except_osv(_('Error :'), _("You should set a country on the company '%s'" % user.company_id.name))
raise orm.except_orm(_('Error :'), _("You should set a country on the company '%s'" % user.company_id.name))
#print "user_countrycode=", user_countrycode #print "user_countrycode=", user_countrycode
for field in phonefields: for field in phonefields:
if vals.get(field): if vals.get(field):
init_value = vals.get(field)
try: try:
res_parse = phonenumbers.parse(vals.get(field), user_countrycode) res_parse = phonenumbers.parse(vals.get(field), user_countrycode)
except Exception, e: except Exception, e:
raise osv.except_osv(_('Error :'), _("Cannot reformat the phone number '%s' to international format. Error message: %s" % (vals.get(field), e)))
raise orm.except_orm(_('Error :'), _("Cannot reformat the phone number '%s' to international format. Error message: %s" % (vals.get(field), e)))
#print "res_parse=", res_parse #print "res_parse=", res_parse
vals[field] = phonenumbers.format_number(res_parse, phonenumbers.PhoneNumberFormat.E164) vals[field] = phonenumbers.format_number(res_parse, phonenumbers.PhoneNumberFormat.E164)
if init_value != vals[field]:
_logger.info("%s initial value: '%s' updated value: '%s'" % (field, init_value, vals[field]))
return vals return vals
class res_partner(osv.osv):
class res_partner(orm.Model):
_name = 'res.partner' _name = 'res.partner'
_inherit = ['res.partner', 'asterisk.common'] _inherit = ['res.partner', 'asterisk.common']
@ -509,7 +510,7 @@ class res_partner(osv.osv):
# This module supports multi-company # This module supports multi-company
class res_company(osv.osv):
class res_company(orm.Model):
_inherit = "res.company" _inherit = "res.company"
_columns = { _columns = {

2
asterisk_click2dial/asterisk_server_view.xml

@ -47,7 +47,7 @@
<field name="name"/> <field name="name"/>
</h1> </h1>
</div> </div>
<group>
<group name="main">
<field name="company_id" invisible="not context.get('asterisk_server_main_view', False)" groups="base.group_multi_company"/> <field name="company_id" invisible="not context.get('asterisk_server_main_view', False)" groups="base.group_multi_company"/>
<field name="active" /> <field name="active" />
<field name="ip_address" /> <field name="ip_address" />

3
asterisk_click2dial/res_partner_view.xml

@ -50,6 +50,9 @@
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/> <button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group> </group>
</xpath> </xpath>
<xpath expr="//group/group/field[@name='fax']" position="attributes">
<attribute name="widget">fax</attribute>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/group/field[@name='phone']" position="replace"> <xpath expr="//form[@string='Contact']/sheet/group/field[@name='phone']" position="replace">
<group colspan="2" col="8"> <group colspan="2" col="8">
<field name="phone" widget="phone" colspan="7" /> <field name="phone" widget="phone" colspan="7" />

31
asterisk_click2dial/static/src/js/phone_widget.js

@ -19,15 +19,42 @@ openerp.asterisk_click2dial = function (instance) {
} else { } else {
var formatted_number = formatInternational('', this.get('value')) var formatted_number = formatInternational('', this.get('value'))
this.$el.find('a') this.$el.find('a')
.attr('href', 'callto:' + this.get('value'))
.attr('href', 'tel:' + this.get('value'))
.text(formatted_number || ''); .text(formatted_number || '');
} }
}, },
on_button_clicked: function() { on_button_clicked: function() {
location.href = 'callto:' + this.get('value');
location.href = 'tel:' + this.get('value');
} }
}); });
instance.web.form.widgets.add('phone', 'instance.asterisk_click2dial.FieldPhone'); instance.web.form.widgets.add('phone', 'instance.asterisk_click2dial.FieldPhone');
instance.asterisk_click2dial.FieldFax = instance.web.form.FieldChar.extend({
template: 'FieldFax',
initialize_content: function() {
this._super();
var $button = this.$el.find('button');
$button.click(this.on_button_clicked);
this.setupFocus($button);
},
render_value: function() {
if (!this.get("effective_readonly")) {
this._super();
} else {
var formatted_number = formatInternational('', this.get('value'))
this.$el.find('a')
.attr('href', 'fax:' + this.get('value'))
.text(formatted_number || '');
}
},
on_button_clicked: function() {
location.href = 'fax:' + this.get('value');
}
});
instance.web.form.widgets.add('fax', 'instance.asterisk_click2dial.FieldFax');
} }

19
asterisk_click2dial/static/src/xml/phone.xml

@ -6,6 +6,7 @@
--> -->
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-name="FieldPhone"> <t t-name="FieldPhone">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style"> <span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri" target="_blank"/> <a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri" target="_blank"/>
@ -22,4 +23,22 @@
</t> </t>
</span> </span>
</t> </t>
<t t-name="FieldFax">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri" target="_blank"/>
<t t-if="!widget.get('effective_readonly')">
<div>
<input type="text"
t-att-id="widget.id_for_label"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-placeholder="widget.node.attrs.placeholder"
t-att-maxlength="widget.field.size"
/>
</div>
</t>
</span>
</t>
</templates> </templates>

4
asterisk_click2dial/wizard/__init__.py

@ -19,5 +19,5 @@
# #
############################################################################## ##############################################################################
import reformat_all_phonenumbers
import open_calling_partner
from . import reformat_all_phonenumbers
from . import open_calling_partner

13
asterisk_click2dial/wizard/open_calling_partner.py

@ -19,15 +19,14 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
import logging
# Lib to translate error messages
from openerp.osv import orm, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class wizard_open_calling_partner(osv.osv_memory):
class wizard_open_calling_partner(orm.TransientModel):
_name = "wizard.open.calling.partner" _name = "wizard.open.calling.partner"
_description = "Open calling partner" _description = "Open calling partner"
@ -63,7 +62,7 @@ class wizard_open_calling_partner(osv.osv_memory):
res['to_update_partner_id'] = False res['to_update_partner_id'] = False
else: else:
_logger.debug("Could not get the calling number from Asterisk.") _logger.debug("Could not get the calling number from Asterisk.")
raise osv.except_osv(_('Error :'), _("Could not get the calling number from Asterisk. Is your phone ringing or are you currently on the phone ? If yes, check your setup and look at the OpenERP debug logs."))
raise orm.except_orm(_('Error :'), _("Could not get the calling number from Asterisk. Is your phone ringing or are you currently on the phone ? If yes, check your setup and look at the OpenERP debug logs."))
return res return res
@ -75,7 +74,7 @@ class wizard_open_calling_partner(osv.osv_memory):
# and I don't want to add a dependancy on "sale" or "account" # and I don't want to add a dependancy on "sale" or "account"
# So I just check here that the model exists, to avoid a crash # So I just check here that the model exists, to avoid a crash
if not self.pool['ir.model'].search(cr, uid, [('model', '=', oerp_object._name)], context=context): if not self.pool['ir.model'].search(cr, uid, [('model', '=', oerp_object._name)], context=context):
raise osv.except_osv(_('Error :'), _("The object '%s' is not found in your OpenERP database, probably because the related module is not installed." % oerp_object._description))
raise orm.except_orm(_('Error :'), _("The object '%s' is not found in your OpenERP database, probably because the related module is not installed." % oerp_object._description))
partner = self.read(cr, uid, ids[0], ['partner_id', 'parent_partner_id'], context=context) partner = self.read(cr, uid, ids[0], ['partner_id', 'parent_partner_id'], context=context)
partner_id_to_filter = partner['parent_partner_id'] and partner['parent_partner_id'][0] or (partner['partner_id'] and partner['partner_id'][0] or False) partner_id_to_filter = partner['parent_partner_id'] and partner['parent_partner_id'][0] or (partner['partner_id'] and partner['partner_id'][0] or False)
@ -166,7 +165,7 @@ class wizard_open_calling_partner(osv.osv_memory):
def update_partner(self, cr, uid, ids, phone_type='mobile', context=None): def update_partner(self, cr, uid, ids, phone_type='mobile', context=None):
cur_wizard = self.browse(cr, uid, ids[0], context=context) cur_wizard = self.browse(cr, uid, ids[0], context=context)
if not cur_wizard.to_update_partner_id: if not cur_wizard.to_update_partner_id:
raise osv.except_osv(_('Error :'), _("Select the partner to update."))
raise orm.except_orm(_('Error :'), _("Select the partner to update."))
ast_server = self.pool['asterisk.server']._get_asterisk_server_from_user(cr, uid, context=context) ast_server = self.pool['asterisk.server']._get_asterisk_server_from_user(cr, uid, context=context)
number_to_write = self.pool['asterisk.server']._convert_number_to_international_format(cr, uid, cur_wizard.calling_number, ast_server, context=context) number_to_write = self.pool['asterisk.server']._convert_number_to_international_format(cr, uid, cur_wizard.calling_number, ast_server, context=context)
self.pool['res.partner'].write(cr, uid, cur_wizard.to_update_partner_id.id, {phone_type: number_to_write}, context=context) self.pool['res.partner'].write(cr, uid, cur_wizard.to_update_partner_id.id, {phone_type: number_to_write}, context=context)

48
asterisk_click2dial/wizard/reformat_all_phonenumbers.py

@ -19,13 +19,13 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
import logging
from openerp.osv import orm, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class reformat_all_phonenumbers(osv.osv_memory):
class reformat_all_phonenumbers(orm.TransientModel):
_name = "reformat.all.phonenumbers" _name = "reformat.all.phonenumbers"
_description = "Reformat all phone numbers" _description = "Reformat all phone numbers"
@ -34,28 +34,38 @@ class reformat_all_phonenumbers(osv.osv_memory):
} }
def _extend_reformat_phonenumbers(self, cr, uid, context=None):
'''This function is designed to be inherited
to extend the functionnality to objects other than res.partner'''
res = {
self.pool['res.partner']: {
'allids': self.pool['res.partner'].search(cr, uid, ['|', ('active', '=', True), ('active', '=', False)], context=context),
'phonefields': ['phone', 'fax', 'mobile'],
'namefield': 'name',
}
}
return res
def run_reformat_all_phonenumbers(self, cr, uid, ids, context=None): def run_reformat_all_phonenumbers(self, cr, uid, ids, context=None):
partner_obj = self.pool['res.partner']
phonefields = ['phone', 'fax', 'mobile']
_logger.info('Starting to reformat all the phone numbers') _logger.info('Starting to reformat all the phone numbers')
all_partner_ids = partner_obj.search(cr, uid, ['|', ('active', '=', True), ('active', '=', False)], context=context)
phonenumbers_not_reformatted = '' phonenumbers_not_reformatted = ''
for partner in partner_obj.read(cr, uid, all_partner_ids, ['name'] + phonefields, context=context):
init_partner = partner.copy()
# partner is _updated_ by the fonction _generic_reformat_phonenumbers()
toreformat_dict = self._extend_reformat_phonenumbers(cr, uid, context=context)
for obj, prop in toreformat_dict.items():
for entry in obj.read(cr, uid, prop['allids'], [prop['namefield']] + prop['phonefields'], context=context):
init_entry = entry.copy()
# entry is _updated_ by the fonction _generic_reformat_phonenumbers()
try: try:
partner_obj._generic_reformat_phonenumbers(cr, uid, partner, context=context)
obj._generic_reformat_phonenumbers(cr, uid, entry, context=context)
except Exception, e: except Exception, e:
#raise osv.except_osv(_('Error :'), _("Problem on partner '%s'. Error message: %s" % (init_partner.get('name'), e[1])))
phonenumbers_not_reformatted += "Problem on partner '%s'. Error message: %s" % (init_partner.get('name'), e[1]) + "\n"
_logger.warning("Problem on partner '%s'. Error message: %s" % (init_partner.get('name'), e[1]))
#raise orm.except_orm(_('Error :'), _("Problem on entry '%s'. Error message: %s" % (init_entry.get(prop['namefield']), e[1])))
phonenumbers_not_reformatted += "Problem on %s '%s'. Error message: %s" % (obj._description, init_entry.get(prop['namefield']), e[1]) + "\n"
_logger.warning("Problem on %s '%s'. Error message: %s" % (obj._description, init_entry.get(prop['namefield']), e[1]))
continue continue
# Test if the phone numbers have been changed
if any([init_partner.get(field) != partner.get(field) for field in phonefields]):
partner.pop('id')
partner.pop('name')
_logger.info('Reformating phone number: FROM %s TO %s' % (unicode(init_partner), unicode(partner)))
partner_obj.write(cr, uid, init_partner['id'], partner, context=context)
if any([init_entry.get(field) != entry.get(field) for field in prop['phonefields']]):
entry.pop('id')
entry.pop(prop['namefield'])
_logger.info('[%s] Reformating phone number: FROM %s TO %s' % (obj._description, unicode(init_entry), unicode(entry)))
obj.write(cr, uid, init_entry['id'], entry, context=context)
if not phonenumbers_not_reformatted: if not phonenumbers_not_reformatted:
phonenumbers_not_reformatted = 'All phone numbers have been reformatted successfully.' phonenumbers_not_reformatted = 'All phone numbers have been reformatted successfully.'
self.write(cr, uid, ids[0], {'phonenumbers_not_reformatted': phonenumbers_not_reformatted}, context=context) self.write(cr, uid, ids[0], {'phonenumbers_not_reformatted': phonenumbers_not_reformatted}, context=context)

4
asterisk_click2dial_crm/__init__.py

@ -22,5 +22,5 @@
# #
############################################################################## ##############################################################################
import asterisk_click2dial_crm
import wizard
from . import asterisk_click2dial_crm
from . import wizard

9
asterisk_click2dial_crm/asterisk_click2dial_crm.py

@ -23,12 +23,11 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
# Lib to translate error messages
from openerp.osv import orm, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
class res_partner(osv.osv):
class res_partner(orm.Model):
_name = 'res.partner' _name = 'res.partner'
_inherit = ['res.partner', 'asterisk.common'] _inherit = ['res.partner', 'asterisk.common']
@ -60,7 +59,7 @@ class res_partner(osv.osv):
class res_users(osv.osv):
class res_users(orm.Model):
_inherit = "res.users" _inherit = "res.users"
_columns = { _columns = {
@ -74,7 +73,7 @@ class res_users(osv.osv):
'context_propose_creation_crm_call': True, 'context_propose_creation_crm_call': True,
} }
class crm_lead(osv.osv):
class crm_lead(orm.Model):
_name = 'crm.lead' _name = 'crm.lead'
_inherit = ['crm.lead', 'asterisk.common'] _inherit = ['crm.lead', 'asterisk.common']

24
asterisk_click2dial_crm/crm_lead_view.xml

@ -13,22 +13,25 @@
<data> <data>
<record id="asterisk_crm_lead_simplified_form_dial" model="ir.ui.view"> <record id="asterisk_crm_lead_simplified_form_dial" model="ir.ui.view">
<field name="name">asterisk.crm_lead.simplified.form.dial</field>
<field name="name">asterisk.crm_lead.form.dial</field>
<field name="model">crm.lead</field> <field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/> <field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<field name="phone" position="replace">
<group colspan="2" col="8"> <group colspan="2" col="8">
<field name="phone" widget="phone" colspan="7" /> <field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/> <button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group> </group>
</xpath>
<xpath expr="//group/group/field[@name='mobile']" position="replace">
</field>
<field name="mobile" position="replace">
<group colspan="2" col="8"> <group colspan="2" col="8">
<field name="mobile" widget="phone" colspan="7" /> <field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/> <button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group> </group>
</xpath>
</field>
<field name="fax" position="attributes">
<attribute name="widget">fax</attribute>
</field>
</field> </field>
</record> </record>
@ -38,18 +41,21 @@
<field name="model">crm.lead</field> <field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/> <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<field name="phone" position="replace">
<group colspan="2" col="8"> <group colspan="2" col="8">
<field name="phone" widget="phone" colspan="7" /> <field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/> <button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group> </group>
</xpath>
<xpath expr="//group/group/field[@name='mobile']" position="replace">
</field>
<field name="mobile" position="replace">
<group colspan="2" col="8"> <group colspan="2" col="8">
<field name="mobile" widget="phone" colspan="7" /> <field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/> <button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group> </group>
</xpath>
</field>
<field name="fax" position="attributes">
<attribute name="widget">fax</attribute>
</field>
</field> </field>
</record> </record>

3
asterisk_click2dial_crm/wizard/__init__.py

@ -20,4 +20,5 @@
# #
############################################################################## ##############################################################################
import create_crm_phonecall
from . import create_crm_phonecall
from . import reformat_all_phonenumbers

9
asterisk_click2dial_crm/wizard/create_crm_phonecall.py

@ -22,12 +22,11 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
# Lib to translate error messages
from openerp.osv import orm, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
class wizard_create_crm_phonecall(osv.osv_memory):
class wizard_create_crm_phonecall(orm.TransientModel):
_name = "wizard.create.crm.phonecall" _name = "wizard.create.crm.phonecall"
def button_create_outgoing_phonecall(self, cr, uid, ids, context=None): def button_create_outgoing_phonecall(self, cr, uid, ids, context=None):
@ -59,10 +58,9 @@ class wizard_create_crm_phonecall(osv.osv_memory):
'context': context, 'context': context,
} }
wizard_create_crm_phonecall()
class wizard_open_calling_partner(osv.osv_memory):
class wizard_open_calling_partner(orm.TransientModel):
_inherit = "wizard.open.calling.partner" _inherit = "wizard.open.calling.partner"
def create_incoming_phonecall(self, cr, uid, ids, crm_categ, context=None): def create_incoming_phonecall(self, cr, uid, ids, crm_categ, context=None):
@ -71,4 +69,3 @@ class wizard_open_calling_partner(osv.osv_memory):
action = self.pool['wizard.create.crm.phonecall']._create_open_crm_phonecall(cr, uid, partner, crm_categ='Inbound', context=context) action = self.pool['wizard.create.crm.phonecall']._create_open_crm_phonecall(cr, uid, partner, crm_categ='Inbound', context=context)
return action return action
wizard_open_calling_partner()

36
asterisk_click2dial_crm/wizard/reformat_all_phonenumbers.py

@ -0,0 +1,36 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2013 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/>.
#
##############################################################################
from openerp.osv import orm
class reformat_all_phonenumbers(orm.TransientModel):
_inherit = "reformat.all.phonenumbers"
def _extend_reformat_phonenumbers(self, cr, uid, context=None):
res = super(reformat_all_phonenumbers, self)._extend_reformat_phonenumbers(cr, uid, context=context)
res[self.pool['crm.lead']] = {
'allids': self.pool['crm.lead'].search(cr, uid, [], context=context),
'phonefields': ['phone', 'fax', 'mobile'],
'namefield': 'partner_name',
}
return res

4
asterisk_click2dial_crm_claim/__init__.py

@ -20,5 +20,5 @@
# #
############################################################################## ##############################################################################
import wizard
import asterisk_click2dial_crm_claim
from . import wizard
from . import asterisk_click2dial_crm_claim

4
asterisk_click2dial_crm_claim/asterisk_click2dial_crm_claim.py

@ -19,10 +19,10 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
from openerp.osv import orm, fields
class crm_claim(osv.osv):
class crm_claim(orm.Model):
_name = 'crm.claim' _name = 'crm.claim'
_inherit = ['crm.claim', 'asterisk.common'] _inherit = ['crm.claim', 'asterisk.common']

3
asterisk_click2dial_crm_claim/wizard/__init__.py

@ -20,4 +20,5 @@
# #
############################################################################## ##############################################################################
import open_calling_partner
from . import open_calling_partner
from . import reformat_all_phonenumbers

4
asterisk_click2dial_crm_claim/wizard/open_calling_partner.py

@ -20,9 +20,9 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
from openerp.osv import orm, fields
class wizard_open_calling_partner(osv.osv_memory):
class wizard_open_calling_partner(orm.TransientModel):
_inherit = "wizard.open.calling.partner" _inherit = "wizard.open.calling.partner"
def open_crm_claims(self, cr, uid, ids, context=None): def open_crm_claims(self, cr, uid, ids, context=None):

36
asterisk_click2dial_crm_claim/wizard/reformat_all_phonenumbers.py

@ -0,0 +1,36 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial CRM Claim module for OpenERP
# Copyright (c) 2013 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/>.
#
##############################################################################
from openerp.osv import orm
class reformat_all_phonenumbers(orm.TransientModel):
_inherit = "reformat.all.phonenumbers"
def _extend_reformat_phonenumbers(self, cr, uid, context=None):
res = super(reformat_all_phonenumbers, self)._extend_reformat_phonenumbers(cr, uid, context=context)
res[self.pool['crm.claim']] = {
'allids': self.pool['crm.claim'].search(cr, uid, [], context=context),
'phonefields': ['partner_phone'],
'namefield': 'name',
}
return res

4
asterisk_click2dial_registration/__init__.py

@ -19,5 +19,5 @@
# #
############################################################################## ##############################################################################
import wizard
import asterisk_click2dial_registration
from . import wizard
from . import asterisk_click2dial_registration

4
asterisk_click2dial_registration/asterisk_click2dial_registration.py

@ -19,10 +19,10 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv, fields
from openerp.osv import orm, fields
class event_registration(osv.osv):
class event_registration(orm.Model):
_name = 'event.registration' _name = 'event.registration'
_inherit = ['event.registration', 'asterisk.common'] _inherit = ['event.registration', 'asterisk.common']

2
asterisk_click2dial_registration/wizard/__init__.py

@ -19,4 +19,4 @@
# #
############################################################################## ##############################################################################
import open_calling_partner
from . import open_calling_partner

4
asterisk_click2dial_registration/wizard/open_calling_partner.py

@ -19,9 +19,9 @@
# #
############################################################################## ##############################################################################
from openerp.osv import osv
from openerp.osv import orm
class wizard_open_calling_partner(osv.osv_memory):
class wizard_open_calling_partner(orm.TransientModel):
_inherit = "wizard.open.calling.partner" _inherit = "wizard.open.calling.partner"
def open_registrations(self, cr, uid, ids, context=None): def open_registrations(self, cr, uid, ids, context=None):

Loading…
Cancel
Save