1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
21 from osv import fields, osv
23 from tools.translate import _
25 class import_sugarcrm(osv.osv):
26 """Import SugarCRM DATA"""
28 _name = "import.sugarcrm"
29 _description = __doc__
31 'mod_name':fields.selection([
33 ('opportunity','Opportunities'),
34 ('accounts','Accounts'),
35 ('contact','Contacts'),
36 ],'Module Name', help="Module Name is used to specify which Module data want to Import"),
40 def import_data(self, cr, uid, ids,context=None):
43 lead_pool = self.pool.get("crm.lead")
44 for current in self.browse(cr, uid, ids):
45 if current.mod_name == 'lead' or current.mod_name == 'opportunity':
48 elif current.mod_name == "accounts":
49 module_name = 'account'
50 ids = self.pool.get("ir.module.module").search(cr, uid, [("name", '=',
51 module_name), ('state', '=', 'installed')])
53 raise osv.except_osv(_('Error !'), _('Please Install %s Module') % (module_name))
55 if current.mod_name == 'lead':
57 elif current.mod_name == 'opportunity':
58 sugar_name="Opportunities"
59 elif current.mod_name == 'accounts':
61 elif current.mod_name == 'contact':
64 sugar_data = sugar.test(sugar_name)
65 for sugar_val in sugar_data:
66 if sugar_name == "Leads":
67 vals = {'name':sugar_val.get('first_name', ''),
68 'user_id':sugar_val.get('created_by',''),
69 'partner_name': sugar_val.get('first_name','')+''+ sugar_val.get('last_name',''),
70 'email_from': sugar_val.get('email1',''),
71 'phone': sugar_val.get('phone_work',''),
72 'mobile': sugar_val.get('phone_mobile',''),
73 'write_date':sugar_val.get('date_modified',''),
74 'function':sugar_val.get('title',''),
75 'street': sugar_val.get('primary_address_street',''),
76 'zip': sugar_val.get('primary_address_postalcode',''),
77 'city':sugar_val.get('primary_address_city',''),
79 lead_pool.create(cr, uid, vals)