[IMP] [REF] crm: WIP and first attempt to remove state field.
authorThibault Delavallée <tde@openerp.com>
Mon, 10 Jun 2013 14:29:27 +0000 (16:29 +0200)
committerThibault Delavallée <tde@openerp.com>
Mon, 10 Jun 2013 14:29:27 +0000 (16:29 +0200)
crm.case.section: removed state field
crm.lead: code now use probability and on_change to fetch stages related to
Won and Lost. Improved stage management. Improved a bit the demo data.

mail: improved message_track to use browse_record instead of read result. This allows
to avoid having to track fields to be able to use them in the subtype condition.

bzr revid: tde@openerp.com-20130610142927-tyxxklojv2wxw44g

16 files changed:
addons/base_status/base_stage.py
addons/crm/__openerp__.py
addons/crm/crm.py
addons/crm/crm_lead.py
addons/crm/crm_lead_data.xml
addons/crm/crm_lead_demo.xml
addons/crm/crm_lead_view.xml
addons/crm/crm_view.xml
addons/crm/report/crm_lead_report.py
addons/crm/report/crm_lead_report_view.xml
addons/crm/report/crm_phonecall_report.py
addons/crm/report/crm_phonecall_report_view.xml
addons/crm/res_partner.py
addons/crm/wizard/crm_lead_to_opportunity.py
addons/crm/wizard/crm_merge_opportunities.py
addons/mail/mail_thread.py

index edf9db1..6a5386b 100644 (file)
@@ -22,6 +22,7 @@
 from openerp.osv import fields, osv
 from openerp.tools.translate import _
 
+
 class base_stage(object):
     """ Base utility mixin class for objects willing to manage their stages.
         Object that inherit from this class should inherit from mailgate.thread
@@ -55,7 +56,7 @@ class base_stage(object):
         if context.get('portal'):
             user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
             return user.email
-        return False        
+        return False
 
     def _get_default_user(self, cr, uid, context=None):
         """ Gives current user id
@@ -67,17 +68,20 @@ class base_stage(object):
             return False
         return uid
 
-    def onchange_partner_address_id(self, cr, uid, ids, add, email=False, context=None):
+    def onchange_partner_address_id(self, cr, uid, ids, address_id, context=None):
         """ This function returns value of partner email based on Partner Address
-            :param add: Id of Partner's address
-            :param email: Partner's email ID
+            :param address_id: partner_id related to the correct address
         """
-        data = {'value': {'email_from': False, 'phone':False}}
-        if add:
-            address = self.pool.get('res.partner').browse(cr, uid, add)
+        if context is None:
+            context = {}
+        data = {'value': {'email_from': False, 'phone': False}}
+        if address_id:
+            address = self.pool.get('res.partner').browse(cr, uid, address_id, context=context)
             data['value'] = {'partner_name': address and address.name or False,
                              'email_from': address and address.email or False,
                              'phone':  address and address.phone or False,
+                             'mobile': address and address.mobile or False,
+                             'fax': address and address.fax or False,
                              'street': address and address.street or False,
                              'street2': address and address.street2 or False,
                              'city': address and address.city or False,
@@ -85,21 +89,18 @@ class base_stage(object):
                              'zip': address and address.zip or False,
                              'country_id': address.country_id and address.country_id.id or False,
                              }
-        fields = self.fields_get(cr, uid, context=context or {})
+        model_fields = self.fields_get(cr, uid, context=context)
         for key in data['value'].keys():
-            if key not in fields:
+            if key not in model_fields:
                 del data['value'][key]
         return data
 
-    def onchange_partner_id(self, cr, uid, ids, part, email=False):
-        """ This function returns value of partner address based on partner
-            :param part: Partner's id
-            :param email: Partner's email ID
-        """
-        data={}
-        if  part:
-            addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
-            data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
+    def onchange_partner_id(self, cr, uid, ids, partner_id, email=False, context=None):
+        """ This function returns value of partner address based on partner """
+        data = {}
+        if partner_id:
+            address = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['contact'], context=context)
+            data.update(self.onchange_partner_address_id(cr, uid, ids, address['contact'], context=context)['value'])
         return {'value': data}
 
     def _get_default_section_id(self, cr, uid, context=None):
@@ -108,7 +109,8 @@ class base_stage(object):
 
     def _get_default_stage_id(self, cr, uid, context=None):
         """ Gives default stage_id """
-        return self.stage_find(cr, uid, [], None, [('state', '=', 'draft')], context=context)
+        section_id = self._get_default_section_id(cr, uid, context=context)
+        return self.stage_find(cr, uid, [], section_id, [('sequence', '=', '1')], context=context)
 
     def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
         """ Find stage, with a given (optional) domain on the search,
@@ -129,18 +131,6 @@ class base_stage(object):
         """
         return False
 
-    def stage_set_with_state_name(self, cr, uid, cases, state_name, context=None):
-        """ Set a new stage, with a state_name instead of a stage_id
-            :param cases: browse_record of cases
-        """
-        if isinstance(cases, (int, long)):
-            cases = self.browse(cr, uid, cases, context=context)
-        for case in cases:
-            stage_id = self.stage_find(cr, uid, [case], None, [('state', '=', state_name)], context=context)
-            if stage_id:
-                self.stage_set(cr, uid, [case.id], stage_id, context=context)
-        return True
-
     def stage_set(self, cr, uid, ids, stage_id, context=None):
         """ Set the new stage. This methods is the right method to call
             when changing states. It also checks whether an onchange is
@@ -165,8 +155,7 @@ class base_stage(object):
             seq = 0
             if case.stage_id:
                 seq = case.stage_id.sequence or 0
-            section_id = None
-            next_stage_id = self.stage_find(cr, uid, [case], None, [('sequence', op, seq)],order, context=context)
+            next_stage_id = self.stage_find(cr, uid, [case], None, [('sequence', op, seq)], order, context=context)
             if next_stage_id:
                 return self.stage_set(cr, uid, [case.id], next_stage_id, context=context)
         return False
@@ -175,7 +164,7 @@ class base_stage(object):
         """ This function computes next stage for case from its current stage
             using available stage for that case type
         """
-        return self.stage_change(cr, uid, ids, '>','sequence', context)
+        return self.stage_change(cr, uid, ids, '>', 'sequence', context)
 
     def stage_previous(self, cr, uid, ids, context=None):
         """ This function computes previous stage for case from its current
@@ -192,9 +181,9 @@ class base_stage(object):
 
         if hasattr(self, '_columns'):
             if self._columns.get('date_closed'):
-                default.update({ 'date_closed': False, })
+                default.update({'date_closed': False})
             if self._columns.get('date_open'):
-                default.update({ 'date_open': False })
+                default.update({'date_open': False})
         return super(base_stage, self).copy(cr, uid, id, default, context=context)
 
     def case_escalate(self, cr, uid, ids, context=None):
@@ -211,54 +200,42 @@ class base_stage(object):
             self.write(cr, uid, [case.id], data, context=context)
         return True
 
-    def case_open(self, cr, uid, ids, context=None):
-        """ Opens case """
-        cases = self.browse(cr, uid, ids, context=context)
-        for case in cases:
-            data = {'active': True}
-            if not case.user_id:
-                data['user_id'] = uid
-            self.case_set(cr, uid, [case.id], 'open', data, context=context)
-        return True
-
-    def case_close(self, cr, uid, ids, context=None):
-        """ Closes case """
-        return self.case_set(cr, uid, ids, 'done', {'active': True, 'date_closed': fields.datetime.now()}, context=context)
-
-    def case_cancel(self, cr, uid, ids, context=None):
-        """ Cancels case """
-        return self.case_set(cr, uid, ids, 'cancel', {'active': True}, context=context)
-
-    def case_pending(self, cr, uid, ids, context=None):
-        """ Set case as pending """
-        return self.case_set(cr, uid, ids, 'pending', {'active': True}, context=context)
-
-    def case_reset(self, cr, uid, ids, context=None):
-        """ Resets case as draft """
-        return self.case_set(cr, uid, ids, 'draft', {'active': True}, context=context)
-
-    def case_set(self, cr, uid, ids, new_state_name=None, values_to_update=None, new_stage_id=None, context=None):
+    # def case_open(self, cr, uid, ids, context=None):
+    #     """ Opens case """
+    #     cases = self.browse(cr, uid, ids, context=context)
+    #     for case in cases:
+    #         data = {'active': True}
+    #         if not case.user_id:
+    #             data['user_id'] = uid
+    #         self.case_set(cr, uid, [case.id], data, context=context)
+    #     return True
+
+    # def case_close(self, cr, uid, ids, context=None):
+    #     """ Closes case """
+    #     return self.case_set(cr, uid, ids, None, {'active': True, 'date_closed': fields.datetime.now()}, context=context)
+
+    # def case_cancel(self, cr, uid, ids, context=None):
+    #     """ Cancels case """
+    #     return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
+
+    # def case_pending(self, cr, uid, ids, context=None):
+    #     """ Set case as pending """
+    #     return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
+
+    # def case_reset(self, cr, uid, ids, context=None):
+    #     """ Resets case as draft """
+    #     return self.case_set(cr, uid, ids, None, {'active': True}, context=context)
+
+    def case_set(self, cr, uid, ids, new_stage_id, values_to_update=None, context=None):
         """ Generic method for setting case. This methods wraps the update
             of the record.
 
-            :params new_state_name: the new state of the record; this method
-                                    will call ``stage_set_with_state_name``
-                                    that will find the stage matching the
-                                    new state, using the ``stage_find`` method.
             :params new_stage_id: alternatively, you may directly give the
                                   new stage of the record
-            :params state_name: the new value of the state, such as
-                     'draft' or 'close'.
             :params update_values: values that will be added with the state
                      update when writing values to the record.
         """
-        cases = self.browse(cr, uid, ids, context=context)
-        # 1. update the stage
-        if new_state_name:
-            self.stage_set_with_state_name(cr, uid, cases, new_state_name, context=context)
-        elif not (new_stage_id is None):
-            self.stage_set(cr, uid, ids, new_stage_id, context=context)
-        # 2. update values
+        self.stage_set(cr, uid, ids, new_stage_id, context=context)
         if values_to_update:
             self.write(cr, uid, ids, values_to_update, context=context)
         return True
index e7ab7df..578eb4d 100644 (file)
@@ -98,13 +98,15 @@ Dashboard for CRM will include:
         'base_partner_merge_view.xml',
 
         'crm_case_section_view.xml',
-    ],
-    'demo': [
+
         'crm_demo.xml',
         'crm_lead_demo.xml',
         'crm_phonecall_demo.xml',
         'crm_action_rule_demo.xml',
     ],
+    'demo': [
+        
+    ],
     'test': [
         'test/crm_lead_message.yml',
         'test/lead2opportunity2win.yml',
index 4c9a606..e8bb011 100644 (file)
@@ -26,7 +26,6 @@ from openerp import tools
 from openerp.osv import fields
 from openerp.osv import osv
 
-MAX_LEVEL = 15
 AVAILABLE_STATES = [
     ('draft', 'New'),
     ('cancel', 'Cancelled'),
@@ -72,16 +71,13 @@ class crm_case_stage(osv.osv):
         'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"),
         'on_change': fields.boolean('Change Probability Automatically', help="Setting this stage will change the probability automatically on the opportunity."),
         'requirements': fields.text('Requirements'),
-        'section_ids':fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', string='Sections',
+        'section_ids': fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', string='Sections',
                         help="Link between stages and sales teams. When set, this limitate the current stage to the selected sales teams."),
-        'state': fields.selection(AVAILABLE_STATES, 'Related Status', required=True,
-            help="The status of your document will automatically change regarding the selected stage. " \
-                "For example, if a stage is related to the status 'Close', when your document reaches this stage, it is automatically closed."),
         'case_default': fields.boolean('Default to New Sales Team',
                         help="If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams."),
         'fold': fields.boolean('Fold by Default',
                         help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."),
-        'type': fields.selection([  ('lead','Lead'),
+        'type': fields.selection([('lead', 'Lead'),
                                     ('opportunity', 'Opportunity'),
                                     ('both', 'Both')],
                                     string='Type', size=16, required=True,
@@ -91,7 +87,7 @@ class crm_case_stage(osv.osv):
     _defaults = {
         'sequence': lambda *args: 1,
         'probability': lambda *args: 0.0,
-        'state': 'open',
+        'on_change': True,
         'fold': False,
         'type': 'both',
         'case_default': True,
index b8673e7..564b51b 100644 (file)
@@ -62,11 +62,7 @@ CRM_LEAD_FIELDS_TO_MERGE = ['name',
     'email_from',
     'email_cc',
     'partner_name']
-CRM_LEAD_PENDING_STATES = (
-    crm.AVAILABLE_STATES[2][0], # Cancelled
-    crm.AVAILABLE_STATES[3][0], # Done
-    crm.AVAILABLE_STATES[4][0], # Pending
-)
+
 
 class crm_lead(base_stage, format_address, osv.osv):
     """ CRM Lead Case """
@@ -76,14 +72,12 @@ class crm_lead(base_stage, format_address, osv.osv):
     _inherit = ['mail.thread', 'ir.needaction_mixin']
 
     _track = {
-        'state': {
-            'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['new', 'draft'],
-            'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done',
-            'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel',
-        },
         'stage_id': {
-            'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'draft', 'cancel', 'done'],
-        },
+            'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.sequence == 1,
+            'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj.probability > 0 and obj.probability < 100,
+            'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj.probability == 100,
+            'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.sequence != 1,
+        }
     }
 
     def get_empty_list_help(self, cr, uid, help, context=None):
@@ -111,11 +105,6 @@ class crm_lead(base_stage, format_address, osv.osv):
         """ Gives default section by checking if present in the context """
         return self._resolve_section_id_from_context(cr, uid, context=context) or False
 
-    def _get_default_stage_id(self, cr, uid, context=None):
-        """ Gives default stage_id """
-        section_id = self._get_default_section_id(cr, uid, context=context)
-        return self.stage_find(cr, uid, [], section_id, [('state', '=', 'draft')], context=context)
-
     def _resolve_section_id_from_context(self, cr, uid, context=None):
         """ Returns ID of section based on the value of 'section_id'
             context key, or None if it cannot be resolved to a single
@@ -166,7 +155,7 @@ class crm_lead(base_stage, format_address, osv.osv):
         stage_ids = stage_obj._search(cr, uid, search_domain, order=order, access_rights_uid=access_rights_uid, context=context)
         result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
         # restore order of the search
-        result.sort(lambda x,y: cmp(stage_ids.index(x[0]), stage_ids.index(y[0])))
+        result.sort(lambda x, y: cmp(stage_ids.index(x[0]), stage_ids.index(y[0])))
 
         fold = {}
         for stage in stage_obj.browse(cr, access_rights_uid, stage_ids, context=context):
@@ -174,7 +163,7 @@ class crm_lead(base_stage, format_address, osv.osv):
         return result, fold
 
     def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
-        res = super(crm_lead,self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
+        res = super(crm_lead, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
         if view_type == 'form':
             res['arch'] = self.fields_view_get_address(cr, user, res['arch'], context=context)
         return res
@@ -236,17 +225,6 @@ class crm_lead(base_stage, format_address, osv.osv):
                 res[lead.id][field] = abs(int(duration))
         return res
 
-    def _history_search(self, cr, uid, obj, name, args, context=None):
-        res = []
-        msg_obj = self.pool.get('mail.message')
-        message_ids = msg_obj.search(cr, uid, [('email_from','!=',False), ('subject', args[0][1], args[0][2])], context=context)
-        lead_ids = self.search(cr, uid, [('message_ids', 'in', message_ids)], context=context)
-
-        if lead_ids:
-            return [('id', 'in', lead_ids)]
-        else:
-            return [('id', '=', '0')]
-
     _columns = {
         'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', track_visibility='onchange',
             select=True, help="Linked partner (optional). Usually created when converting the lead."),
@@ -259,21 +237,21 @@ class crm_lead(base_stage, format_address, osv.osv):
         'email_from': fields.char('Email', size=128, help="Email address of the contact", select=1),
         'section_id': fields.many2one('crm.case.section', 'Sales Team',
                         select=True, track_visibility='onchange', help='When sending mails, the default email address is taken from the sales team.'),
-        'create_date': fields.datetime('Creation Date' , readonly=True),
-        'email_cc': fields.text('Global CC', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
+        'create_date': fields.datetime('Creation Date', readonly=True),
+        'email_cc': fields.text('Global CC', size=252, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
         'description': fields.text('Notes'),
-        'write_date': fields.datetime('Update Date' , readonly=True),
+        'write_date': fields.datetime('Update Date', readonly=True),
         'categ_ids': fields.many2many('crm.case.categ', 'crm_lead_category_rel', 'lead_id', 'category_id', 'Categories', \
             domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]"),
         'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
             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 company 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),
         'opt_out': fields.boolean('Opt-Out', oldname='optout',
             help="If opt-out is checked, this contact has refused to receive emails for mass mailing and marketing campaign. "
                     "Filter 'Available for Mass Mailing' allows users to filter the leads when performing mass mailing."),
-        'type':fields.selection([ ('lead','Lead'), ('opportunity','Opportunity'), ],'Type', help="Type is used to separate Leads and Opportunities"),
+        'type': fields.selection([('lead', 'Lead'), ('opportunity', 'Opportunity'), ], 'Type', help="Type is used to separate Leads and Opportunities"),
         'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority', select=True),
         'date_closed': fields.datetime('Closed', readonly=True),
         'stage_id': fields.many2one('crm.case.stage', 'Stage', track_visibility='onchange',
@@ -285,12 +263,9 @@ class crm_lead(base_stage, format_address, osv.osv):
                                 multi='day_open', type="float", store=True),
         'day_close': fields.function(_compute_day, string='Days to Close', \
                                 multi='day_close', type="float", store=True),
-        'state': fields.related('stage_id', 'state', type="selection", store=True,
-                selection=crm.AVAILABLE_STATES, string="Status", readonly=True,
-                help='The Status is set to \'Draft\', when a case is created. If the case is in progress the Status is set to \'Open\'. When the case is over, the Status is set to \'Done\'. If the case needs to be reviewed then the Status is  set to \'Pending\'.'),
 
         # Only used for type opportunity
-        'probability': fields.float('Success Rate (%)',group_operator="avg"),
+        'probability': fields.float('Success Rate (%)', group_operator="avg"),
         'planned_revenue': fields.float('Expected Revenue', track_visibility='always'),
         'ref': fields.reference('Reference', selection=crm._links_get, size=128),
         'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
@@ -341,30 +316,11 @@ class crm_lead(base_stage, format_address, osv.osv):
 
     def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
         if not stage_id:
-            return {'value':{}}
-        stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
+            return {'value': {}}
+        stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context=context)
         if not stage.on_change:
-            return {'value':{}}
-        return {'value':{'probability': stage.probability}}
-
-    def on_change_partner(self, cr, uid, ids, partner_id, context=None):
-        result = {}
-        values = {}
-        if partner_id:
-            partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
-            values = {
-                'partner_name' : partner.name,
-                'street' : partner.street,
-                'street2' : partner.street2,
-                'city' : partner.city,
-                'state_id' : partner.state_id and partner.state_id.id or False,
-                'country_id' : partner.country_id and partner.country_id.id or False,
-                'email_from' : partner.email,
-                'phone' : partner.phone,
-                'mobile' : partner.mobile,
-                'fax' : partner.fax,
-            }
-        return {'value' : values}
+            return {'value': {}}
+        return {'value': {'probability': stage.probability}}
 
     def on_change_user(self, cr, uid, ids, user_id, context=None):
         """ When changing the user, also set a section_id or restrict section id
@@ -403,16 +359,16 @@ class crm_lead(base_stage, format_address, osv.osv):
         if isinstance(cases, (int, long)):
             cases = self.browse(cr, uid, cases, context=context)
         # collect all section_ids
-        section_ids = []
+        section_ids = set()
         types = ['both']
-        if not cases :
-            type = context.get('default_type')
-            types += [type]
+        if not cases:
+            ctx_type = context.get('default_type')
+            types += [ctx_type]
         if section_id:
-            section_ids.append(section_id)
+            section_ids.add(section_id)
         for lead in cases:
             if lead.section_id:
-                section_ids.append(lead.section_id.id)
+                section_ids.add(lead.section_id.id)
             if lead.type not in types:
                 types.append(lead.type)
         # OR all section_ids and OR with case_default
@@ -421,8 +377,7 @@ class crm_lead(base_stage, format_address, osv.osv):
             search_domain += [('|')] * len(section_ids)
             for section_id in section_ids:
                 search_domain.append(('section_ids', '=', section_id))
-        else:
-            search_domain.append(('case_default', '=', True))
+        search_domain.append(('case_default', '=', True))
         # AND with cases types
         search_domain.append(('type', 'in', types))
         # AND with the domain in parameter
@@ -433,38 +388,36 @@ class crm_lead(base_stage, format_address, osv.osv):
             return stage_ids[0]
         return False
 
-    def case_cancel(self, cr, uid, ids, context=None):
-        """ Overrides case_cancel from base_stage to set probability """
-        res = super(crm_lead, self).case_cancel(cr, uid, ids, context=context)
-        self.write(cr, uid, ids, {'probability' : 0.0}, context=context)
-        return res
-
-    def case_reset(self, cr, uid, ids, context=None):
-        """ Overrides case_reset from base_stage to set probability """
-        res = super(crm_lead, self).case_reset(cr, uid, ids, context=context)
-        self.write(cr, uid, ids, {'probability': 0.0}, context=context)
-        return res
-
     def case_mark_lost(self, cr, uid, ids, context=None):
-        """ Mark the case as lost: state=cancel and probability=0 """
+        """ Mark the case as lost: stage with probability=0, on_change=True """
         for lead in self.browse(cr, uid, ids):
-            stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0),('on_change','=',True)], context=context)
+            stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0), ('on_change', '=', True), ('sequence', '>', 1)], context=context)
             if stage_id:
-                self.case_set(cr, uid, [lead.id], values_to_update={'probability': 0.0}, new_stage_id=stage_id, context=context)
+                self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context)
+            else:
+                raise self.pool.get('res.config.settings').get_config_warning(cr,
+                    _("To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n"
+                        "probability = 0, sequence != 1 and on_change = True.\n"
+                        "You can create a specific column or edit an existing one from the menu %(menu:crm.menu_crm_case_section_act)s"), context=context)
         return True
 
     def case_mark_won(self, cr, uid, ids, context=None):
-        """ Mark the case as won: state=done and probability=100 """
+        """ Mark the case as won: stage with probability=100, , on_change=True """
         for lead in self.browse(cr, uid, ids):
-            stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0),('on_change','=',True)], context=context)
+            stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0), ('on_change', '=', True)], context=context)
             if stage_id:
-                self.case_set(cr, uid, [lead.id], values_to_update={'probability': 100.0}, new_stage_id=stage_id, context=context)
+                self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context)
+            else:
+                raise self.pool.get('res.config.settings').get_config_warning(cr,
+                    _("To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n"
+                        "probability = 100 and on_change = True.\n"
+                        "You can create a specific column or edit an existing one from the menu %(menu:crm.menu_crm_case_section_act)s"), context=context)
         return True
 
     def set_priority(self, cr, uid, ids, priority):
         """ Set lead priority
         """
-        return self.write(cr, uid, ids, {'priority' : priority})
+        return self.write(cr, uid, ids, {'priority': priority})
 
     def set_high_priority(self, cr, uid, ids, context=None):
         """ Set lead priority to high
@@ -650,7 +603,7 @@ class crm_lead(base_stage, format_address, osv.osv):
         sequenced_opps = []
         for opportunity in opportunities:
             sequence = -1
-            if opportunity.stage_id and opportunity.stage_id.state != 'cancel':
+            if opportunity.stage_id:
                 sequence = opportunity.stage_id.sequence
             sequenced_opps.append(((int(sequence != -1 and opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity))
 
@@ -705,8 +658,8 @@ class crm_lead(base_stage, format_address, osv.osv):
             'email_from': customer and customer.email or lead.email_from,
             'phone': customer and customer.phone or lead.phone,
         }
-        if not lead.stage_id or lead.stage_id.type=='lead':
-            val['stage_id'] = self.stage_find(cr, uid, [lead], section_id, [('state', '=', 'draft'),('type', 'in', ('opportunity','both'))], context=context)
+        if not lead.stage_id or lead.stage_id.type == 'lead':
+            val['stage_id'] = self.stage_find(cr, uid, [lead], section_id, ['&', ('sequence', '=', '1'), ('type', 'in', ('opportunity', 'both'))], context=context)
         return val
 
     def convert_opportunity(self, cr, uid, ids, partner_id, user_ids=False, section_id=False, context=None):
@@ -715,7 +668,8 @@ class crm_lead(base_stage, format_address, osv.osv):
             partner = self.pool.get('res.partner')
             customer = partner.browse(cr, uid, partner_id, context=context)
         for lead in self.browse(cr, uid, ids, context=context):
-            if lead.state in ('done', 'cancel'):
+            # avoid done / cancelled leads
+            if lead.probability == 100 or (lead.probability == 0 and lead.stage_id and lead.stage_id.sequence == 1):
                 continue
             vals = self._convert_opportunity_data(cr, uid, lead, customer, section_id, context=context)
             self.write(cr, uid, [lead.id], vals, context=context)
@@ -1025,7 +979,7 @@ class crm_lead(base_stage, format_address, osv.osv):
             'user_id': False,
         }
         if msg.get('author_id'):
-            defaults.update(self.on_change_partner(cr, uid, None, msg.get('author_id'), context=context)['value'])
+            defaults.update(self.onchange_partner_id(cr, uid, None, msg.get('author_id'), context=context)['value'])
         if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES):
             defaults['priority'] = msg.get('priority')
         defaults.update(custom_values)
@@ -1038,14 +992,14 @@ class crm_lead(base_stage, format_address, osv.osv):
         """
         if isinstance(ids, (str, int, long)):
             ids = [ids]
-        if update_vals is None: update_vals = {}
-
+        if update_vals is None:
+            update_vals = {}
         if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES):
             update_vals['priority'] = msg.get('priority')
         maps = {
-            'cost':'planned_cost',
+            'cost': 'planned_cost',
             'revenue': 'planned_revenue',
-            'probability':'probability',
+            'probability': 'probability',
         }
         for line in msg.get('body', '').split('\n'):
             line = line.strip()
index 0979a94..cda92ab 100644 (file)
@@ -1,75 +1,61 @@
 <?xml version="1.0"?>
 <openerp>
-    <data noupdate="1">
-
+    <!-- <data noupdate="1"> -->
+    <data>
         <!-- Crm stages -->
         <record model="crm.case.stage" id="stage_lead1">
             <field name="name">New</field>
-            <field eval="1" name="case_default"/>
-            <field name="state">draft</field>
-            <field eval="0" name="probability"/>
-            <field eval="10" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="probability">0</field>
+            <field name="on_change">1</field>
+            <field name="sequence">1</field>
             <field name="type">both</field>
         </record>
         <record model="crm.case.stage" id="stage_lead2">
-            <field name="name">Opportunity</field>
-            <field eval="1" name="case_default"/>
-            <field name="state">open</field>
-            <field eval="20" name="probability"/>
-            <field eval="20" name="sequence"/>
-            <field name="type">lead</field>
-        </record>
-        <record model="crm.case.stage" id="stage_lead7">
             <field name="name">Dead</field>
-            <field eval="1" name="case_default"/>
-            <field eval="False" name="fold"/>
-            <field name="state">cancel</field>
-            <field eval="0" name="probability"/>
-            <field eval="30" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="probability">0</field>
+            <field name="on_change">1</field>
+            <field name="sequence">30</field>
             <field name="type">lead</field>
         </record>
         <record model="crm.case.stage" id="stage_lead3">
             <field name="name">Qualification</field>
-            <field eval="1" name="case_default"/>
-            <field name="state">open</field>
-            <field eval="20" name="probability"/>
-            <field eval="100" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="probability">20</field>
+            <field name="on_change">1</field>
+            <field name="sequence">40</field>
             <field name="type">opportunity</field>
         </record>
         <record model="crm.case.stage" id="stage_lead4">
             <field name="name">Proposition</field>
-            <field eval="1" name="case_default"/>
-            <field name="state">open</field>
-            <field eval="40" name="probability"/>
-            <field eval="110" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="probability">40</field>
+            <field name="sequence">50</field>
             <field name="type">opportunity</field>
         </record>
         <record model="crm.case.stage" id="stage_lead5">
             <field name="name">Negotiation</field>
-            <field eval="1" name="case_default"/>
-            <field name="state">open</field>
-            <field eval="60" name="probability"/>
-            <field eval="120" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="probability">60</field>
+            <field name="sequence">60</field>
             <field name="type">opportunity</field>
         </record>
         <record model="crm.case.stage" id="stage_lead6">
             <field name="name">Won</field>
-            <field eval="True" name="fold"/>
-            <field eval="1" name="case_default"/>
-            <field name="state">done</field>
-            <field eval="100" name="probability"/>
-            <field eval="130" name="sequence"/>
-            <field eval="1" name="on_change"/>
+            <field name="case_default">1</field>
+            <field name="probability">100</field>
+            <field name="on_change">1</field>
+            <field name="sequence">70</field>
             <field name="type">opportunity</field>
         </record>
-        <record model="crm.case.stage" id="stage_lead8">
+        <record model="crm.case.stage" id="stage_lead7">
             <field name="name">Lost</field>
-            <field eval="1" name="case_default"/>
-            <field eval="True" name="fold"/>
-            <field eval="1" name="on_change"/>
-            <field name="state">cancel</field>
-            <field eval="0" name="probability"/>
-            <field eval="140" name="sequence"/>
+            <field name="case_default">1</field>
+            <field name="fold">1</field>
+            <field name="probability">0</field>
+            <field name="on_change">1</field>
+            <field name="sequence">80</field>
             <field name="type">opportunity</field>
         </record>
         
@@ -77,7 +63,7 @@
             <field name="stage_ids" eval="[ (4, ref('stage_lead1')), (4, ref('stage_lead2')),
                                             (4, ref('stage_lead3')), (4, ref('stage_lead4')),
                                             (4, ref('stage_lead5')), (4, ref('stage_lead6')),
-                                            (4, ref('stage_lead7')), (4, ref('stage_lead8'))]"/>
+                                            (4, ref('stage_lead7'))]"/>
         </record>
 
         <!-- Crm campain -->
             <field name="name">Lead Created</field>
             <field name="res_model">crm.lead</field>
             <field name="default" eval="False"/>
-            <field name="description">Opportunity created</field>
+            <field name="description">Lead created</field>
         </record>
         <record id="mt_lead_convert_to_opportunity" model="mail.message.subtype">
             <field name="name">Lead to Opportunity</field>
index e7e6bea..cdd3b30 100644 (file)
@@ -1,14 +1,15 @@
 <?xml version="1.0"?>
 <openerp>
-    <data noupdate="1">
+    <!-- <data noupdate="1"> -->
+    <data>
 
         <!--  Demo Leads -->
         <record id="crm_case_1" model="crm.lead">
             <field name="type">lead</field>
             <field name="name">Plan to Attend a Training</field>
-            <field name="contact_name">Jason Dunagan</field>
+            <field name="contact_name">Jacques Dunagan</field>
             <field name="partner_name">Le Club SARL</field>
-            <field name="email_from">jason@leclub.fr</field>
+            <field name="email_from">jdunagan@leclub.fr</field>
             <field name="partner_id" ref=""/>
             <field name="function">Training Manager</field>
             <field name="street">73, rue Léon Dierx</field>
             <field name="categ_ids" eval="[(6, 0, [categ_oppor6])]"/>
             <field name="channel_id" ref="crm_case_channel_email"/>
             <field name="priority">1</field>
-            <field name="section_id" ref="crm_case_section_2"/>
+            <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_root"/>
             <field name="stage_id" ref="stage_lead1"/>
             <field name="description">Hello,
-I am Jason from Le Club SARL.
-I am intertested to attend a training organized in your company.
-Can you send me the details ?</field>
-            <field eval="1" name="active"/>
+I am Jacques from Le Club SARL.
+I am interested to attend a training organized in your company.
+Could you please send me the details ?</field>
+        </record>
+        <record id="crm_case_1" model="crm.lead">
+            <field name="create_date" eval="(DateTime.today() - relativedelta(months=2)).strftime('%Y-%m-%d %H:%M')"/>
+        </record>
+        <record id="msg_case1_1" model="mail.message">
+            <field name="subject">Inquiry</field>
+            <field name="model">crm.lead</field>
+            <field name="res_id" ref="crm_case_1"/>
+            <field name="body"><![CDATA[<p>Hello,<br />
+            I am Jacques from Le Club SARL. I am interested to attend a training organized in your company.<br />
+            Can you send me the details ?</p>]]></field>
+            <field name="type">email</field>
         </record>
 
         <record id="crm_case_2" model="crm.lead">
@@ -44,10 +56,20 @@ Can you send me the details ?</field>
             <field name="categ_ids" eval="[(6, 0, [categ_oppor2])]"/>
             <field name="channel_id" ref="crm_case_channel_website"/>
             <field name="priority">4</field>
-            <field name="section_id" ref="crm_case_section_2"/>
+            <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_root"/>
             <field name="stage_id" ref="stage_lead1"/>
-            <field eval="1" name="active"/>
+        </record>
+        <record id="crm_case_2" model="crm.lead">
+            <field name="create_date" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
+        </record>
+        <record id="msg_case2_1" model="mail.message">
+            <field name="subject">Need Details</field>
+            <field name="model">crm.lead</field>
+            <field name="author_id" ref="base.partner_demo"/>
+            <field name="res_id" ref="crm_case_2"/>
+            <field name="body">Want to know features and benefits to use the new software.</field>
+            <field name="type">comment</field>
         </record>
 
         <record id="crm_case_3" model="crm.lead">
@@ -65,8 +87,10 @@ Can you send me the details ?</field>
             <field name="priority">2</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="stage_lead2"/>
-            <field eval="1" name="active"/>
+            <field name="stage_id" ref="stage_lead1"/>
+        </record>
+        <record id="crm_case_2" model="crm.lead">
+            <field name="create_date" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
         </record>
 
         <record id="crm_case_4" model="crm.lead">
@@ -82,10 +106,12 @@ Can you send me the details ?</field>
             <field name="categ_ids" eval="[(6, 0, [categ_oppor5])]"/>
             <field name="channel_id" ref=""/>
             <field name="priority">3</field>
