[IMP/FIX] res_partner_addres model clean up for crm, lead, phonecall, meeting
authorJigar Amin - OpenERP <jam@tinyerp.com>
Mon, 5 Mar 2012 11:03:46 +0000 (16:33 +0530)
committerJigar Amin - OpenERP <jam@tinyerp.com>
Mon, 5 Mar 2012 11:03:46 +0000 (16:33 +0530)
bzr revid: jam@tinyerp.com-20120305110346-6vn4he5imzlu53iv

1  2 
addons/crm/crm_lead.py
addons/crm/crm_lead_view.xml
addons/crm/crm_phonecall.py
addons/crm/crm_phonecall_view.xml
addons/crm/wizard/crm_lead_to_opportunity.py
addons/crm/wizard/crm_phonecall_to_partner.py

@@@ -170,7 -170,7 +170,7 @@@ class crm_lead(crm_case, osv.osv)
              domain="['|',('section_id','=',section_id),('section_id','=',False)]", help="From which campaign (seminar, marketing campaign, mass mailing, ...) did this contact come from?"),
          'channel_id': fields.many2one('crm.case.channel', 'Channel', help="Communication channel (mail, direct, phone, ...)"),
          'contact_name': fields.char('Contact Name', size=64),
--        'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner that will be created while converting the lead into opportunity', select=1),
++        'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner company that will be created while converting the lead into opportunity', select=1),
          'optin': fields.boolean('Opt-In', help="If opt-in is checked, this contact has accepted to receive emails."),
          'optout': fields.boolean('Opt-Out', help="If opt-out is checked, this contact has refused to receive emails or unsubscribed to a campaign."),
          'type':fields.selection([ ('lead','Lead'), ('opportunity','Opportunity'), ],'Type', help="Type is used to separate Leads and Opportunities"),
                      }, context=context)
          return True
  
--    def _lead_create_partner(self, cr, uid, lead, context=None):
++    def _lead_create_contact(self, cr, uid, lead, name, is_company, parent_id=False, context=None):
          partner = self.pool.get('res.partner')
--        partner_id = partner.create(cr, uid, {
--                    'name': lead.partner_name or lead.contact_name or lead.name,
--                    'user_id': lead.user_id.id,
--                    'comment': lead.description,
--                    'section_id': lead.section_id.id or False,
--                    'address': []
--        })
++        vals = { 'name': name,
++            'user_id': lead.user_id.id,
++            'comment': lead.description,
++            'section_id': lead.section_id.id or False,
++            'parent_id': parent_id,
++            'phone': lead.phone,
++            'mobile': lead.mobile,
++            'email': lead.email_from and to_email(lead.email_from)[0],
++            'fax': lead.fax,
++            'title': lead.title and lead.title.id or False,
++            'function': lead.function,
++            'street': lead.street,
++            'street2': lead.street2,
++            'zip': lead.zip,
++            'city': lead.city,
++            'country_id': lead.country_id and lead.country_id.id or False,
++            'state_id': lead.state_id and lead.state_id.id or False,
++            'is_company': is_company,
++        }
++
++        partner = partner.create(cr, uid,vals, context)
++        return partner
++
++    def _create_lead_partner(self, cr, uid, lead, context=None):
++        partner_id =  False
++        if lead.partner_name and lead.contact_name:
++            partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, 'partner', context=context)
++            self._lead_create_contact(cr, uid, lead, lead.contact_name, 'contact', partner_id, context=context)
++        elif lead.partner_name and not lead.contact_name:
++            partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, 'partner', context=context)
++        elif not lead.partner_name and lead.contact_name:
++            partner_id = self._lead_create_contact(cr, uid, lead, lead.contact_name, 'contact', context=context)
++        else:
++            partner_id = self._lead_create_contact(cr, uid, lead, lead.name, 'contact', context=context)
          return partner_id
  
      def _lead_set_partner(self, cr, uid, lead, partner_id, context=None):
          if partner_id:
              res_partner.write(cr, uid, partner_id, {'section_id': lead.section_id.id or False})
              contact_id = res_partner.address_get(cr, uid, [partner_id])['default']
-             res = lead.write({'partner_id' : partner_id, 'partner_address_id': contact_id}, context=context)
+             res = lead.write({'partner_id' : partner_id, }, context=context)
 -
          return res
  
