diff --git a/addons/base_status/base_stage.py b/addons/base_status/base_stage.py index 418c927fc0b..33d28adfbe8 100644 --- a/addons/base_status/base_stage.py +++ b/addons/base_status/base_stage.py @@ -19,7 +19,6 @@ # ############################################################################## -from openerp.osv import fields, osv from openerp.tools.translate import _ @@ -82,6 +81,7 @@ class base_stage(object): 'phone': address and address.phone or False, 'mobile': address and address.mobile or False, 'fax': address and address.fax or False, + 'function': address and address.function or False, 'street': address and address.street or False, 'street2': address and address.street2 or False, 'city': address and address.city or False, diff --git a/addons/crm/board_crm_view.xml b/addons/crm/board_crm_view.xml index 8d789d43652..1e71e5f9cc1 100644 --- a/addons/crm/board_crm_view.xml +++ b/addons/crm/board_crm_view.xml @@ -19,8 +19,11 @@ form graph,tree,form - [('probability', 'not in', (0, 100)),('stage_id.sequence','!=',1),('type', '=', 'opportunity')] - {'search_default_Stage':1} + ['|', + '!', '&', ('probability', '=', 100), ('stage_id.on_change', '=', 1), + '!', '&', ('probability', '=', 0), ('stage_id.sequence', '!=', 1), + ('type', '=', 'opportunity')] + {'search_default_Stage': 1} @@ -43,8 +46,8 @@ form graph,tree,form - [('probability', '=', '0'), ('stage_id.sequence', '!=', 1),('opening_date','>',context_today().strftime("%Y-%m-%d"))] - {'search_default_Stage':1} + ['!', '&', ('probability', '=', 0), ('stage_id.sequence', '!=', 1)] + {'search_default_user': 1, 'search_default_Stage': 1} diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 83ef62f587e..04a17b9dbc0 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -26,14 +26,6 @@ from openerp import tools from openerp.osv import fields from openerp.osv import osv -AVAILABLE_STATES = [ - ('draft', 'New'), - ('cancel', 'Cancelled'), - ('open', 'In Progress'), - ('pending', 'Pending'), - ('done', 'Closed') -] - AVAILABLE_PRIORITIES = [ ('1', 'Highest'), ('2', 'High'), diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 80e1e752089..7c7dcfe79a9 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-today OpenERP SA () +# Copyright (C) 2004-Today OpenERP SA () # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,18 +19,18 @@ # ############################################################################## -from openerp.addons.base_status.base_stage import base_stage -import crm from datetime import datetime from operator import itemgetter -from openerp.osv import fields, osv, orm import time + from openerp import SUPERUSER_ID from openerp import tools -from openerp.tools.translate import _ -from openerp.tools import html2plaintext - +from openerp.addons.crm import crm +from openerp.addons.base_status.base_stage import base_stage from openerp.addons.base.res.res_partner import format_address +from openerp.osv import fields, osv, orm +from openerp.tools import html2plaintext +from openerp.tools.translate import _ CRM_LEAD_FIELDS_TO_MERGE = ['name', 'partner_id', @@ -74,8 +74,8 @@ class crm_lead(base_stage, format_address, osv.osv): _track = { 'stage_id': { '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_stage': lambda self, cr, uid, obj, ctx=None: (obj.stage_id and obj.stage_id.sequence != 1) and obj.probability < 100, + 'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj.probability == 100 and obj.stage_id and obj.stage_id.on_change, 'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.sequence != 1, } } @@ -321,25 +321,6 @@ class crm_lead(base_stage, format_address, osv.osv): 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} - 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 to the ones user_id is member of. """ @@ -353,12 +334,12 @@ class crm_lead(base_stage, format_address, osv.osv): def _check(self, cr, uid, ids=False, context=None): """ Override of the base.stage method. Function called by the scheduler to process cases for date actions - Only works on not won and lost cases. + Avoid won cases """ cr.execute('select * from crm_case \ where (date_action_last<%s or date_action_last is null) \ and (date_action_next<=%s or date_action_next is null) \ - and probability not in (0,100)', + and probability not in (100)', (time.strftime("%Y-%m-%d %H:%M:%S"), time.strftime('%Y-%m-%d %H:%M:%S'))) @@ -413,9 +394,10 @@ class crm_lead(base_stage, format_address, osv.osv): if stage_id: self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context) else: - raise osv.except_osv(_('Warning!'), _('To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n' - 'probability = 0 %, select "Change Probability Automatically".\n' - 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.')) + raise osv.except_osv(_('Warning!'), + _('To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n' + 'probability = 0 %, select "Change Probability Automatically".\n' + 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.')) return True def case_mark_won(self, cr, uid, ids, context=None): @@ -425,25 +407,26 @@ class crm_lead(base_stage, format_address, osv.osv): if stage_id: self.case_set(cr, uid, [lead.id], new_stage_id=stage_id, context=context) else: - raise osv.except_osv(_('Warning!'), _('To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n' - 'probability = 100 % and select "Change Probability Automatically".\n' - 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.')) + raise osv.except_osv(_('Warning!'), + _('To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n' + 'probability = 100 % and select "Change Probability Automatically".\n' + 'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.')) return True - def set_priority(self, cr, uid, ids, priority): + def set_priority(self, cr, uid, ids, priority, context=None): """ Set lead priority """ - return self.write(cr, uid, ids, {'priority': priority}) + return self.write(cr, uid, ids, {'priority': priority}, context=context) def set_high_priority(self, cr, uid, ids, context=None): """ Set lead priority to high """ - return self.set_priority(cr, uid, ids, '1') + return self.set_priority(cr, uid, ids, '1', context=context) def set_normal_priority(self, cr, uid, ids, context=None): """ Set lead priority to normal """ - return self.set_priority(cr, uid, ids, '3') + return self.set_priority(cr, uid, ids, '3', context=context) def _merge_get_result_type(self, cr, uid, opps, context=None): """ @@ -619,7 +602,7 @@ class crm_lead(base_stage, format_address, osv.osv): sequenced_opps = [] for opportunity in opportunities: sequence = -1 - if opportunity.stage_id and (opportunity.probability == 0 and opportunity.stage_id and opportunity.stage_id.sequence != 1): + if opportunity.probability == 0 and opportunity.stage_id and opportunity.stage_id.sequence != 1: sequence = opportunity.stage_id.sequence sequenced_opps.append(((int(sequence != -1 and opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity)) @@ -751,10 +734,7 @@ class crm_lead(base_stage, format_address, osv.osv): res_partner = self.pool.get('res.partner') if partner_id: res_partner.write(cr, uid, partner_id, {'section_id': lead.section_id and lead.section_id.id or False}) - contact_id = res_partner.address_get(cr, uid, [partner_id])['default'] res = lead.write({'partner_id': partner_id}, context=context) - message = _("Partner set to %s." % (lead.partner_id.name)) - self.message_post(cr, uid, [lead.id], body=message, context=context) return res def handle_partner_assignation(self, cr, uid, ids, action='create', partner_id=False, context=None): @@ -894,7 +874,7 @@ class crm_lead(base_stage, format_address, osv.osv): res['context'] = { 'default_opportunity_id': opportunity.id, 'default_partner_id': opportunity.partner_id and opportunity.partner_id.id or False, - 'default_partner_ids' : opportunity.partner_id and [opportunity.partner_id.id] or False, + 'default_partner_ids': opportunity.partner_id and [opportunity.partner_id.id] or False, 'default_user_id': uid, 'default_section_id': opportunity.section_id and opportunity.section_id.id or False, 'default_email_from': opportunity.email_from, @@ -903,14 +883,11 @@ class crm_lead(base_stage, format_address, osv.osv): return res def write(self, cr, uid, ids, vals, context=None): - stage_pool=self.pool.get('crm.case.stage') if vals.get('stage_id') and not vals.get('probability'): # change probability of lead(s) if required by stage - stage = stage_pool.browse(cr, uid, vals['stage_id'], context=context) + stage = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context) if stage.on_change: vals['probability'] = stage.probability - if vals.get('probability') == 100: - vals['stage_id'] = stage_pool.search(cr, uid, [('probability','=',100.0)],order='sequence')[0] return super(crm_lead, self).write(cr, uid, ids, vals, context=context) def new_mail_send(self, cr, uid, ids, context=None): diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index 0a3ff083671..f6adf2b6071 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -1,7 +1,7 @@ - - + + New diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 08d7b331dca..3b18bebb92f 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -116,7 +116,7 @@ diff --git a/addons/crm/report/crm_lead_report.py b/addons/crm/report/crm_lead_report.py index 2fa29070ed7..3faf6fb5f00 100644 --- a/addons/crm/report/crm_lead_report.py +++ b/addons/crm/report/crm_lead_report.py @@ -19,9 +19,9 @@ # ############################################################################## -from openerp.osv import fields,osv +from openerp.osv import fields, osv from openerp import tools -from .. import crm +from openerp.addons.crm import crm MONTHS = [ ('01', 'January'), @@ -71,7 +71,6 @@ 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), '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), @@ -86,10 +85,7 @@ class crm_lead_report(osv.osv): ('opportunity','Opportunity'), ],'Type', help="Type is used to separate Leads and Opportunities"), } - - - - + def init(self, cr): """ @@ -128,7 +124,7 @@ class crm_lead_report(osv.osv): c.planned_revenue*(c.probability/100) as probable_revenue, 1 as nbr, date_trunc('day',c.create_date) as create_date, - extract('epoch' from (c.write_date-c.create_date))/(3600*24) as delay_close, + extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close, abs(extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24)) as delay_expected, extract('epoch' from (c.date_open-c.create_date))/(3600*24) as delay_open FROM diff --git a/addons/crm/report/crm_lead_report_view.xml b/addons/crm/report/crm_lead_report_view.xml index 23ad8065de2..0dd6365360c 100644 --- a/addons/crm/report/crm_lead_report_view.xml +++ b/addons/crm/report/crm_lead_report_view.xml @@ -13,7 +13,6 @@ - @@ -69,10 +68,12 @@ - - - - + + + @@ -131,7 +132,6 @@ crm.lead.report.tree crm.lead.report - @@ -142,7 +142,6 @@ - diff --git a/addons/crm/report/crm_phonecall_report.py b/addons/crm/report/crm_phonecall_report.py index dd8d2f0167d..636d4f9b2b7 100644 --- a/addons/crm/report/crm_phonecall_report.py +++ b/addons/crm/report/crm_phonecall_report.py @@ -19,10 +19,17 @@ # ############################################################################## -from openerp.osv import fields,osv from openerp import tools -from .. import crm +from openerp.addons.crm import crm +from openerp.osv import fields, osv +AVAILABLE_STATES = [ + ('draft', 'Draft'), + ('open', 'Todo'), + ('cancel', 'Cancelled'), + ('done', 'Held'), + ('pending', 'Pending') +] class crm_phonecall_report(osv.osv): """ Phone calls by user and section """ @@ -30,13 +37,14 @@ class crm_phonecall_report(osv.osv): _name = "crm.phonecall.report" _description = "Phone calls by user and section" _auto = False - + _columns = { 'name': fields.char('Year', size=64, required=False, readonly=True), 'user_id':fields.many2one('res.users', 'User', readonly=True), '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), 'month':fields.selection([('01', 'January'), ('02', 'February'), \ ('03', 'March'), ('04', 'April'),\ ('05', 'May'), ('06', 'June'), \ diff --git a/addons/crm/report/crm_phonecall_report_view.xml b/addons/crm/report/crm_phonecall_report_view.xml index 21cf0819c68..52ecd2d13b3 100644 --- a/addons/crm/report/crm_phonecall_report_view.xml +++ b/addons/crm/report/crm_phonecall_report_view.xml @@ -17,7 +17,7 @@ - + @@ -35,7 +35,7 @@ crm.phonecall.report - + @@ -49,12 +49,12 @@ crm.phonecall.report - + help="Phone calls which are in pending state"/> @@ -76,7 +76,7 @@ - + diff --git a/addons/crm_helpdesk/crm_helpdesk.py b/addons/crm_helpdesk/crm_helpdesk.py index 2d0383962b1..543a2a841ad 100644 --- a/addons/crm_helpdesk/crm_helpdesk.py +++ b/addons/crm_helpdesk/crm_helpdesk.py @@ -27,11 +27,14 @@ from openerp import tools from openerp.tools.translate import _ from openerp.tools import html2plaintext -CRM_HELPDESK_STATES = ( - crm.AVAILABLE_STATES[2][0], # Cancelled - crm.AVAILABLE_STATES[3][0], # Done - crm.AVAILABLE_STATES[4][0], # Pending -) +AVAILABLE_STATES = [ + ('draft', 'New'), + ('cancel', 'Cancelled'), + ('open', 'In Progress'), + ('pending', 'Pending'), + ('done', 'Closed') +] + class crm_helpdesk(base_state, base_stage, osv.osv): """ Helpdesk Cases """ @@ -71,7 +74,7 @@ class crm_helpdesk(base_state, base_stage, osv.osv): domain="['|',('section_id','=',False),('section_id','=',section_id),\ ('object_id.model', '=', 'crm.helpdesk')]"), 'duration': fields.float('Duration', states={'done': [('readonly', True)]}), - 'state': fields.selection(crm.AVAILABLE_STATES, 'Status', size=16, readonly=True, + 'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True, help='The status is set to \'Draft\', when a case is created.\ \nIf the case is in progress the status is set to \'Open\'.\ \nWhen the case is over, the status is set to \'Done\'.\