Jigar Amin (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-import_salesforce-b9_opportunity-jam
into lp:~openerp-dev/openobject-addons/trunk-import_salesforce.
Requested reviews:
Bhumika (OpenERP) (sbh-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_salesforce-b9_opportunity-jam/+merge/67019
Improvements :
1) Campaign in Campaign
2) In description ppconcat (Description , Type, Order Number, Current
generator, Tracking Number, Amount, Annual revenue ,
3) History : Import history like any other object (depend on Opportunity)
with mapping and getData
4) LeadToOpp Val : Less intuitive but import as an opportunity that also
depend on opportunity, import as opportunity, The goal is to avoid query in the
hook
5) Merge with lp:~openerp-dev/openobject-addons/trunk-import_salesforce
kindly review this
thank You
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_salesforce-b9_opportunity-jam/+merge/67019
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-import_salesforce.
=== modified file 'import_salesforce/wizard/import_salesforce.py'
--- import_salesforce/wizard/import_salesforce.py 2011-07-06 09:42:20 +0000
+++ import_salesforce/wizard/import_salesforce.py 2011-07-06 11:35:35 +0000
@@ -44,6 +44,7 @@
TABLE_LEAD = 'Lead'
TABLE_CONTACT = 'Contact'
TABLE_OPPORTUNITY = 'Opportunity'
+ TABLE_CONVERTEDOPPO = 'ConvertedOpportunity'
TABLE_CLAIM = 'Case'
TABLE_MEETING = 'Event'
TABLE_STAGE = 'crm_stage'
@@ -72,8 +73,8 @@
self.TABLE_FOLDER: "SELECT Id, Name FROM %s WHERE Type = 'Document'"%(self.TABLE_FOLDER),
self.TABLE_DOCUMENT: "SELECT Id, Name, Type, AuthorId, FolderId, Description, Url FROM %s"%(self.TABLE_DOCUMENT),
self.TABLE_CONTACT: "SELECT Id, Name, Title, Email, MailingStreet, MailingCity, Phone, MobilePhone, MailingPostalCode, MailingState, MailingCountry, Fax, OtherStreet, OtherCity, OtherCountry, OtherState, OtherPostalCode, OtherPhone FROM %s"%(self.TABLE_CONTACT),
+ self.TABLE_OPPORTUNITY: "SELECT CreatedById, AccountId, Id, Name , Probability, NextStep, Amount, Description, OwnerId, StageName, CloseDate, Account.Name, Campaign.Name, Type, OrderNumber__c, CurrentGenerators__c, TrackingNumber__c, ExpectedRevenue FROM %s"%(self.TABLE_OPPORTUNITY),
self.TABLE_LEAD: "SELECT Id, Name, Title, Phone, Email, MobilePhone, Company, Description, PostalCode, Street, City, Rating, Country, Status, LeadSource, Salutation, State, Fax, CreatedById, Industry, AnnualRevenue, NumberOfEmployees, SICCode__c, NumberofLocations__c, ProductInterest__c, CurrentGenerators__c, Primary__c FROM %s"%(self.TABLE_LEAD),
- self.TABLE_OPPORTUNITY: "SELECT CreatedById, AccountId, Id, Name , Probability, NextStep, Amount, Description, OwnerId, StageName, CloseDate, Account.Name FROM %s"%(self.TABLE_OPPORTUNITY),
self.TABLE_CLAIM: "SELECT Id, CaseNumber, Subject, OwnerId, Description, CreatedById, Priority, ContactId, ClosedDate, Status FROM %s"%(self.TABLE_CLAIM),
self.TABLE_MEETING: "SELECT Id, Subject, OwnerId, WhoId, Location, Description, StartDateTime, EndDateTime, IsRecurrence, IsAllDayEvent, DurationInMinutes, RecurrenceType, RecurrenceInterval, RecurrenceEndDateOnly, RecurrenceDayOfWeekMask, RecurrenceDayOfMonth, RecurrenceInstance FROM %s"%(self.TABLE_MEETING),
self.TABLE_ATTACHMENT: "SELECT Id, Name, Description, ParentId FROM Attachment",
@@ -81,6 +82,8 @@
self.TABLE_PRODUCT: "SELECT Id,CreatedById, Description, Family, IsActive, Name, ProductCode FROM %s"%(self.TABLE_PRODUCT),
self.TABLE_EMPLOYEE: "SELECT Id, Phone, Email, MobilePhone, Name, Department, IsActive, ManagerId FROM %s"%(self.TABLE_USER),
self.TABLE_ACCOUNT: "SELECT Id, Name, AccountNumber, OwnerId, ParentId, Fax, Phone, Website , BillingStreet, BillingCity, BillingState, BillingCountry, BillingPostalCode, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Site, Type, Industry, AnnualRevenue, Description, TickerSymbol, Ownership, NumberOfEmployees, Sic, SLA__c, SLASerialNumber__c, CustomerPriority__c, SLAExpirationDate__c, NumberofLocations__c FROM %s"%(self.TABLE_ACCOUNT),
+ self.TABLE_OPPOHISTORY: "SELECT Id, StageName ,CloseDate, OpportunityId From %s"%(self.TABLE_OPPOHISTORY),
+ self.TABLE_CONVERTEDOPPO: "SELECT Id, Name, Title, Phone, Email, MobilePhone, Company, Description, PostalCode, Street, City, Rating, Country, Status, LeadSource, Salutation, State, Fax, CreatedById, Industry, AnnualRevenue, NumberOfEmployees FROM Lead WHERE ConvertedOpportunityId != Null",
}
def get_data(self, table):
@@ -102,6 +105,8 @@
self.TABLE_PRODUCT: self.get_product_mapping(),
self.TABLE_EMPLOYEE: self.get_employee_mapping(),
self.TABLE_ACCOUNT: self.get_account_mapping(),
+ self.TABLE_OPPOHISTORY: self.get_oppo_history_mapping(),
+ self.TABLE_CONVERTEDOPPO: self.get_convertoppo_mapping(),
}
def get_all_states(self, external_val, country_id):
@@ -356,30 +361,6 @@
}
}
- def get_leadtoppo_vals(self, val):
- lead_data = self._SFCLIENT.query("SELECT Company, Title, Street, City, PostalCode, Country, State, Email, Fax, MobilePhone, Phone FROM Lead WHERE ConvertedOpportunityId = '%s'"%val.get('Id'))
- for data in lead_data:
- val.update({
- 'Company': data.get('Company', ''),
- 'Title': data.get('Title', ''),
- 'Street': data.get('Street', ''),
- 'City': data.get('City', ''),
- 'Email': data.get('Email', ''),
- 'Phone': data.get('Phone', ''),
- 'MobilePhone': data.get('MobilePhone', ''),
- 'PostalCode': data.get('PostalCode', ''),
- 'Fax': data.get('Fax', ''),
- 'Email': data.get('Email', ''),
- })
- country = state = False
- if data.get('Country'):
- country = self.get_all_countries(data.get('Country'))
- if data.get('State'):
- state = self.get_all_states(data.get('State'), country)
- val.update({'Country': country, 'State': state})
- return val
-
-
opportunity_state_map = {
'Prospecting': 'draft',
'Qualification': 'open',
@@ -393,25 +374,9 @@
'Closed Lost': 'cancel',
}
- def get_oppo_history(self, val):
- field_map = {
- 'name': 'StageName',
- 'description': 'StageName',
- 'model': 'Model',
- 'date': 'CloseDate',
- }
-
- histories = self._SFCLIENT.query("SELECT Id, StageName ,CloseDate From %s WHERE OpportunityId = '%s'"%(self.TABLE_OPPOHISTORY, val.get('Id')))
- if histories:
- ids = []
- for history in histories:
- history.update({'Model': 'crm.lead',
- 'StageName': ' Changed Stage to: %s'%(history.get('StageName')),
- 'CloseDate': val.get('CloseDate') and val.get('CloseDate').strftime(self.DATETIME_FORMAT) or False})
- history.update({'id_new': history.get('Id')})
- nid = self.import_object_mapping(field_map, history, 'mailgate.message', self.TABLE_OPPOHISTORY, history.get('id_new'), self.DO_NOT_FIND_DOMAIN)
- ids.append(nid)
- return ",".join(ids)
+ def get_opportunityId(self, vals):
+ if vals.get('OpportunityId'):
+ return self.get_mapped_id(self.TABLE_OPPORTUNITY, vals.get('OpportunityId'))
return False
def get_oppo_date_deadline(self, val):
@@ -419,11 +384,59 @@
return val.get('CloseDate').strftime(self.DATETIME_FORMAT)
return False
+ def get_oppo_history_mapping(self):
+ return {
+ 'model': 'mailgate.message',
+ 'dependencies': [self.TABLE_OPPORTUNITY],
+ 'map': {
+ 'name': 'StageName',
+ 'description': 'StageName',
+ 'model': 'crm.lead',
+ 'date': self.get_oppo_date_deadline,
+ 'res_id': self.get_opportunityId,
+ }
+ }
+
+ def get_convertoppo_mapping(self):
+ return{
+ 'model': 'crm.lead',
+ 'dependencies': [self.TABLE_USER],
+ 'hook' : self.import_lead,
+ 'map': {
+ 'name': 'Company',
+ 'user_id/id': ref(self.TABLE_USER, 'CreatedById'),
+ 'state': const('done'),
+ 'planned_revenue': 'AnnualRevenue',
+ 'partner_name': 'Company',
+ 'contact_name': 'Name',
+ 'function': 'Title',
+ 'street': 'Street',
+ 'city': 'City',
+ 'email_from': 'Email',
+ 'phone': 'Phone',
+ 'mobile': 'MobilePhone',
+ 'fax': 'Fax',
+ 'zip': 'PostalCode',
+ 'description': ppconcat('Description', 'Industry', 'AnnualRevenue', 'NumberOfEmployees'),
+ 'country_id/id': 'country_id/id',
+ 'state_id/id': 'state_id/id',
+ 'channel_id/id': call(self.get_channel, value('LeadSource')),
+ 'type' : const('opportunity'),
+ }
+ }
+
+ def get_type(self, vals, val):
+ if not val:
+ return False
+ fields = ['name']
+ name = 'campaign_' + val.get('Name')
+ data = [val.get('Name')]
+ return self.import_object(fields, data, 'crm.case.resource.type', self.TABLE_OPPORTUNITY, name, [('name', 'ilike', val)])
+
def get_opportunity_mapping(self):
return {
'model': 'crm.lead',
- 'dependencies': [self.TABLE_USER, self.TABLE_CONTACT, self.TABLE_ACCOUNT],
- 'hook': self.get_leadtoppo_vals,
+ 'dependencies': [self.TABLE_USER, self.TABLE_CONTACT, self.TABLE_ACCOUNT, self.TABLE_CONVERTEDOPPO],
'map': {
'name': 'Name',
'probability': 'Probability',
@@ -435,21 +448,9 @@
'type': const('opportunity'),
'partner_id/id': ref(self.TABLE_ACCOUNT, 'AccountId'),
'channel_id/id': call(self.get_channel, value('LeadSource')),
- 'description': 'Description',
+ 'description': ppconcat('Description', 'Type', 'OrderNumber__c', 'CurrentGenerators__c', 'TrackingNumber__c', 'ExpectedRevenue'),
'state': map_val('StageName', self.opportunity_state_map, 'open'),
- 'partner_name': 'Company',
- 'function': 'Title',
- 'street': 'Street',
- 'city': 'City',
- 'email_from': 'Email',
- 'phone': 'Phone',
- 'fax': 'Fax',
- 'email_from': 'Email',
- 'mobile': 'MobilePhone',
- 'zip': 'PostalCode',
- 'country_id/id': 'Country',
- 'state_id/id': 'State',
- 'message_ids/id': self.get_oppo_history,
+ 'type_id/id': call(self.get_type, value('Campaign')),
}
}
@@ -883,7 +884,7 @@
if current.contact:
nodes.append('Contact')
if current.lead:
- nodes.extend(['Lead', 'Opportunity'])
+ nodes.extend(['Lead', 'Opportunity', 'OpportunityHistory', 'ConvertedOpportunity'])
if current.employee:
nodes.append('Employee')
if current.account:
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp