Browse Source

For the feature "Open calling party", if the phone number is not in OpenERP, he proposes to create a new partner with this phone or mobile number.

pull/26/head
Alexis de Lattre 13 years ago
parent
commit
3a01e63f36
  1. 27
      asterisk_click2dial/asterisk_click2dial.py
  2. 14
      asterisk_click2dial/res_partner_view.xml

27
asterisk_click2dial/asterisk_click2dial.py

@ -466,7 +466,8 @@ class wizard_open_calling_partner(osv.osv_memory):
res['partner_address_id'] = partner[0]
res['partner_id'] = partner[1]
else:
raise osv.except_osv(_('Error :'), _("Could not find a partner corresponding to the calling number '%s'" % calling_number))
res['partner_id'] = False
res['partner_address_id'] = False
else:
_logger.debug("Could not get the calling number from Asterisk.")
raise osv.except_osv(_('Error :'), _("Could not get the calling number from Asterisk. Check your setup and look at the OpenERP debug logs."))
@ -524,6 +525,30 @@ class wizard_open_calling_partner(osv.osv_memory):
else:
return False
def create_new_partner(self, cr, uid, ids, phone_type='phone', context=None):
'''Function called by the related button of the wizard'''
calling_number = self.read(cr, uid, ids[0], ['calling_number'], context=context)['calling_number']
# TODO : convert the number to the international format +33141981242
new_partner_dict = {'name': 'ENTER PARTNER NAME',
'address': [(0,0, {phone_type: calling_number})]}
new_partner_id = self.pool.get('res.partner').create(cr, uid, new_partner_dict, context=context)
action = {
'name': 'Create new partner',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'type': 'ir.actions.act_window',
'nodestroy': False,
'target': 'current',
'res_id': [new_partner_id],
}
return action
def create_new_partner_phone(self, cr, uid, ids, context=None):
return self.create_new_partner(cr, uid, ids, phone_type='phone', context=context)
def create_new_partner_mobile(self, cr, uid, ids, context=None):
return self.create_new_partner(cr, uid, ids, phone_type='mobile', context=context)
wizard_open_calling_partner()

14
asterisk_click2dial/res_partner_view.xml

@ -92,10 +92,16 @@
<field name="partner_address_id" readonly="1" />
<field name="partner_id" readonly="1" />
<newline />
<button name="open_partner" icon="gtk-go-forward" string="Partner form" type="object" />
<button name="open_sale_orders" icon="gtk-go-forward" string="Related sale orders" type="object" />
<button name="open_invoices" icon="gtk-go-forward" string="Related invoices" type="object" />
<button special="cancel" icon="gtk-cancel" string="Cancel" />
<button name="open_partner" icon="gtk-go-forward" string="Partner form" type="object" attrs="{'invisible':[('partner_id','=',False)]}"/>
<button name="open_sale_orders" icon="gtk-go-forward" string="Related sale orders" type="object" attrs="{'invisible':[('partner_id','=',False)]}" />
<button name="open_invoices" icon="gtk-go-forward" string="Related invoices" type="object" attrs="{'invisible':[('partner_id','=',False)]}" />
<button special="cancel" icon="gtk-cancel" string="Cancel" attrs="{'invisible':[('partner_id','=',False)]}" />
<newline />
<button name="create_new_partner_phone" icon="gtk-new" string="Create new partner with this phone number" type="object" attrs="{'invisible':[('partner_id','!=',False)]}" colspan="2"/>
<button name="create_new_partner_mobile" icon="gtk-new" string="Create new partner with this mobile number" type="object" attrs="{'invisible':[('partner_id','!=',False)]}" colspan="2"/>
<newline />
<button special="cancel" icon="gtk-cancel" string="Cancel" attrs="{'invisible':[('partner_id','!=',False)]}" colspan="4" />
<!-- I repeat the cancel button for layout reasons -->
</form>
</field>
</record>

Loading…
Cancel
Save