Odoo Help


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.


How can I check if the field value from one model exist in the field value of another model?

John Baldwin
on 1/16/15, 5:26 AM 934 views

I want to create a Do Not Call list. When a customer phone number from res.partner or crm.lead is entered, I want to trigger an onchage event that checks a third model (dnc.numbers) to see if that value exist in the field "numbers" and if it exists raise an alert.

I've created dnc.numbers with the field numbers:

class dnc_numbers(models.Model):
    _name = 'dnc.numbers'
    numbers = fields.Char('Numbers')

And have the field 'phone' to compare against in res.partner and crm.lead, but don't know how to compare?

I've also created a DNC boolean in respartner that will hide the 'phone' field when checked and would like it to also add the phone number to the dnc.numbers number list on_change when changed to True or remove it on_change when changed to False.

I'm sure this is probably easy, but I'm lost. 



| 5 3 6
Jakarta, Indonesia
On 1/16/15, 5:57 AM

I am not well versed with the new API.  So, please take my answer with a grain of salt.  What you can do is to basically perform a query in the on_change to search if the 'phone' of the res.partner is in the 'dnc.numbers' models.  You can do a raw SQL query or, I believe, you can also invoke the name_search() method of the model if you set the attribute _name = 'numbers' for 'dnc.numbers', or the search() method of the model for a greater flexibility.

That's where I'm lost... no idea what that code should look like. Thanks for the answer though.

John Baldwin
on 1/16/15, 1:42 PM

Most of v8 code are still based on old APIs. You might want to try to develop it using the old APIs if you are familiar with it. The Account Invoice model in account module (/homeaddons/account/account_invoice.py) is one of the handful files that have been refactored to use v8 API. There are also samples of code there that execute raw SQL and inherited name_search as well.

on 1/20/15, 6:40 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)


Asked: 1/16/15, 5:26 AM
Seen: 934 times
Last updated: 3/16/15, 8:10 AM