--    def _lead_create_partner_address(self, cr, uid, lead, partner_id, context=None):
-         address = self.pool.get('res.partner.address')
-         return address.create(cr, uid, {
-                     'partner_id': partner_id,
-                     'name': lead.contact_name,
-                     'phone': lead.phone,
-                     'mobile': lead.mobile,
-                     'email': lead.email_from and to_email(lead.email_from)[0],
-                     'fax': lead.fax,
-                     'title': lead.title and lead.title.id or False,
-                     'function': lead.function,
-                     'street': lead.street,
-                     'street2': lead.street2,
-                     'zip': lead.zip,
-                     'city': lead.city,
-                     'country_id': lead.country_id and lead.country_id.id or False,
-                     'state_id': lead.state_id and lead.state_id.id or False,
-                 })
 -        address = self.pool.get('res.partner')
 -        return address.create(cr, uid, {
 -                    'parent_id': partner_id,
 -                    'name': lead.contact_name,
 -                    'phone': lead.phone,
 -                    'mobile': lead.mobile,
 -                    'email': lead.email_from and to_email(lead.email_from)[0],
 -                    'fax': lead.fax,
 -                    'title': lead.title and lead.title.id or False,
 -                    'function': lead.function,
 -                    'street': lead.street,
 -                    'street2': lead.street2,
 -                    'zip': lead.zip,
 -                    'city': lead.city,
 -                    'country_id': lead.country_id and lead.country_id.id or False,
 -                    'state_id': lead.state_id and lead.state_id.id or False,
 -                })
 -
      def convert_partner(self, cr, uid, ids, action='create', partner_id=False, context=None):
          """
          This function convert partner based on action.
          for lead in self.browse(cr, uid, ids, context=context):
              if action == 'create':
                  if not partner_id:
--                    partner_id = self._lead_create_partner(cr, uid, lead, context=context)
--                self._lead_create_partner_address(cr, uid, lead, partner_id, context=context)
++                    partner_id = self._create_lead_partner(cr, uid, lead, context)
              self._lead_set_partner(cr, uid, lead, partner_id, context=context)
              partner_ids[lead.id] = partner_id
          return partner_ids
@@@ -81,7 -81,7 +81,7 @@@
                  <notebook colspan="4">
                  <page string="Lead">
                      <group colspan="4" col="2">
--                        <field name="partner_name" string="Partner Name" />
++                        <field name="partner_name" string="Company Name" />
                      </group>
                      <group colspan="2" col="4">
                          <separator string="Contact" colspan="4" col="4"/>
@@@ -180,9 -175,9 +175,9 @@@ class crm_phonecall(crm_base, osv.osv)
          return self.write(cr, uid, ids, {'partner_id' : partner_id}, context=context)
  
      def _call_create_partner_address(self, cr, uid, phonecall, partner_id, context=None):
-         address = self.pool.get('res.partner.address')
+         address = self.pool.get('res.partner')
          return address.create(cr, uid, {
-                     'partner_id': partner_id,
 -                    'parent_id': parent_id,
++                    'parent_id': partner_id,
                      'name': phonecall.name,
                      'phone': phonecall.partner_phone,
          })
@@@ -28,7 -28,7 +28,6 @@@
                  <field name="date"/>
                  <field name="name"/>
                  <field name="partner_id"/>
--                <field name="partner_contact"/>
                  <field name="partner_phone"/>
                  <field name="user_id"/>
                  <field name="categ_id" invisible="1"/>
@@@ -67,8 -67,8 +67,6 @@@ class crm_lead2opportunity_partner(osv.
              ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity'), '!', ('state', 'in', ['done', 'cancel'])])
              if ids:
                  opportunities.append(ids[0])
--                
--                
          if not partner_id:
              label = False
              opp_ids = []
@@@ -38,10 -38,9 +38,9 @@@ class crm_phonecall2partner(osv.osv_mem
  
          phonecall_obj = self.pool.get('crm.phonecall')
          partner_obj = self.pool.get('res.partner')
-         contact_obj = self.pool.get('res.partner.address')
          rec_ids = context and context.get('active_ids', [])
          value = {}
--
++        partner_id = False
          for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
              partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
              if not partner_ids and phonecall.email_from: