Odoo Help

1

Override Wizard Function [SOLVED]

By
Mirco Strizzi
on 12/14/15, 9:41 AM 1,247 views

I'm trying to override  _find_matching_partner function in crm_partner_bind.py, so i have created a inherit class:

but only super class are called. What is it wrong ? 

from openerp.osv import fields, osv
from openerp.tools.translate import _
class crm_partner_binding(osv.osv_memory):
    """
    Handle the partner binding or generation in any CRM wizard that requires
    such feature, like the lead2opportunity wizard, or the
    phonecall2opportunity wizard.  Try to find a matching partner from the
    CRM model's information (name, email, phone number, etc) or create a new
    one on the fly.
    Use it like a mixin with the wizard of your choice.
    """
    _inherit = 'crm.partner.binding'
    _description = 'Handle partner binding or generation in CRM wizards.'
    """
    _columns = {
        'action': fields.selection([
                ('create', 'Create a new customer'),
                ('nothing', 'Do not link to a customer')
            ], 'Related Customer', required=True),
        'partner_id': fields.many2one('res.partner', 'Customer'),
    }
    """
    def _find_matching_partner(self, cr, uid, context=None):
        """
        Try to find a matching partner regarding the active model data, like
        the customer's name, email, phone number, etc.
        :return int partner_id if any, False otherwise
        """
        set_trace()
        if context is None:

     context = {}

        partner_id = False         partner_obj = self.pool.get('res.partner')         # The active model has to be a lead or a phonecall

        if (context.get('active_model') == 'crm.lead') and context.get('active_id'):

            active_model = self.pool.get('crm.lead').browse(cr, uid, context.get('active_id'), context=context)

        elif (context.get('active_model') == 'crm.phonecall') and context.get('active_id'):

            active_model = self.pool.get('crm.phonecall').browse(cr, uid, context.get('active_id'), context=context)         # Find the best matching partner for the active model

        if (active_model):

            partner_obj = self.pool.get('res.partner')

            # A partner is set already

            if active_model.partner_id:

                partner_id = active_model.partner_id.id

            # Search through the existing partners based on the lead's email

            elif active_model.email_from:                partner_ids = partner_obj.search(cr, uid, [('email', '=', active_model.email_from)], context=context)

                if partner_ids:

                    partner_id = partner_ids[0]

            # Check x_datanascita

            elif active_model.x_datanascita:

                partner_ids = partner_obj.search(cr, uid, [('x_datanascita', '=', active_model.x_datanascita)], context=context)

                if partner_ids:

                    partner_id = partner_ids[0]

            # Search through the existing partners based on the lead's partner or contact name

            elif active_model.partner_name:

                partner_ids = partner_obj.search(cr, uid, [('name', 'ilike', '%'+active_model.partner_name+'%')], context=context)

                if partner_ids:

                    partner_id = partner_ids[0]

            elif active_model.contact_name:

                partner_ids = partner_obj.search(cr, uid, [

                        ('name', 'ilike', '%'+active_model.contact_name+'%')], context=context)

                if partner_ids:

                    partner_id = partner_ids[0]

        return super(crm_partner_binding, self)._find_matching_partner(cr,uid,context=context)

0
Mirco Strizzi
On 12/14/15, 1:01 PM

I needed to override CRM_leadto_opportunity 

0
Axel Mendoza
On 12/14/15, 10:03 AM

Hi @Mirco Strizzi
Check the depends with crm in your module __openerp__.py

i added depends yet.

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/14/15, 10:12 AM

And restarted the server and update module list before test it again?

Axel Mendoza
on 12/14/15, 10:17 AM

I already done this step before write questions on fourm

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/14/15, 10:41 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 12/14/15, 9:41 AM
Seen: 1247 times
Last updated: 3/2/16, 6:23 AM