<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 partner_create(wizard.interface):

    case_form = """<?xml version="1.0"?>
    <form string="Create a Partner">
        <label string="Are you sure you want to create a partner based on this phonecall ?" colspan="4"/>
        <label string="You may have to verify that this partner does not exist already." colspan="4"/>
        <!--field name="close"/-->
    </form>"""

    case_fields = {
        'close': {'type':'boolean', 'string':'Close Phonecall'}
    }

    partner_form = """<?xml version="1.0"?>
    <form string="Create a 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','!=','exist')]}">
            <field name="partner_id"/>
        </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:'exist'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    def _selectPartner(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.phonecall')
        for case in case_obj.browse(cr, uid, data['ids']):
            if case.partner_id:
                raise wizard.except_wizard(_('Warning !'),
                    _('A partner is already defined on this phonecall.'))                        
        return {}

    def _create_partner(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)        
        case_obj = pool.get('crm.phonecall')
        partner_obj = pool.get('res.partner')
        contact_obj = pool.get('res.partner.address')
        partner_ids = []
        partner_id = False
        contact_id = False
        for case in case_obj.browse(cr, uid, data['ids']):
            if data['form']['action'] == 'create':
                partner_id = partner_obj.create(cr, uid, {
                    'name': case.partner_name or case.name,
                    'user_id': case.user_id.id,
                    'comment': case.description,
                })
                contact_id = contact_obj.create(cr, uid, {
                    'partner_id': partner_id,
                    'name': case.name,
                    'phone': case.phone,
                    'mobile': case.mobile,
                    'email': case.email_from
                })

            else:
                if data['form']['partner_id']:
                    partner = partner_obj.browse(cr,uid,data['form']['partner_id'])
                    partner_id = partner.id
                    contact_id = partner.address and partner.address[0].id

            partner_ids.append(partner_id)
            vals = {}
            if partner_id:
                vals.update({'partner_id': partner_id})
            if contact_id:
                vals.update({'partner_address_id': contact_id})
            case_obj.write(cr, uid, [case.id], vals)   
        return partner_ids

    def _make_partner(self, cr, uid, data, context): 
        pool = pooler.get_pool(cr.dbname)             
        partner_ids = self._create_partner(cr, uid, data, context)
        mod_obj = pool.get('ir.model.data') 
        result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
        res = mod_obj.read(cr, uid, result, ['res_id'])
        value = {
            'domain': "[]",
            'view_type': 'form',
            'view_mode': 'form,tree',
            'res_model': 'res.partner',
            'res_id': partner_ids and int(partner_ids[0]) or False,<commit_msg>[Fix] crm: Fix the problem of crm_phonecall_wizard<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 partner_create(wizard.interface):

    case_form = """<?xml version="1.0"?>
    <form string="Create a Partner">
        <label string="Are you sure you want to create a partner based on this phonecall ?" colspan="4"/>
        <label string="You may have to verify that this partner does not exist already." colspan="4"/>
        <!--field name="close"/-->
    </form>"""

    case_fields = {
        'close': {'type':'boolean', 'string':'Close Phonecall'}
    }

    partner_form = """<?xml version="1.0"?>
    <form string="Create a 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','!=','exist')]}">
            <field name="partner_id"/>
        </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:'exist'},
        'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
    }

    def _selectPartner(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)
        case_obj = pool.get('crm.phonecall')
        for case in case_obj.browse(cr, uid, data['ids']):
            if case.partner_id:
                raise wizard.except_wizard(_('Warning !'),
                    _('A partner is already defined on this phonecall.'))                        
        return {}

    def _create_partner(self, cr, uid, data, context):
        pool = pooler.get_pool(cr.dbname)        
        case_obj = pool.get('crm.phonecall')
        partner_obj = pool.get('res.partner')
        contact_obj = pool.get('res.partner.address')
        partner_ids = []
        partner_id = False
        contact_id = False
        for case in case_obj.browse(cr, uid, data['ids']):
            if data['form']['action'] == 'create':
                partner_id = partner_obj.create(cr, uid, {
                    'name': case.partner_contact or case.name,
                    'user_id': case.user_id.id,
                    'comment': case.description,
                })
                contact_id = contact_obj.create(cr, uid, {
                    'partner_id': partner_id,
                    'name': case.name,
                    'phone': case.partner_phone,
                    'mobile': case.partner_mobile,
                    'email': case.email_from
                })

            else:
                if data['form']['partner_id']:
                    partner = partner_obj.browse(cr,uid,data['form']['partner_id'])
                    partner_id = partner.id
                    contact_id = partner.address and partner.address[0].id

            partner_ids.append(partner_id)
            vals = {}
            if partner_id:
                vals.update({'partner_id': partner_id})
            if contact_id:
                vals.update({'partner_address_id': contact_id})
            case_obj.write(cr, uid, [case.id], vals)   
        return partner_ids

    def _make_partner(self, cr, uid, data, context): 
        pool = pooler.get_pool(cr.dbname)             
        partner_ids = self._create_partner(cr, uid, data, context)
        mod_obj = pool.get('ir.model.data') 
        result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
        res = mod_obj.read(cr, uid, result, ['res_id'])
        value = {
            'domain': "[]",
            'view_type': 'form',
            'view_mode': 'form,tree',
            'res_model': 'res.partner',
            'res_id': partner_ids and int(partner_ids[0]) or False,
{'fraction_non_alphanumeric': 0.1564441771898176, 'fraction_numerical': 0.004209260372820205, 'mean_word_length': 2.2664484451718496, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 4, '>': 39, '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': '1071001', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2746, 'n_words': 783}