[IMP] merge opp, merging data in the module responsible of those data
authortfr@openerp.com <>
Fri, 6 May 2011 08:14:47 +0000 (10:14 +0200)
committertfr@openerp.com <>
Fri, 6 May 2011 08:14:47 +0000 (10:14 +0200)
bzr revid: tfr@openerp.com-20110506081447-k6mglb3ipzfd1bns

addons/crm/wizard/crm_merge_opportunities.py
addons/crm/wizard/crm_send_email.py
addons/crm_partner_assign/wizard/__init__.py
addons/crm_partner_assign/wizard/crm_merge_opportunity.py [new file with mode: 0644]

index 6330d05..248bff2 100644 (file)
@@ -69,31 +69,9 @@ class crm_merge_opportunity(osv.osv_memory):
         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
@@ -104,7 +82,6 @@ class crm_merge_opportunity(osv.osv_memory):
                 '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), #!!
@@ -113,8 +90,6 @@ class crm_merge_opportunity(osv.osv_memory):
                 '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),
@@ -125,13 +100,39 @@ class crm_merge_opportunity(osv.osv_memory):
                 '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]:
index 21902d9..d4ba8b4 100644 (file)
@@ -67,7 +67,6 @@ class crm_send_new_email(osv.osv_memory):
 
         context.update({'mail' : 'new'})
         actives_ids = context.get('active_ids')
-        print "mass_mail", context.get('mass_mail')
         model = context.get('active_model')
         case_pool = self.pool.get(model)
         for id in actives_ids:
index 9224173..be6c153 100644 (file)
@@ -20,3 +20,4 @@
 ##############################################################################
 
 import crm_forward_to_partner
+import crm_merge_opportunity
diff --git a/addons/crm_partner_assign/wizard/crm_merge_opportunity.py b/addons/crm_partner_assign/wizard/crm_merge_opportunity.py
new file mode 100644 (file)
index 0000000..3993a5d
--- /dev/null
@@ -0,0 +1,42 @@
+# -*- 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()