Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
9045 Weergaven

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. 

Avatar
Annuleer
Beste antwoord

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.

Avatar
Annuleer
Auteur

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

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.