-            <field name="section_id" ref="crm_case_section_1"/>
-            <field name="user_id" ref=""/>
-            <field name="stage_id" ref="stage_lead7"/>
-            <field eval="1" name="active"/>
+            <field name="section_id" ref="crm_case_section_2"/>
+            <field name="user_id" ref="base.user_demo"/>
+            <field name="stage_id" ref="stage_lead1"/>
+        </record>
+        <record id="crm_case_2" model="crm.lead">
+            <field name="create_date" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
         </record>
 
         <record id="crm_case_5" model="crm.lead">
@@ -105,8 +131,8 @@ Can you send me the details ?</field>
             <field name="categ_ids" eval="[(6, 0, [categ_oppor1])]"/>
             <field name="channel_id" ref="crm_case_channel_website"/>
             <field name="priority">3</field>
-            <field name="section_id" ref="section_sales_department"/>
-            <field name="user_id" ref="base.user_root"/>
+            <field name="section_id" ref="crm_case_section_1"/>
+            <field name="user_id" ref=""/>
             <field name="stage_id" ref="stage_lead1"/>
             <field name="description">Hi,
 Can you send me a quotation for 20 computers with speakers?
@@ -116,7 +142,6 @@ Purchase Manager
 Stonage IT,
 Franklinville
 Contact: +1 813 494 5005</field>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_6" model="crm.lead">
@@ -134,9 +159,8 @@ Contact: +1 813 494 5005</field>
             <field name="channel_id" ref=""/>
             <field name="priority">3</field>
             <field name="section_id" ref="crm_case_section_2"/>
-            <field name="user_id" ref="base.user_root"/>
+            <field name="user_id" ref=""/>
             <field name="stage_id" ref="stage_lead1"/>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_7" model="crm.lead">
@@ -153,9 +177,8 @@ Contact: +1 813 494 5005</field>
             <field name="channel_id" ref=""/>
             <field name="priority">5</field>
             <field name="section_id" ref="crm_case_section_2"/>
-            <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="stage_lead7"/>
-            <field eval="1" name="active"/>
+            <field name="user_id" ref="base.user_root"/>
+            <field name="stage_id" ref="stage_lead1"/>
         </record>
 
         <record id="crm_case_8" model="crm.lead">
@@ -173,9 +196,8 @@ Contact: +1 813 494 5005</field>
             <field name="channel_id" ref=""/>
             <field name="priority">4</field>
             <field name="section_id" ref="section_sales_department"/>
-            <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="stage_lead7"/>
-            <field eval="1" name="active"/>
+            <field name="user_id" ref="base.user_root"/>
+            <field name="stage_id" ref="stage_lead1"/>
         </record>
 
         <record id="crm_case_9" model="crm.lead">
@@ -193,12 +215,8 @@ Contact: +1 813 494 5005</field>
             <field name="channel_id" ref="crm_case_channel_phone"/>
             <field name="priority">2</field>
             <field name="section_id" ref="section_sales_department"/>
-            <field name="user_id" ref="base.user_root"/>
+            <field name="user_id" ref="base.user_demo"/>
             <field name="stage_id" ref="stage_lead1"/>
-            <field eval="1" name="active"/>
-        </record>
-        <record id="crm_case_9" model="crm.lead">
-            <field name="create_date" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
         </record>
 
         <record id="crm_case_10" model="crm.lead">
@@ -215,14 +233,13 @@ Contact: +1 813 494 5005</field>
             <field name="channel_id" ref="crm_case_channel_email"/>
             <field name="priority">2</field>
             <field name="section_id" ref="crm_case_section_2"/>
-            <field name="user_id" ref=""/>
+            <field name="user_id" ref="base.user_demo"/>
             <field name="stage_id" ref="stage_lead1"/>
             <field name="description">Hi,
 I would like to know more about specification and cost of laptops of your company.
 
 Thanks,
 Andrew</field>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_11" model="crm.lead">
@@ -239,9 +256,8 @@ Andrew</field>
             <field name="channel_id" ref="crm_case_channel_direct"/>
             <field name="priority">3</field>
             <field name="section_id" ref="crm_case_section_1"/>
-            <field name="user_id" ref="base.user_demo"/>
+            <field name="user_id" ref=""/>
             <field name="stage_id" ref="stage_lead1"/>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_12" model="crm.lead">
@@ -258,22 +274,23 @@ Andrew</field>
             <field name="channel_id" ref="crm_case_channel_website"/>
             <field name="priority">2</field>
             <field name="section_id" ref="section_sales_department"/>
-            <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="stage_lead2"/>
-            <field eval="1" name="active"/>
+            <field name="user_id" ref=""/>
+            <field name="stage_id" ref="stage_lead1"/>
         </record>
 
         <!-- Call Function to Cancel the leads (set as Dead) -->
-        <function model="crm.lead" name="case_cancel"
-            eval="[ ref('crm_case_12'), ref('crm_case_7'),
-                    ref('crm_case_3'), ref('crm_case_8')],
-                  {'install_mode': True}"
+        <function model="crm.lead" name="write"
+            eval="[ ref('crm_case_7'), ref('crm_case_8'),
+                    ref('crm_case_9'), ref('crm_case_10'),
+                    ref('crm_case_11'), ref('crm_case_12')],
+                    {'stage_id': ref('stage_lead2')},
+                    {'install_mode': True}"
         />
 
         <!-- Call Function to set the leads as Unread -->
         <function model="crm.lead" name="message_mark_as_unread"
             eval="[ ref('crm_case_1'), ref('crm_case_2'),
-                    ref('crm_case_5'), ref('crm_case_11')], {}"
+                    ref('crm_case_5'), ref('crm_case_6')], {}"
         />
 
         <!-- Demo Opportunities -->
@@ -297,7 +314,6 @@ Andrew</field>
             <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_root"/>
             <field name="stage_id" ref="crm.stage_lead3"/>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_14" model="crm.lead">
@@ -323,7 +339,6 @@ Andrew</field>
             <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_demo"/>
             <field name="stage_id" ref="crm.stage_lead3"/>
-            <field eval="1" name="active"/>
         </record>
 
         <record id="crm_case_15" model="crm.lead">
@@ -344,9 +359,8 @@ Andrew</field>
             <field name="title_action">Call to ask system requirement</field>
             <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(months=2)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead3"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(months=2)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_16" model="crm.lead">
@@ -369,9 +383,8 @@ Andrew</field>
             <field name="title_action">Convert to quote</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead3"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_17" model="crm.lead">
@@ -395,9 +408,8 @@ Andrew</field>
             <field name="title_action">Send price list regarding our interventions</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead4"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_18" model="crm.lead">
@@ -420,7 +432,7 @@ Andrew</field>
             <field name="title_action">Call to define real needs about training</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead3"/>
+            <field name="stage_id" ref="crm.stage_lead4"/>
             <field eval="1" name="active"/>
         </record>
 
@@ -444,9 +456,8 @@ Andrew</field>
             <field name="title_action">Ask for the good receprion of the proposition</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_root"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(months=3)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead4"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(months=3)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_20" model="crm.lead">
@@ -462,8 +473,7 @@ Andrew</field>
             <field name="priority">2</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead1"/>
-            <field eval="1" name="active"/>
+            <field name="stage_id" ref="crm.stage_lead4"/>
         </record>
 
         <record id="crm_case_21" model="crm.lead">
@@ -477,9 +487,8 @@ Andrew</field>
             <field name="priority">3</field>
             <field name="section_id" ref="crm_case_section_2"/>
             <field name="user_id" ref="base.user_root"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead4"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_22" model="crm.lead">
@@ -496,8 +505,7 @@ Andrew</field>
             <field name="priority">3</field>
             <field name="section_id" ref="crm_case_section_2"/>
             <field name="user_id" ref="base.user_root"/>
-            <field name="stage_id" ref="crm.stage_lead8"/>
-            <field eval="1" name="active"/>
+            <field name="stage_id" ref="crm.stage_lead5"/>
         </record>
 
         <record id="crm_case_23" model="crm.lead">
@@ -512,9 +520,8 @@ Andrew</field>
             <field name="priority">5</field>
             <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead5"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_24" model="crm.lead">
