<commit_before># -*- coding: utf-8 -*-
##############################################################################
#    
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
#
##############################################################################

from mx.DateTime import now

import wizard
import netsvc
import ir
import pooler
from tools.translate import _

class lead2opportunity(wizard.interface):

    partner_form = """<?xml version="1.0"?>
    <form string="Convert To Partner">
        <label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
        <label string="You may have to verify that this partner does not exist already." colspan="4"/>
        <newline />
        <field name="action"/>
        <group attrs="{'invisible':[('action','=','create')]}">
            <field name="partner_id" attrs="{'required':[('action','=','exist')]}"/>
        </group>
    </form>"""

    partner_fields = {
        'action': {'type':'selection',
                'selection':[('exist','Link to an existing partner'),('create','Create a new partner')],
                'string':'Action', 'required':True, 'default': lambda *a:'create'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    case_form = """<?xml version="1.0"?>
    <form string="Convert To Opportunity">
        <field name="name"/>
        <field name="partner_id"/>
        <newline/>
        <field name="planned_revenue"/>
        <field name="probability"/>
    </form>"""

    case_fields = {
        'name': {'type':'char', 'size':64, 'string':'Opportunity Summary', 'required':True},
        'planned_revenue': {'type':'float', 'digits':(16,2), 'string': 'Expected Revenue'},
        'probability': {'type':'float', 'digits':(16,2), 'string': 'Success Probability'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    def _selectopportunity(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.lead')
        for case in case_obj.browse(cr, uid, data['ids']):
            if not case.partner_id:
                return 'create_partner'
        return {'name': case.name, 'probability': case.probability or 20.0,
                'planned_revenue':case.planned_revenue, 'partner_id':case.partner_id.id}

    def _selectChoice(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.lead')
        for case in case_obj.browse(cr, uid, data['ids']):
            if not case.partner_id:
                return 'create_partner'
        return 'opportunity'

    def _makeOrder(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        data_obj = pool.get('ir.model.data')
        result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
        res = data_obj.read(cr, uid, result, ['res_id'])
        

        id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
        id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
        if id2:
            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
        if id3:
            id3 = data_obj.browse(cr, uid, id3, context=context).res_id

        lead_case_obj = pool.get('crm.lead')
        opportunity_case_obj = pool.get('crm.opportunity')        
        for lead in lead_case_obj.browse(cr, uid, data['ids']):
            #TODO : Take other info from lead       
            new_opportunity_id = opportunity_case_obj.create(cr, uid, {            
                'name': data['form']['name'],
                'planned_revenue': data['form']['planned_revenue'],
                'probability': data['form']['probability'],
                'partner_id': data['form']['partner_id'],
                'section_id':lead.section_id.id,
                'description':lead.description,
            })       
            
            new_opportunity = opportunity_case_obj.browse(cr, uid, new_opportunity_id)
            
            vals = {
                'partner_id': data['form']['partner_id'],                
                }
            if not lead.opportunity_id:
                vals.update({'opportunity_id' : new_opportunity.id})

            lead_case_obj.write(cr, uid, [lead.id], vals)
            lead_case_obj.case_cancel(cr, uid, [lead.id])
            opportunity_case_obj.case_open(cr, uid, [new_opportunity_id])
        <commit_msg>[IMP]CRM: add the field lead2opportunity<commit_after># -*- coding: utf-8 -*-
##############################################################################
#    
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
#
##############################################################################

from mx.DateTime import now

import wizard
import netsvc
import ir
import pooler
from tools.translate import _

class lead2opportunity(wizard.interface):

    partner_form = """<?xml version="1.0"?>
    <form string="Convert To Partner">
        <label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
        <label string="You may have to verify that this partner does not exist already." colspan="4"/>
        <newline />
        <field name="action"/>
        <group attrs="{'invisible':[('action','=','create')]}">
            <field name="partner_id" attrs="{'required':[('action','=','exist')]}"/>
        </group>
    </form>"""

    partner_fields = {
        'action': {'type':'selection',
                'selection':[('exist','Link to an existing partner'),('create','Create a new partner')],
                'string':'Action', 'required':True, 'default': lambda *a:'create'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    case_form = """<?xml version="1.0"?>
    <form string="Convert To Opportunity">
        <field name="name"/>
        <field name="partner_id"/>
        <newline/>
        <field name="planned_revenue"/>
        <field name="probability"/>
    </form>"""

    case_fields = {
        'name': {'type':'char', 'size':64, 'string':'Opportunity Summary', 'required':True},
        'planned_revenue': {'type':'float', 'digits':(16,2), 'string': 'Expected Revenue'},
        'probability': {'type':'float', 'digits':(16,2), 'string': 'Success Probability'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    def _selectopportunity(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.lead')
        for case in case_obj.browse(cr, uid, data['ids']):
            if not case.partner_id:
                return 'create_partner'
        return {'name': case.name, 'probability': case.probability or 20.0,
                'planned_revenue':case.planned_revenue, 'partner_id':case.partner_id.id}

    def _selectChoice(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.lead')
        for case in case_obj.browse(cr, uid, data['ids']):
            if not case.partner_id:
                return 'create_partner'
        return 'opportunity'

    def _makeOrder(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        data_obj = pool.get('ir.model.data')
        result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
        res = data_obj.read(cr, uid, result, ['res_id'])
        

        id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
        id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
        if id2:
            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
        if id3:
            id3 = data_obj.browse(cr, uid, id3, context=context).res_id

        lead_case_obj = pool.get('crm.lead')
        opportunity_case_obj = pool.get('crm.opportunity')        
        for lead in lead_case_obj.browse(cr, uid, data['ids']):
            #TODO : Take other info from lead       
            new_opportunity_id = opportunity_case_obj.create(cr, uid, {            
                'name': data['form']['name'],
                'planned_revenue': data['form']['planned_revenue'],
                'probability': data['form']['probability'],
                'partner_id': data['form']['partner_id'],
                'section_id':lead.section_id.id,
                'description':lead.description,
                'partner_address_id':lead.partner_address_id.id, 
                'priority':lead.priority,         
            })       
            
            new_opportunity = opportunity_case_obj.browse(cr, uid, new_opportunity_id)
            
            vals = {
                'partner_id': data['form']['partner_id'],                
                }
            if not lead.opportunity_id:
                vals.update({'opportunity_id' : new_opportunity.id})

            lead_case_obj.write(cr, uid, [lead.id], vals)
            lead_case_obj.case_cancel(cr, uid, [lead.id])
            opportunity_case_obj.case_open(cr, uid, [new_opportunity_id])
        
{'fraction_non_alphanumeric': 0.16729323308270677, 'fraction_numerical': 0.007236842105263158, 'mean_word_length': 2.6769177608845887, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 4, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4315186', 'n_tokens_mistral': 3308, 'n_tokens_neox': 3112, 'n_words': 780}