Odoo Help

Welcome!

This community 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.

1

Override Wizard Function [SOLVED]

By
Mirco Strizzi
on 12/14/15, 9:41 AM 694 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

--Axel Mendoza--
10298
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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