partner_social_fields.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import osv, fields
  22. class res_partner(osv.osv):
  23. '''
  24. Add social media to res.partner
  25. '''
  26. _name = 'res.partner'
  27. _inherit = 'res.partner'
  28. _description = 'Add social media to Partner'
  29. _columns = {
  30. 'facebook':fields.char('Facebook', size=64, required=False, readonly=False),
  31. 'twitter':fields.char('Twitter', size=64, required=False, readonly=False),
  32. 'skype':fields.char('Skype', size=64, required=False, readonly=False),
  33. 'msn':fields.char('MSN', size=64, required=False, readonly=False),
  34. 'whatsapp':fields.boolean('Whatsapp',help='Marque está opción si el cliente tiene Whatsapp'),
  35. 'primer_contacto':fields.many2one('res.partner.primer.contacto','Por cual medio se enteró de la empresa?',help='Medio por cual supo acerca de la empresa'),
  36. }
  37. def goto_facebook(self, cr, uid, ids, context=None):
  38. partner_obj = self.pool.get('res.partner')
  39. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  40. if partner.facebook:
  41. good_starting_urls = ['https://facebook.com/', 'https://www.facebook.com/', \
  42. 'http://facebook.com/', 'http://www.facebook.com/']
  43. non_protocol_starting_urls = ['facebook.com/', 'www.facebook.com/']
  44. if any(map(lambda x: partner.facebook.startswith(x), good_starting_urls)):
  45. url = partner.facebook
  46. elif any(map(lambda x: partner.facebook.startswith(x), non_protocol_starting_urls)):
  47. url = 'https://' + partner.facebook
  48. else:
  49. url = 'https://www.facebook.com/' + partner.facebook
  50. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  51. def goto_twitter(self, cr, uid, ids, context=None):
  52. partner_obj = self.pool.get('res.partner')
  53. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  54. if partner.twitter:
  55. good_starting_urls = ['https://twitter.com/', 'https://www.twitter.com/', \
  56. 'http://twitter.com/', 'http://www.twitter.com/']
  57. non_protocol_starting_urls = ['twitter.com/', 'www.twitter.com/']
  58. if any(map(lambda x: partner.twitter.startswith(x), good_starting_urls)):
  59. url = partner.twitter
  60. elif any(map(lambda x: partner.twitter.startswith(x), non_protocol_starting_urls)):
  61. url = 'https://' + partner.twitter
  62. else:
  63. url = 'https://www.twitter.com/' + partner.twitter
  64. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  65. class res_partner_primer_contacto(osv.osv):
  66. _name = 'res.partner.primer.contacto'
  67. _columns = {
  68. 'name':fields.char('Forma de Contacto', size=64, required=False),
  69. }