crm_lead_social_fields.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # -*- encoding: utf-8 -*-
  2. #################################################################################
  3. # #
  4. # product_features for OpenERP #
  5. # Copyright (C) 2009 NetAndCo (<http://www.netandco.net>). #
  6. # Authors, Mathieu Lemercier, mathieu@netandco.net, #
  7. # Franck Bret, franck@netandco.net #
  8. # Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com> #
  9. # #
  10. # This program is free software: you can redistribute it and/or modify #
  11. # it under the terms of the GNU Affero General Public License as #
  12. # published by the Free Software Foundation, either version 3 of the #
  13. # License, or (at your option) any later version. #
  14. # #
  15. # This program is distributed in the hope that it will be useful, #
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  18. # GNU Affero General Public License for more details. #
  19. # #
  20. # You should have received a copy of the GNU Affero General Public License #
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  22. # #
  23. #################################################################################
  24. from openerp import models, fields, tools
  25. class crm_lead(models.Model):
  26. _name = 'crm.lead'
  27. _inherit = 'crm.lead'
  28. #Campos
  29. facebook = fields.Char('Facebook', size=64, required=False, readonly=False)
  30. twitter = fields.Char('Twitter', size=64, required=False, readonly=False)
  31. skype = fields.Char('Skype', size=64, required=False, readonly=False)
  32. msn = fields.Char('MSN', size=64, required=False, readonly=False)
  33. instagram = fields.Char('Instagram', 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. def goto_facebook(self, cr, uid, ids, context=None):
  37. partner_obj = self.pool.get('res.partner')
  38. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  39. if partner.facebook:
  40. good_starting_urls = ['https://facebook.com/', 'https://www.facebook.com/', \
  41. 'http://facebook.com/', 'http://www.facebook.com/']
  42. non_protocol_starting_urls = ['facebook.com/', 'www.facebook.com/']
  43. if any(map(lambda x: partner.facebook.startswith(x), good_starting_urls)):
  44. url = partner.facebook
  45. elif any(map(lambda x: partner.facebook.startswith(x), non_protocol_starting_urls)):
  46. url = 'https://' + partner.facebook
  47. else:
  48. url = 'https://www.facebook.com/' + partner.facebook
  49. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  50. def goto_twitter(self, cr, uid, ids, context=None):
  51. partner_obj = self.pool.get('res.partner')
  52. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  53. if partner.twitter:
  54. good_starting_urls = ['https://twitter.com/', 'https://www.twitter.com/', \
  55. 'http://twitter.com/', 'http://www.twitter.com/']
  56. non_protocol_starting_urls = ['twitter.com/', 'www.twitter.com/']
  57. if any(map(lambda x: partner.twitter.startswith(x), good_starting_urls)):
  58. url = partner.twitter
  59. elif any(map(lambda x: partner.twitter.startswith(x), non_protocol_starting_urls)):
  60. url = 'https://' + partner.twitter
  61. else:
  62. url = 'https://www.twitter.com/' + partner.twitter
  63. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  64. def goto_instagram(self, cr, uid, ids, context=None):
  65. partner_obj = self.pool.get('res.partner')
  66. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  67. if partner.instagram:
  68. good_starting_urls = ['https://instagram.com/', 'https://www.instagram.com/', \
  69. 'http://instagram.com/', 'http://www.instagram.com/']
  70. non_protocol_starting_urls = ['instagram.com/', 'www.instagram.com/']
  71. if any(map(lambda x: partner.instagram.startswith(x), good_starting_urls)):
  72. url = partner.instagram
  73. elif any(map(lambda x: partner.instagram.startswith(x), non_protocol_starting_urls)):
  74. url = 'https://' + partner.instagram
  75. else:
  76. url = 'https://www.instagram.com/' + partner.instagram
  77. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}
  78. def _lead_create_contact(self, cr, uid, lead, name, is_company, parent_id=False, context=None):
  79. partner = self.pool.get('res.partner')
  80. vals = {'name': name,
  81. 'user_id': lead.user_id.id,
  82. 'comment': lead.description,
  83. 'section_id': lead.section_id.id or False,
  84. 'parent_id': parent_id,
  85. 'phone': lead.phone,
  86. 'mobile': lead.mobile,
  87. 'email': tools.email_split(lead.email_from) and tools.email_split(lead.email_from)[0] or False,
  88. 'fax': lead.fax,
  89. 'title': lead.title and lead.title.id or False,
  90. 'function': lead.function,
  91. 'street': lead.street,
  92. 'street2': lead.street2,
  93. 'zip': lead.zip,
  94. 'city': lead.city,
  95. 'country_id': lead.country_id and lead.country_id.id or False,
  96. 'state_id': lead.state_id and lead.state_id.id or False,
  97. 'is_company': is_company,
  98. 'type': 'contact',
  99. 'facebook':lead.facebook,
  100. 'twitter':lead.twitter,
  101. 'instagram':lead.instagram,
  102. 'skype':lead.skype,
  103. 'msn':lead.msn,
  104. 'whatsapp':lead.whatsapp,
  105. 'primer_contacto': lead.primer_contacto and lead.primer_contacto.id or False
  106. }
  107. partner = partner.create(cr, uid, vals, context=context)
  108. return partner
  109. crm_lead()