@@ -532,9 +539,8 @@ Andrew</field>
             <field eval="time.strftime('%Y-%m-6')" name="date_deadline"/>
             <field name="section_id" ref="section_sales_department"/>
             <field name="user_id" ref="base.user_root"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(month=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead5"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(month=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <record id="crm_case_25" model="crm.lead">
@@ -556,8 +562,7 @@ Andrew</field>
             <field name="title_action">Conf call with technical service</field>
             <field name="section_id" ref="crm_case_section_1"/>
             <field name="user_id" ref="base.user_root"/>
-            <field name="stage_id" ref="crm.stage_lead4"/>
-            <field eval="1" name="active"/>
+            <field name="stage_id" ref="crm.stage_lead5"/>
         </record>
 
         <record id="crm_case_26" model="crm.lead">
@@ -581,9 +586,8 @@ Andrew</field>
             <field name="title_action">Send Catalogue by Email</field>
             <field name="section_id" ref="crm_case_section_2"/>
             <field name="user_id" ref="base.user_demo"/>
-            <field name="stage_id" ref="crm.stage_lead6"/>
-            <field eval="1" name="active"/>
-            <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/>
+            <field name="stage_id" ref="crm.stage_lead5"/>
+            <!-- <field name="date_closed" eval="(DateTime.today() - relativedelta(hours=1)).strftime('%Y-%m-%d %H:%M')"/> -->
         </record>
 
         <!-- Unsubscribe Admin from case15, subscribe Demo -->
@@ -689,22 +693,6 @@ Andrew</field>
             <field name="parent_id" ref="msg_case18_1"/>
             <field name="author_id" ref="base.partner_demo"/>
         </record>
-        <record id="msg_case1_1" model="mail.message">
-            <field name="subject">Inquiry</field>
-            <field name="model">crm.lead</field>
-            <field name="res_id" ref="crm_case_1"/>
-            <field name="body"><![CDATA[<p>Hello,<br />
-            I am Jason from Le Club SARL. I am interested to attend a training organized in your company.<br />
-            Can you send me the details ?</p>]]></field>
-            <field name="type">email</field>
-        </record>
-        <record id="msg_case2_1" model="mail.message">
-            <field name="subject">Need Details</field>
-            <field name="model">crm.lead</field>
-            <field name="res_id" ref="crm_case_2"/>
-            <field name="body">Want to know features and benefits to use the new software.</field>
-            <field name="type">comment</field>
-        </record>
         <function model="mail.message" name="set_message_starred"
             eval="[ ref('msg_case18_1'), ref('msg_case18_2')], True, {}"
         />
index 6ddd06c..b5d28e5 100644 (file)
             <field name="model">crm.case.stage</field>
             <field name="arch" type="xml">
                 <search string="Stage Search">
-                    <field name="name" string="Stage Name"/>
-                    <field name="state"/>
+                    <field name="name"/>
                     <field name="type"/>
+                    <field name="sequence"/>
+                    <field name="probability"/>
                 </search>
             </field>
         </record>
             <form string="Leads Form" version="7.0">
                 <header>
                     <button name="%(crm.action_crm_lead2opportunity_partner)d" string="Convert to Opportunity" type="action"
-                            states="draft,open,pending" help="Convert to Opportunity" class="oe_highlight"/>
-                    <button name="case_reset" string="Reset" type="object"
-                            states="cancel"/>
-                    <button name="case_cancel" string="Cancel Case" type="object"
-                            states="draft,open,pending"/>
+                            attrs="{'invisible': [('probability', '=', 100)]}"
+                            help="Convert to Opportunity" class="oe_highlight"/>
                     <field name="stage_id" widget="statusbar" clickable="True"
                             domain="['&amp;', '|', ('case_default', '=', True), ('section_ids', '=', section_id), '|', ('type', '=', type), ('type', '=', 'both')]"
                             on_change="onchange_stage_id(stage_id)"/>
                             <field name="phone"/>
                             <field name="mobile"/>
                             <field name="fax"/>
-                            <!--
-                            This should be integrated in Open Chatter
-                            <button string="Mail"
-                                name="%(mail.action_email_compose_message_wizard)d"
-                                icon="terp-mail-message-new" type="action" colspan="1"/>
-                            -->
                         </group>
                         <group>
                             <field name="user_id" on_change="on_change_user(user_id, context)"
                                 <field name="section_id"/>
                                 <button name="case_escalate" string="Escalate"
                                         type="object" class="oe_link"
-                                        attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
+                                        attrs="{'invisible': ['|', ('section_id','=',False), ('probability', '=', 100)]}"/>
                             </div>
                             <field name="type" invisible="1"/>
                         </group>
                                 <field name="company_id"
                                     groups="base.group_multi_company"
                                     widget="selection" colspan="2"/>
-                                <field name="state" groups="base.group_no_one"/>
                             </group>
                             <group string="Mailings">
                                 <field name="opt_out"/>
                             </group>
                             <group string="Misc">
+                                <field name="probability" groups="base.group_no_one"/>
                                 <field name="active"/>
                                 <field name="referred"/>
                             </group>
             <field name="name">Leads</field>
             <field name="model">crm.lead</field>
             <field name="arch" type="xml">
-                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:state in ('cancel', 'done')">
+                <tree string="Leads" fonts="bold:message_unread==True" colors="grey:probability == 100">
                     <field name="date_deadline" invisible="1"/>
                     <field name="create_date"/>
                     <field name="name"/>
                     <field name="user_id" invisible="1"/>
                     <field name="partner_id" invisible="1"/>
                     <field name="section_id" invisible="context.get('invisible_section', True)" groups="base.group_multi_salesteams"/>
-                    <field name="state" invisible="1"/>
+                    <field name="probability" invisible="1"/>
                     <field name="type_id" invisible="1"/>
                     <field name="referred" invisible="1"/>
                     <field name="channel_id" invisible="1"/>
             <field name="model">crm.lead</field>
             <field name="arch" type="xml">
                 <kanban default_group_by="stage_id">
-                    <field name="state" groups="base.group_no_one"/>
                     <field name="stage_id"/>
                     <field name="color"/>
                     <field name="priority"/>
                     <field name="create_date"/>
                     <field name="country_id" context="{'invisible_country': False}"/>
                     <separator/>
-                    <filter string="Open" name="open" domain="[('state','!=','cancel')]" help="Open Leads"/>
-                    <filter string="Dead" name="dead" domain="[('state','=','cancel')]"/>
-                    <filter string="Unassigned" name="unassigned" domain="[('user_id','=', False)]" help="No salesperson"/>
-                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]" help="Unread messages"/>
+                    <filter string="Open" name="open" domain="[('user_id', '!=', 'False'), ('probability', '!=', 100)]" help="Open and Assigned Leads"/>
+                    <filter string="Dead" name="dead" domain="[('probability', '=', '0'), ('stage_id.sequence', '!=', 1)]"/>
+                    <filter string="Unassigned" name="unassigned" domain="[('user_id','=', False), ('probability', '!=', 100)]" help="No salesperson"/>
                     <filter string="Assigned to Me"
                             domain="[('user_id','=',uid)]" context="{'invisible_section': False}"
                             help="Leads that are assigned to me"/>
                     <filter string="Assigned to My Team(s)"
                             domain="[('section_id.member_ids', 'in', [uid])]" context="{'invisible_section': False}"
                             help="Leads that are assigned to any sales teams I am member of" groups="base.group_multi_salesteams"/>
+                    <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]" help="Unread messages"/>
                     <separator />
                     <filter string="Available for mass mailing"
                             name='not_opt_out' domain="[('opt_out', '=', False)]"
             <field name="arch" type="xml">
                 <form string="Opportunities" version="7.0">
                     <header>
-                        <button name="case_mark_won" string="Mark Won" type="object"
-                                states="draft,open,pending" class="oe_highlight"/>
-                        <button name="case_mark_lost" string="Mark Lost" type="object"
-                                states="draft,open" class="oe_highlight"/>
-                        <field name="stage_id" widget="statusbar" clickable="True"/>
+                        <button name="case_mark_won" string="Mark Won" type="object" class="oe_highlight"
+                                attrs="{'invisible': [('probability', '=', 100)]}"/>
+                        <button name="case_mark_lost" string="Mark Lost" type="object" class="oe_highlight"
+                                attrs="{'invisible': [('probability', '=', 100)]}"/>
+                        <field name="stage_id" widget="statusbar" clickable="True"
+                                domain="['&amp;', '|', ('case_default', '=', True), ('section_ids', '=', section_id), '|', ('type', '=', type), ('type', '=', 'both')]"/>
                     </header>
                     <sheet>
                         <div class="oe_right oe_button_box">
-                            <button string="Schedule/Log Call"
-                                name="%(opportunity2phonecall_act)d"
-                                type="action"/>
-                            <button string="Meeting"
+                            <button string="Schedule/Log Call" type="action"
+                                name="%(opportunity2phonecall_act)d"/>
+                            <button string="Meeting" type="object"
                                 name="action_makeMeeting"
-                                type="object"
                                 context="{'search_default_attendee_id': active_id, 'default_attendee_id' : active_id}"/>
                         </div>
                         <div class="oe_title">
                                 <label for="section_id" groups="base.group_multi_salesteams"/>
                                 <div groups="base.group_multi_salesteams">
                                     <field name="section_id" widget="selection"/>
