Jigar Amin (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-import_salesforce-b9_contract-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_contract-jam/+merge/67693
Changes - Contract : Import as Analytic Account
- Address if the account have no billing address add this address to the
partner (account)
- Everything else in the description (use ppconcat)
Kindly Review this
Thank You
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_salesforce-b9_contract-jam/+merge/67693
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-import_salesforce.
=== modified file 'import_salesforce/__openerp__.py'
--- import_salesforce/__openerp__.py 2011-06-02 11:36:34 +0000
+++ import_salesforce/__openerp__.py 2011-07-12 13:04:37 +0000
@@ -32,7 +32,7 @@
""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
- 'depends': ['import_base', 'crm_claim', 'document', 'product', 'hr'],
+ 'depends': ['import_base', 'crm_claim', 'document', 'product', 'hr', 'account'],
'init_xml': [],
'update_xml': [
'security/ir.model.access.csv',
=== modified file 'import_salesforce/wizard/import_salesforce.py'
--- import_salesforce/wizard/import_salesforce.py 2011-07-11 11:28:55 +0000
+++ import_salesforce/wizard/import_salesforce.py 2011-07-12 13:04:37 +0000
@@ -57,6 +57,7 @@
TABLE_PRODUCTCAT = "product.category"
TABLE_HRDEPT = 'hr.department'
TABLE_ACCOUNT = "Account"
+ TABLE_CONTRACT = 'Contract'
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
object_description = {}
@@ -98,10 +99,19 @@
}
return mapping.get(table, table)
+ def replace_account(self, table, fields):
+ res = []
+ for field in fields:
+ if field == 'AccountId' and table == self.TABLE_CONTRACT:
+ res.extend(['Account.Name', 'Account.Id'])
+ else:
+ res.append(field)
+ return res
+
def get_data(self, table):
table_origin = table
table = self.get_salesforce_table(table)
- sql = "SELECT " + ', '.join(self.object_description[table].fields) + " FROM " + table + self.get_where_clause(table_origin)
+ sql = "SELECT " + ', '.join(self.replace_account(table, self.object_description[table].fields)) + " FROM " + table + self.get_where_clause(table_origin)
res = self._SFCLIENT.query(sql)
data = res
while res['done'] != 'false' and res['queryLocator']:
@@ -127,6 +137,7 @@
self.TABLE_OPPOHISTORY: self.get_oppo_history_mapping(),
self.TABLE_CONVERTEDOPPO: self.get_convertoppo_mapping(),
self.TABLE_ATTENDEE: self.get_attendee_mapping(),
+ self.TABLE_CONTRACT: self.get_contract_mapping(),
}
def get_all_states(self, external_val, country_id):
@@ -863,6 +874,65 @@
}
}
+ def get_contract(self, vals):
+ partner_pool = self.obj.pool.get("res.partner")
+ account = vals.pop('Account', {})
+ name = vals.get('ContractNumber') + "-" + account.get('Name', "")
+ vals.update({'Name':name,
+ 'AccountId': account.get('Id', False)})
+ if account.get('Id'):
+ contact = self.xml_id_exist(self.TABLE_ACCOUNT, account.get('Id'))
+ if contact:
+ account_id = self.get_mapped_id(self.TABLE_ACCOUNT, account.get('Id'))
+ account_rec = partner_pool.browse(self.cr, self.uid, account_id, context=self.context)
+ if account_rec.address:
+ types =[ address.type for address in account_rec.address]
+ if 'invoice' not in types:
+ address = {
+ 'partner_id/.id': 'PartnerId',
+ 'name': 'contact_name',
+ 'type': 'type',
+ 'street': 'street',
+ 'zip': 'zip',
+ 'city': 'city',
+ 'country_id/id': 'country_id/id',
+ 'state_id/id': 'state_id/id',
+ }
+ values = {
+ 'PartnerId': account_rec.id,
+ 'contact_name': account_rec.name,
+ 'type': 'invoice',
+ 'street': vals.get('BillingStreet', ''),
+ 'zip': vals.get('BillingPostalCode', ''),
+ 'city': vals.get('BillingCity', ''),
+ 'state_id/id': False,
+ 'country_id/id': False,
+ }
+ if vals.get('BillingCountry'):
+ country = self.get_all_countries(vals.get('BillingCountry'))
+ if vals.get('BillingState'):
+ state = self.get_all_states(vals.get('BillingState'), country)
+ values.update({'country_id/id': country,
+ 'state_id/id': state,
+ 'id_new': vals['Id'] + '_address_' + 'invoice'})
+ self.import_object_mapping(address, values, 'res.partner.address', self.TABLE_ACCOUNT, values['id_new'], self.DO_NOT_FIND_DOMAIN)
+ return vals
+
+ def get_contract_mapping(self):
+ return {
+ 'model': 'account.analytic.account',
+ 'dependencies': [self.TABLE_USER, self.TABLE_ACCOUNT],
+ 'hook': self.get_contract,
+ 'map': {
+ 'name': 'Name',
+ 'code': 'ContractNumber',
+ 'partner_id/id': ref(self.TABLE_ACCOUNT, 'AccountId'),
+ 'date': call(self.get_date, value('EndDate')),
+ 'date_start': call(self.get_date, value('StartDate')),
+ 'description': ppconcat('CustomerSignedTitle', 'StatusCode', 'SpecialTerms', 'Status', 'ContractTerm', 'OwnerExpirationNotice', 'SystemModstamp', 'Description')
+ }
+ }
+
def get_email_subject(self, result):
return "Your Salesforce's data were successfully imported at %s" % self.date_ended
@@ -890,6 +960,7 @@
'product': fields.boolean('Products', help="If Products is checked, SalesFroce Products data imported to OpenERP Products"),
'employee': fields.boolean('Employees', help="If Employees is checked, SalesFroce Per Users Employees will be created"),
'account': fields.boolean('Accounts', help="If Accounts is checked, SalesFroce Accounts details will be imported to the OpenERP Contact."),
+ 'contract': fields.boolean('Contarcts/Analytic Account', help="If Contarcts/Analytic Account is checked, SalesFroce Contarcts details will be imported to the OpenERP Analytic Account."),
'email': fields.char('Email address to notify', size=128, help="On Successful import the Email is Send to the mention email address."),
'instance_name': fields.char('Instance Name', required=True, size=128, help="Instance name will be used to separate import from multiple salesforce login instance."),
}
@@ -927,6 +998,8 @@
nodes.append('Document')
if current.product:
nodes.append('Product2')
+ if current.contract:
+ nodes.append('Contract')
return nodes
def import_all(self, cr, uid, ids, context=None):
=== modified file 'import_salesforce/wizard/import_salesforce_view.xml'
--- import_salesforce/wizard/import_salesforce_view.xml 2011-07-11 11:32:11 +0000
+++ import_salesforce/wizard/import_salesforce_view.xml 2011-07-12 13:04:37 +0000
@@ -25,6 +25,7 @@
<separator string="Address Book :" colspan="2"/>
<field name="contact"/>
<field name="account"/>
+ <field name="contract"/>
</group>
<group colspan="2" col="2">
<separator string="CRM :" colspan="2"/>
_______________________________________________
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