op_id = lead_obj.search(cr, uid, [('id', 'in', ids)], order='create_date' , context=context)
opps = lead_obj.browse(cr, uid, [op_id[0]], context=context)
return opps[0]
-
- def merge(self, cr, uid, op_ids, context=None):
- """
- @param opp_ids : list of opportunities ids to merge
- """
- opp_obj = self.pool.get('crm.lead')
- message_obj = self.pool.get('mailgate.message')
-
- lead_ids = context and context.get('lead_ids', []) or []
-
- if len(op_ids) <= 1:
- raise osv.except_osv(_('Warning !'),_('Please select more than one opportunities.'))
-
- opportunities = opp_obj.browse(cr, uid, lead_ids, context=context)
- opportunities_list = list(set(op_ids) - set(opportunities))
- oldest_opp = self.find_oldest(cr, uid, op_ids, context=context)
- if opportunities :
- first_opportunity = opportunities[0]
- tail_opportunities = opportunities_list
- else:
- first_opportunity = opportunities_list[0]
- tail_opportunities = opportunities_list[1:]
-
-
- data = {
+
+ def _update_data(self, op_ids, oldest_opp):
+ data = {
'partner_id': self._get_first_not_null_id('partner_id', op_ids, oldest_opp), # !!
'title': self._get_first_not_null_id('title', op_ids, oldest_opp),
'name' : self._get_first_not_null('name', op_ids, oldest_opp), #not lost
'contact_name' : self._get_first_not_null('contact_name', op_ids, oldest_opp), #not lost
'country_id' : self._get_first_not_null_id('country_id', op_ids, oldest_opp), #!!
'partner_address_id' : self._get_first_not_null_id('partner_address_id', op_ids, oldest_opp), #!!
- 'partner_assigned_id' : hasattr(opp_obj,'partner_assigned_id') and self._get_first_not_null_id('partner_assigned_id', op_ids, oldest_opp), #!!
'type_id' : self._get_first_not_null_id('type_id', op_ids, oldest_opp), #!!
'user_id' : self._get_first_not_null_id('user_id', op_ids, oldest_opp), #!!
'section_id' : self._get_first_not_null_id('section_id', op_ids, oldest_opp), #!!
'email' : self._get_first_not_null('email', op_ids, oldest_opp), # !!
'fax' : self._get_first_not_null('fax', op_ids, oldest_opp),
'mobile' : self._get_first_not_null('mobile', op_ids, oldest_opp),
- 'partner_latitude' : hasattr(opp_obj,'partner_latitude') and self._get_first_not_null('partner_latitude', op_ids, oldest_opp),
- 'partner_longitude' : hasattr(opp_obj,'partner_longitude') and self._get_first_not_null('partner_longitude', op_ids, oldest_opp),
'partner_name' : self._get_first_not_null('partner_name', op_ids, oldest_opp),
'phone' : self._get_first_not_null('phone', op_ids, oldest_opp),
'probability' : self._get_first_not_null('probability', op_ids, oldest_opp),
'state' : 'open',
'create_date' : self._get_first_not_null('create_date', op_ids, oldest_opp),
'date_action_last': self._get_first_not_null('date_action_last', op_ids, oldest_opp),
- 'date_action_next': self._get_first_not_null('date_action_nexte', op_ids, oldest_opp),
+ 'date_action_next': self._get_first_not_null('date_action_next', op_ids, oldest_opp),
'email_from' : self._get_first_not_null('email_from', op_ids, oldest_opp),
'email_cc' : self._get_first_not_null('email_cc', op_ids, oldest_opp),
'partner_name' : self._get_first_not_null('partner_name', op_ids, oldest_opp),
}
+ return data
+
+ def merge(self, cr, uid, op_ids, context=None):
+ """
+ @param opp_ids : list of opportunities ids to merge
+ """
+ opp_obj = self.pool.get('crm.lead')
+ message_obj = self.pool.get('mailgate.message')
+
+ lead_ids = context and context.get('lead_ids', []) or []
+
+ if len(op_ids) <= 1:
+ raise osv.except_osv(_('Warning !'),_('Please select more than one opportunities.'))
+
+ opportunities = opp_obj.browse(cr, uid, lead_ids, context=context)
+ opportunities_list = list(set(op_ids) - set(opportunities))
+ oldest_opp = self.find_oldest(cr, uid, op_ids, context=context)
+ if opportunities :
+ first_opportunity = opportunities[0]
+ tail_opportunities = opportunities_list
+ else:
+ first_opportunity = opportunities_list[0]
+ tail_opportunities = opportunities_list[1:]
+
+
+ data = self._update_data(op_ids, oldest_opp)
#copy message into the first opportunity + merge attachement
for opp in tail_opportunities + [first_opportunity]:
--- /dev/null
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from osv import osv, fields
+from tools.translate import _
+
+
+class crm_merge_opportunity_assign_partner(osv.osv_memory):
+ """Merge two Opportunities"""
+
+ _inherit = 'crm.merge.opportunity'
+
+ def _update_data(self, op_ids, oldest_opp):
+ data = super(crm_merge_opportunity_assign_partner, self)._update_data(op_ids, oldest_opp)
+
+ new_data = {
+ 'partner_latitude': self._get_first_not_null('partner_latitude', op_ids, oldest_opp),
+ 'partner_longitude': self._get_first_not_null('partner_longitude', op_ids, oldest_opp),
+ 'partner_assigned_id': self._get_first_not_null_id('partner_assigned_id', op_ids, oldest_opp),
+ 'date_assign' : self._get_first_not_null('date_assign', op_ids, oldest_opp),
+ }
+ data.update(new_data)
+ return data
+
+crm_merge_opportunity_assign_partner()