-                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link" attrs="{'invisible': ['|', ('section_id','=',False), ('state', 'not in', ['draft','open','pending'])]}"/>
+                                    <button name="case_escalate" string="Escalate" type="object" class="oe_link"
+                                            attrs="{'invisible': ['|', ('section_id','=',False), ('probability', '=', 100)]}"/>
                                 </div>
                             </group>
                             <group>
                                     <field name="day_open" groups="base.group_no_one"/>
                                     <field name="day_close" groups="base.group_no_one"/>
                                     <field name="referred"/>
-                                    <field name="state" invisible="1"/>
                                     <field name="type" invisible="1"/>
                                 </group>
                                 <group string="References">
             <field name="name">Opportunities Tree</field>
             <field name="model">crm.lead</field>
             <field name="arch" type="xml">
-                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:state in ('cancel', 'done');red:date_deadline and (date_deadline &lt; current_date)">
+                <tree string="Opportunities" fonts="bold:message_unread==True" colors="gray:probability == 100;red:date_deadline and (date_deadline &lt; current_date)">
                     <field name="date_deadline" invisible="1"/>
                     <field name="create_date"/>
                     <field name="name" string="Opportunity"/>
                     <field name="referred" invisible="1"/>
                     <field name="priority" invisible="1"/>
                     <field name="message_unread" invisible="1"/>
-                    <field name="state" invisible="1"/>
+                    <field name="probability" invisible="1"/>
                 </tree>
             </field>
         </record>
                     <field name="section_id" context="{'invisible_section': False}" groups="base.group_multi_salesteams"/>
                     <field name="user_id"/>
                     <field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
+                    <field name="stage_id"/>
+                    <field name="probability"/>
                     <separator/>
-                    <filter string="New" name="new" domain="[('state','=','draft')]" help="New Opportunities"/>
-                    <filter string="In Progress" name="open" domain="[('state','=','open')]" help="Open Opportunities"/>
-                    <filter string="Won" name="won" domain="[('state','=','done')]"/>
-                    <filter string="Lost" name="lost" domain="[('state','=','cancel')]"/>
+                    <filter string="New" name="new" domain="[('probability', '=', 0), ('stage_id.sequence', '=', 1)]" help="New Opportunities"/>
+                    <filter string="Won" name="won" domain="[('probability', '=', 100)]"/>
+                    <filter string="Lost" name="lost" domain="[('probability', '=',0), ('stage_id.sequence, '!=', 1')]"/>
                     <filter string="Unassigned" name="unassigned" domain="[('user_id','=', False)]" help="No salesperson"/>
                     <filter string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]" help="Unread messages"/>
                     <filter string="My Opportunities" name="assigned_to_me"
index a84ae55..d0dcc07 100644 (file)
@@ -80,7 +80,6 @@
                     <field name="sequence" widget="handle"/>
                     <field name="name"/>
                     <field name="probability"/>
-                    <field name="state"/>
                     <field name="type"/>
                 </tree>
             </field>
@@ -96,7 +95,6 @@
                 <form string="Stage" version="7.0">
                     <group col="4">
                         <field name="name"/>
-                        <field name="state"/>
                         <field name="probability"/>
                         <field name="type"/>
                         <field name="on_change"/>
index d12facd..7baa721 100644 (file)
@@ -23,13 +23,13 @@ from openerp.osv import fields,osv
 from openerp import tools
 from .. import crm
 
-AVAILABLE_STATES = [
-    ('draft','Draft'),
-    ('open','Open'),
-    ('cancel', 'Cancelled'),
-    ('done', 'Closed'),
-    ('pending','Pending')
-]
+# AVAILABLE_STATES = [
+#     ('draft','Draft'),
+#     ('open','Open'),
+#     ('cancel', 'Cancelled'),
+#     ('done', 'Closed'),
+#     ('pending','Pending')
+# ]
 
 MONTHS = [
     ('01', 'January'),
@@ -79,7 +79,7 @@ class crm_lead_report(osv.osv):
         'section_id':fields.many2one('crm.case.section', 'Sales Team', readonly=True),
         'channel_id':fields.many2one('crm.case.channel', 'Channel', readonly=True),
         'type_id':fields.many2one('crm.case.resource.type', 'Campaign', readonly=True),
-        'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
+        # 'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
         'company_id': fields.many2one('res.company', 'Company', readonly=True),
         'probability': fields.float('Probability',digits=(16,2),readonly=True, group_operator="avg"),
         'planned_revenue': fields.float('Planned Revenue',digits=(16,2),readonly=True),
@@ -121,7 +121,6 @@ class crm_lead_report(osv.osv):
                     to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
                     to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
 
-                    c.state,
                     c.user_id,
                     c.probability,
                     c.stage_id,
index 09853c6..f9439c4 100644 (file)
@@ -13,7 +13,7 @@
                 <field name="creation_month" invisible="1"/>
                 <field name="creation_day" invisible="1"/>
                 <field name="deadline_month" invisible="1"/>
-                <field name="state"  invisible="1"/>
+                <!-- <field name="state"  invisible="1"/> -->
                 <field name="stage_id"  invisible="1"/>
                 <field name="type_id" invisible="1"/>
                 <field name="channel_id" invisible="1"/>
                     <filter icon="terp-personal" name="lead" string="Lead" domain="[('type','=', 'lead')]" help="Show only lead"/>
                     <filter icon="terp-personal+" string="Opportunity" name="opportunity" domain="[('type','=','opportunity')]" help="Show only opportunity"/>
                     <separator/>
-                    <filter icon="terp-check" string="New" domain="[('state','=','draft')]" help="Leads/Opportunities which are in New state"/>
-                    <filter icon="terp-camera_test" string="Open" domain="[('state','=','open')]" help="Leads/Opportunities which are in open state"/>
-                    <filter icon="gtk-media-pause" string="Pending" domain="[('state','=','pending')]" help="Leads/Opportunities which are in pending state"/>
-                    <filter icon="terp-dialog-close" string="Closed" domain="[('state','=','done')]" help="Leads/Opportunities which are in done state"/>
+                    <!-- <filter icon="terp-check" string="New" domain="[('state','=','draft')]" help="Leads/Opportunities which are in New state"/> -->
+                    <!-- <filter icon="terp-camera_test" string="Open" domain="[('state','=','open')]" help="Leads/Opportunities which are in open state"/> -->
+                    <!-- <filter icon="gtk-media-pause" string="Pending" domain="[('state','=','pending')]" help="Leads/Opportunities which are in pending state"/> -->
+                    <!-- <filter icon="terp-dialog-close" string="Closed" domain="[('state','=','done')]" help="Leads/Opportunities which are in done state"/> -->
                     <separator/>
                     <filter string="My Sales Team(s)" icon="terp-personal+" context="{'invisible_section': False}" domain="[('section_id.user_id','=',uid)]"
                             help="Leads/Opportunities that are assigned to one of the sale teams I manage" groups="base.group_multi_salesteams"/>
             <field name="name">crm.lead.report.tree</field>
             <field name="model">crm.lead.report</field>
             <field name="arch" type="xml">
-            <tree colors="blue:state == 'draft';black:state in ('open','pending','done');gray:state == 'cancel' " create="false" string="Opportunities Analysis">
+            <!-- <tree colors="blue:state == 'draft';black:state in ('open','pending','done');gray:state == 'cancel' " create="false" string="Opportunities Analysis"> -->
+            <tree create="false" string="Opportunities Analysis">
                 <field name="creation_year" invisible="1"/>
                 <field name="creation_month" invisible="1"/>
                 <field name="creation_day" invisible="1"/>
                 <field name="user_id" invisible="1"/>
                 <field name="partner_id" invisible="1"/>
                 <field name="country_id" invisible="1"/>
-                <field name="state"  invisible="1"/>
+                <!-- <field name="state"  invisible="1"/> -->
                 <field name="stage_id"  invisible="1"/>
                 <field name="priority"  invisible="1"/>
                 <field name="type_id" invisible="1"/>
index 7719509..0bc1d8b 100644 (file)
@@ -23,13 +23,13 @@ from openerp.osv import fields,osv
 from openerp import tools
 from .. import crm
 
-AVAILABLE_STATES = [
-    ('draft','Draft'),
-    ('open','Todo'),
-    ('cancel', 'Cancelled'),
-    ('done', 'Held'),
-    ('pending','Pending')
-]
+# AVAILABLE_STATES = [
+#     ('draft','Draft'),
+#     ('open','Todo'),
+#     ('cancel', 'Cancelled'),
+#     ('done', 'Held'),
+#     ('pending','Pending')
+# ]
 
 
 class crm_phonecall_report(osv.osv):
@@ -45,7 +45,7 @@ class crm_phonecall_report(osv.osv):
         'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
         'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
         'nbr': fields.integer('# of Cases', readonly=True),
-        'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
+        # 'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
         'month':fields.selection([('01', 'January'), ('02', 'February'), \
                                   ('03', 'March'), ('04', 'April'),\
                                   ('05', 'May'), ('06', 'June'), \
@@ -83,7 +83,6 @@ class crm_phonecall_report(osv.osv):
                     to_char(c.create_date, 'YYYY-MM-DD') as creation_date,
                     to_char(c.date_open, 'YYYY-MM-DD') as opening_date,
                     to_char(c.date_closed, 'YYYY-mm-dd') as date_closed,
-                    c.state,
                     c.user_id,
                     c.section_id,
                     c.categ_id,
index aa2162d..92af93a 100644 (file)
@@ -17,7 +17,7 @@
                     <field name="user_id" invisible="1"/>
                     <field name="company_id" invisible="1"/>
                     <field name="partner_id" invisible="1"/>
-                    <field name="state" invisible="1"/>
+                    <!-- <field name="state" invisible="1"/> -->
                     <field name="categ_id" invisible="1"/>
                     <field name="day" invisible="1"/>
                     <field name="nbr" string="#Phone calls" sum="#Phone calls"/>
@@ -35,7 +35,7 @@
             <field name="model">crm.phonecall.report</field>
             <field name="arch" type="xml">
                 <graph orientation="horizontal" string="Phone calls" type="bar">
-                    <field name="state"/>
+                    <!-- <field name="state"/> -->
                     <field name="nbr" operator="+"/>
                     <field group="True" name="user_id"/>
                 </graph>
             <field name="model">crm.phonecall.report</field>
             <field name="arch" type="xml">
                 <search string="Search">
-                    <filter icon="terp-gtk-go-back-rtl" string="Todo" domain="[('state','in',('draft','open'))]"
+<!--                     <filter icon="terp-gtk-go-back-rtl" string="Todo" domain="[('state','in',('draft','open'))]"
                         help="Phone calls which are in draft and open state"/>
                     <filter icon="terp-camera_test" string="Held" domain="[('state','=','done')]"
                         help="Phone calls which are in closed state"/>
                     <filter icon="gtk-media-pause" string="Not Held" domain="[('state','=','pending')]"
-                        help="Phone calls which are in pending state"/>
+                        help="Phone calls which are in pending state"/> -->
                     <separator/>
                     <filter string="My Sales Team(s)" icon="terp-personal+" context="{'invisible_section': False}" domain="[('section_id.user_id','=',uid)]"
                             help="Phone calls that are assigned to one of the sale teams I manage" groups="base.group_multi_salesteams"/>
@@ -76,7 +76,7 @@
                         <filter string="Partner" icon="terp-partner" context="{'group_by':'partner_id'}" />
                         <filter string="Priority"  icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}" />
                         <filter string="Category" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'categ_id'}" />
-                        <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}" />
+                        <!-- <filter string="Status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}" /> -->
                         <filter string="Company" icon="terp-go-home" domain="[]" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
                         <filter string="Day" icon="terp-go-today" domain="[]" context="{'group_by':'day'}" help="Date of call"/>
                         <filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by':'month'}" help="Month of call"/>
