diff --git a/addons/crm/crm.py b/addons/crm/crm.py
index edfee9e7614..0b6275598d2 100644
--- a/addons/crm/crm.py
+++ b/addons/crm/crm.py
@@ -281,14 +281,11 @@ class crm_case(object):
@param part: Partner's id
@email: Partner's email ID
"""
- if not part:
- return {'value': {'partner_address_id': False,
- 'email_from': False,
- 'phone': False
- }}
- addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
- data = {'partner_address_id': addr['contact']}
- data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
+ data={}
+ if part:
+ addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
+ data = {'partner_address_id': addr['contact']}
+ data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
return {'value': data}
def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py
index 661180c0874..ec32d359d68 100644
--- a/addons/crm/wizard/crm_merge_opportunities.py
+++ b/addons/crm/wizard/crm_merge_opportunities.py
@@ -18,7 +18,6 @@
# along with this program. If not, see .
#
##############################################################################
-from crm import crm
from osv import osv, fields
from tools.translate import _
@@ -28,35 +27,9 @@ class crm_merge_opportunity(osv.osv_memory):
_name = 'crm.merge.opportunity'
_description = 'Merge two Opportunities'
- def view_init(self, cr, uid, fields, context=None):
- """
- This function checks for precondition before wizard executes
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param fields: List of fields for default value
- @param context: A standard dictionary for contextual values
-
- """
- record_id = context and context.get('active_id', False) or False
- if record_id:
- opp_obj = self.pool.get('crm.lead')
- opp = opp_obj.browse(cr, uid, record_id, context=context)
- if not opp.partner_id:
- raise osv.except_osv(_('Warning!'), _('Opportunity must have Partner assigned before merging with other Opportunity.'))
- #Search for Opportunity for the same partner
- opp_ids = opp_obj.search(cr, uid, [('partner_id', '=', opp.partner_id.id), ('type', '=', 'opportunity'), ('state', 'in', ('open', 'pending'))])
- # Removing current opportunity
- if record_id in opp_ids:
- opp_ids.remove(record_id)
- if not opp_ids:
- raise osv.except_osv(_('Warning!'), _("There are no other 'Open' or 'Pending' Opportunities for the partner '%s'.") % (opp.partner_id.name))
- pass
-
-
def action_merge(self, cr, uid, ids, context=None):
"""
- This function merges two opportunities
+ This function merges opportunities
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@@ -65,54 +38,94 @@ class crm_merge_opportunity(osv.osv_memory):
@return : Dictionary value for created Opportunity form
"""
- record_id = context and context.get('active_id', False) or False
- if record_id:
- opp_obj = self.pool.get('crm.lead')
- message_obj = self.pool.get('mailgate.message')
- current_opp = opp_obj.browse(cr, uid, record_id, context=context)
+ record_id = context and context.get('active_id') or False
+ opp_obj = self.pool.get('crm.lead')
+ if self.datas:
+ obj_opportunity = self.browse(cr, uid, ids[0], context=context)
+ if hasattr(obj_opportunity, 'opportunity_ids'):
+ op_ids = obj_opportunity.opportunity_ids
+ else:
+ op_ids = context.get('opportunity_ids')
+
+ if len(op_ids) <= 1:
+ raise osv.except_osv(_('Warning !'),_('Please select more than one opportunities.'))
+ elif op_ids[0].id == record_id:
+ op_ids = op_ids[1:]
+
+ first_opp = opp_obj.browse(cr, uid, record_id, context=context)
+ first_opp_data = {}
- for this in self.browse(cr, uid, ids, context=context):
- for opp in this.opportunity_ids:
- opp_obj.write(cr, uid, [opp.id], {
- 'stage_id': opp.stage_id.id or current_opp.stage_id.id or False,
- 'priority': opp.priority or current_opp.priority,
- 'email_from': opp.email_from or current_opp.email_from,
- 'phone': opp.phone or current_opp.phone,
- 'section_id': opp.section_id.id or current_opp.section_id.id or False,
- 'categ_id': opp.categ_id.id or current_opp.categ_id.id or False,
- 'description': (opp.description or '') + '\n' + (current_opp.description or ''),
- 'partner_name': opp.partner_name or current_opp.partner_name,
- 'title': opp.title.id or current_opp.title.id or False,
- 'function': opp.function or current_opp.function,
- 'street': opp.street or current_opp.street,
- 'street2': opp.street2 or current_opp.street2,
- 'zip': opp.zip or current_opp.zip,
- 'city': opp.city or current_opp.city,
- 'country_id': opp.country_id.id or current_opp.country_id.id or False,
- 'state_id': opp.state_id.id or current_opp.state_id.id or False,
- 'fax': opp.fax or current_opp.fax,
- 'mobile': opp.mobile or current_opp.mobile,
- 'email_cc': ','.join(filter(lambda x: x, [opp.email_cc, current_opp.email_cc]))
- })
- for history in current_opp.message_ids:
- if history.history:
- new_history = message_obj.copy(cr, uid, history.id, default={'res_id': opp.id})
- opp_obj._history(cr, uid, [current_opp], _('Merged into Opportunity: %s') % (opp.id))
+ for opp in op_ids:
+ first_opp_data = {
+ 'partner_id': first_opp.partner_id.id or opp.partner_id.id,
+ 'stage_id': first_opp.stage_id.id or opp.stage_id.id,
+ 'section_id': first_opp.section_id.id or opp.section_id.id,
+ 'categ_id': first_opp.categ_id.id or opp.categ_id.id,
+ 'type_id': first_opp.type_id.id or opp.type_id.id,
+ 'channel_id': first_opp.channel_id.id or opp.channel_id.id,
+ 'user_id': first_opp.user_id.id or opp.user_id.id,
+ 'country_id': first_opp.country_id.id or opp.country_id.id,
+ 'state_id': first_opp.state_id.id or opp.state_id.id,
+ 'partner_address_id': first_opp.partner_address_id.id or opp.partner_address_id.id,
+ 'priority': first_opp.priority or opp.priority,
+ 'title': first_opp.title.id or opp.title.id,
+ 'function': first_opp.function or opp.function,
+ 'email_from': first_opp.email_from or opp.email_from,
+ 'phone': first_opp.phone or opp.phone,
+ 'description': first_opp.description or opp.description,
+ 'partner_name': first_opp.partner_name or opp.partner_name,
+ 'street': first_opp.street or opp.street,
+ 'street2': first_opp.street2 or opp.street2,
+ 'zip': first_opp.zip or opp.zip,
+ 'city': first_opp.city or opp.city,
+ 'fax': first_opp.fax or opp.fax,
+ 'mobile': first_opp.mobile or opp.mobile,
+ 'email_cc': ','.join(filter(lambda x: x, [opp.email_cc, first_opp.email_cc])),
+ 'type': 'opportunity',
+ 'state': 'open'
+ }
+ for history in opp.message_ids:
+ if history.history:
+ new_history = message_obj.copy(cr, uid, history.id, default={'res_id': opp.id})
+ opp_obj._history(cr, uid, [first_opp], _('Merged from Opportunity: %s : Information lost : [Partner: %s, Stage: %s, Section: %s, Salesman: %s]') % (opp.name, opp.partner_id.name or '', opp.stage_id.name or '', opp.section_id.name or '', opp.user_id.name or ''))
+
+ opp_obj.write(cr, uid, [first_opp.id], first_opp_data)
+
+ unlink_ids = map(lambda x: x.id, op_ids)
+ opp_obj.unlink(cr, uid, unlink_ids)
+
+ models_data = self.pool.get('ir.model.data')
- if this.state == 'unchanged':
- pass
- elif this.state == 'done':
- opp_obj.case_close(cr, uid, [record_id])
- elif this.state == 'draft':
- opp_obj.case_reset(cr, uid, [record_id])
- elif this.state in ['cancel', 'open', 'pending']:
- act = 'case_' + this.state
- getattr(opp_obj, act)(cr, uid, [record_id])
- return {'type': 'ir.actions.act_window_close'}
+ # Get Opportunity views
+ result = models_data._get_id(
+ cr, uid, 'crm', 'view_crm_case_opportunities_filter')
+ opportunity_view_form = models_data._get_id(
+ cr, uid, 'crm', 'crm_case_form_view_oppor')
+ opportunity_view_tree = models_data._get_id(
+ cr, uid, 'crm', 'crm_case_tree_view_oppor')
+ if opportunity_view_form:
+ opportunity_view_form = models_data.browse(
+ cr, uid, opportunity_view_form, context=context).res_id
+ if opportunity_view_tree:
+ opportunity_view_tree = models_data.browse(
+ cr, uid, opportunity_view_tree, context=context).res_id
+
+ return {
+ 'name': _('Opportunity'),
+ 'view_type': 'form',
+ 'view_mode': 'tree, form',
+ 'res_model': 'crm.lead',
+ 'domain': [('type', '=', 'opportunity')],
+ 'res_id': int(first_opp.id),
+ 'view_id': False,
+ 'views': [(opportunity_view_form, 'form'),
+ (opportunity_view_tree, 'tree'),
+ (False, 'calendar'), (False, 'graph')],
+ 'type': 'ir.actions.act_window',
+ }
_columns = {
'opportunity_ids' : fields.many2many('crm.lead', 'merge_opportunity_rel', 'merge_id', 'opportunity_id', 'Opportunities', domain=[('type', '=', 'opportunity')]),
- 'state': fields.selection(crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')], string='Set State To', required=True),
}
def default_get(self, cr, uid, fields, context=None):
@@ -126,21 +139,12 @@ class crm_merge_opportunity(osv.osv_memory):
@return : default values of fields.
"""
- record_id = context and context.get('active_id', False) or False
+ record_ids = context and context.get('active_ids', False) or False
res = super(crm_merge_opportunity, self).default_get(cr, uid, fields, context=context)
- if record_id:
- opp_obj = self.pool.get('crm.lead')
- opp = opp_obj.browse(cr, uid, record_id, context=context)
- opp_ids = opp_obj.search(cr, uid, [('partner_id', '=', opp.partner_id.id), ('type', '=', 'opportunity'), ('state', 'in', ('open', 'pending'))])
- # Removing current opportunity
- if record_id in opp_ids:
- opp_ids.remove(record_id)
-
+ if record_ids:
if 'opportunity_ids' in fields:
- res.update({'opportunity_ids': opp_ids})
- if 'state' in fields:
- res.update({'state': u'cancel'})
+ res.update({'opportunity_ids': record_ids})
return res
diff --git a/addons/crm/wizard/crm_merge_opportunities_view.xml b/addons/crm/wizard/crm_merge_opportunities_view.xml
index 153267f0ad1..046cc37cd8f 100644
--- a/addons/crm/wizard/crm_merge_opportunities_view.xml
+++ b/addons/crm/wizard/crm_merge_opportunities_view.xml
@@ -14,7 +14,6 @@
-
diff --git a/addons/crm_partner_assign/crm_lead_view.xml b/addons/crm_partner_assign/crm_lead_view.xml
index d77eb155d01..0113e3dba6f 100644
--- a/addons/crm_partner_assign/crm_lead_view.xml
+++ b/addons/crm_partner_assign/crm_lead_view.xml
@@ -48,5 +48,16 @@
+
+ crm.opportunity.partner.filter
+ crm.lead
+ search
+
+
+
+
+
+
+