index f25b130..087a703 100644 (file)
@@ -41,7 +41,7 @@ class res_partner(osv.osv):
     _columns = {
         'section_id': fields.many2one('crm.case.section', 'Sales Team'),
         'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
-            'Leads and Opportunities', domain=[('state','in', ('draft','open','pending'))]),
+            'Leads and Opportunities', domain=[('probability', '<', ('100'))]),
         'meeting_ids': fields.many2many('crm.meeting', 'crm_meeting_partner_rel','partner_id', 'meeting_id',
             'Meetings'),
         'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
@@ -87,7 +87,6 @@ class res_partner(osv.osv):
                 'probability' : probability,
                 'partner_id' : partner_id,
                 'categ_ids' : categ_ids and categ_ids[0:1] or [],
-                'state' :'draft',
                 'type': 'opportunity'
             }, context=context)
             opportunity_ids[partner_id] = opportunity_id
index 3c847ad..0b8c3dc 100644 (file)
@@ -21,7 +21,6 @@
 
 from openerp.osv import fields, osv
 from openerp.tools.translate import _
-from openerp import tools
 import re
 
 class crm_lead2opportunity_partner(osv.osv_memory):
@@ -58,20 +57,20 @@ class crm_lead2opportunity_partner(osv.osv_memory):
 
             if partner_id:
                 # Search for opportunities that have the same partner and that arent done or cancelled
-                ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('state', '!=', 'done')])
+                ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('probability', '<', '100')])
                 for id in ids:
                     tomerge.add(id)
             if email:
-                ids = lead_obj.search(cr, uid, [('email_from', 'ilike', email[0]), ('state', '!=', 'done')])
+                ids = lead_obj.search(cr, uid, [('email_from', 'ilike', email[0]), ('probability', '<', '100')])
                 for id in ids:
                     tomerge.add(id)
 
             if 'action' in fields:
-                res.update({'action' : partner_id and 'exist' or 'create'})
+                res.update({'action': partner_id and 'exist' or 'create'})
             if 'partner_id' in fields:
-                res.update({'partner_id' : partner_id})
+                res.update({'partner_id': partner_id})
             if 'name' in fields:
-                res.update({'name' : len(tomerge) >= 2 and 'merge' or 'convert'})
+                res.update({'name': len(tomerge) >= 2 and 'merge' or 'convert'})
             if 'opportunity_ids' in fields and len(tomerge) >= 2:
                 res.update({'opportunity_ids': list(tomerge)})
 
@@ -85,8 +84,8 @@ class crm_lead2opportunity_partner(osv.osv_memory):
             context = {}
         lead_obj = self.pool.get('crm.lead')
         for lead in lead_obj.browse(cr, uid, context.get('active_ids', []), context=context):
-            if lead.state in ['done', 'cancel']:
-                raise osv.except_osv(_("Warning!"), _("Closed/Cancelled leads cannot be converted into opportunities."))
+            if lead.probability == 100:
+                raise osv.except_osv(_("Warning!"), _("Dead leads cannot be converted into opportunities."))
         return False
 
     def _convert_opportunity(self, cr, uid, ids, vals, context=None):
index 8b78c03..051a8dc 100644 (file)
@@ -60,8 +60,7 @@ class crm_merge_opportunity(osv.osv_memory):
     def default_get(self, cr, uid, fields, context=None):
         """
         Use active_ids from the context to fetch the leads/opps to merge.
-        In order to get merged, these leads/opps can't be in 'Done' or
-        'Cancel' state.
+        In order to get merged, these leads/opps can't be in 'Dead'.
         """
         if context is None:
             context = {}
@@ -72,7 +71,7 @@ class crm_merge_opportunity(osv.osv_memory):
             opp_ids = []
             opps = self.pool.get('crm.lead').browse(cr, uid, record_ids, context=context)
             for opp in opps:
-                if opp.state not in ('done', 'cancel'):
+                if opp.probability < 100:
                     opp_ids.append(opp.id)
             if 'opportunity_ids' in fields:
                 res.update({'opportunity_ids': opp_ids})
index a46f416..6b466f0 100644 (file)
@@ -308,8 +308,8 @@ class mail_thread(osv.AbstractModel):
         # Track initial values of tracked fields
         tracked_fields = self._get_tracked_fields(cr, uid, values.keys(), context=context)
         if tracked_fields:
-            initial = self.read(cr, uid, ids, tracked_fields.keys(), context=context)
-            initial_values = dict((item['id'], item) for item in initial)
+            records = self.browse(cr, uid, ids, context=context)
+            initial_values = dict((this.id, dict((key, getattr(this, key)) for key in tracked_fields.keys())) for this in records)
 
         # Perform write, update followers
         result = super(mail_thread, self).write(cr, uid, ids, values, context=context)
@@ -368,7 +368,8 @@ class mail_thread(osv.AbstractModel):
             if not value:
                 return ''
             if col_info['type'] == 'many2one':
-                return value[1]
+                # return value[1]
+                return value.name_get()[0][1]
             if col_info['type'] == 'selection':
                 return dict(col_info['selection'])[value]
             return value
@@ -387,7 +388,9 @@ class mail_thread(osv.AbstractModel):
         if not tracked_fields:
             return True
 
-        for record in self.read(cr, uid, ids, tracked_fields.keys(), context=context):
+        for browse_record in self.browse(cr, uid, ids, context=context):
+            record = dict((key, getattr(browse_record, key)) for key in tracked_fields.keys())
+            record['id'] = browse_record.id
             initial = initial_values[record['id']]
             changes = []
             tracked_values = {}
@@ -413,7 +416,7 @@ class mail_thread(osv.AbstractModel):
                 if field not in changes:
                     continue
                 for subtype, method in track_info.items():
-                    if method(self, cr, uid, record, context):
+                    if method(self, cr, uid, browse_record, context):
                         subtypes.append(subtype)
 
             posted = False