Contributors mailing list archives
contributors@odoo-community.org
Browse archives
Re: [Odoo CE 17.0] Help needed with client search on budgets
Re: [Odoo CE 17.0] Help needed with client search on budgets
Re: [Odoo CE 17.0] Help needed with client search on budgets
byI have seen your message right now, and I would like to thank you so much for not only your answer, but also for you writing the code I should do. I do not know how could I pay you back this favor that you have done for me.
El 20/11/2024 0:02 CET Francesco Ballerini <notifications@odoo-community.org> escribió:I apologize, it is now clear to me also that you need both the search from a custom field and the way the name is displayed, but the search is indeed prioritized.As Daniel and Xavier pointed out, in Odoo 17.0 you can already submit the "ref" field (field label on GUI is "Reference") and get the right record. E.g. if you have a contact named John Doe with Reference set on "ab-001" and you search for "ab-001" in the contacts search or dropdown you will fetch John Doe.You could migrate your "x_cliente_interno" data into the "ref" field, and this would automatically unlock the search feature. However if you need to keep this data in a specific custom field you will need to override _name_search() method.In every case you will also need to override _compute_display_name if you want to also show the code before the field. I provided a couple of snippet below (just as an example, especially the _name_search override needs to be refined).Let me point out another thing: from the field name I assume you are using a field defined from GUI, unfortunately it's not recommended to use those kind of fields in python methods as it will easily lead to inconsistencies and bugs (e.g. if you delete field from db and not remove it from python methods..). This means that if you want to use a custom field in _name_search() override you should migrate data to a standard field aniway.
This is an example of what you might do on a custom module. As you can see the _name_search() implementation has to be refined while the_compute_display_name method will work as is.If you decide to migrate data into the "ref" field you can only implement _compute_display_name by replacing "cliente_interno" with "ref" and you do not need to implement _name_search() in this case.from odoo import models, fields, apifrom odoo.osv import expression
class ResPartner(models.Model):_inherit = "res.partner"
cliente_interno = fields.Char() # use a standard field for consistency
@api.depends("name", "cliente_interno")def _compute_display_name(self):"""Show reference code before partner name"""super()._compute_display_name()for partner in self:name = partner.name or "unknown"cliente_interno = f"[{partner.cliente_interno}] " if partner.cliente_interno else ""# !! Disclaimer !!#I f you copy this code and change it DO NOT ASSIGN the value of partner.name,# that would compromise your datas. Only re-assign partner.display_namepartner.display_name = cliente_interno + name
@api.modeldef _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):"""Add custom field `cliente_interno` to the search domain"""domain = expression.OR([domain or [], [("cliente_interno", operator, name)]])# this doesn't work properly, it seems like the domain we pass gets overridden,# might take this as example and adjust by debugging/find more examples on source codereturn super()._name_search(name, domain=domain, operator=operator, limit=limit, order=order)Regards--FrancescoIl giorno mar 19 nov 2024 alle ore 14:13 Daniel Reis <notifications@odoo-community.org> ha scritto:From your description, it feels like this is already available in standard Odoo:
The "ref" field is to be used for Client codes
The code is no longer presented in front of the name.
I think an OCA module is needed to bring that feature back.
/Daniel
On 19/11/2024 09:22, Redes Sociales JLBBERP wrote:Hello everyone,I am writing this message because I need assistance with modifying how searching a client while doing a budget works.What I am trying to do is, instead of searching just by the name, I want it to work like the following: I made a custom field called "x_cliente_interno", which is a number to identify the client, and I would like to make the search work like how product search works: If you write either the product's ID or the product's name, it will show you both fields merged from the data you wrote. Something like this:And when you select it, it shows the data like this:To sum up, what I am trying to do is that when you search a client, the search shows you the field "x_cliente_interno" behind the client name, like this: "[x_cliente_interno] client name" and it should also stay like in the second image when selected.Thanks in advance for the help._______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
--
DANIEL REIS
MANAGING PARTNER>> Schedule time on my calendar.
M: +351 919 991 307
E: dreis@OpenSourceIntegrators.com
A: Avenida da República 3000, Estoril Office Center, 2649-517 Cascais_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
Reference
-
[Odoo CE 17.0] Help needed with client search on budgets
byJose Luis Baños Consulting, S.L.U., Alejandro Párraga Alcázar-
Re: [Odoo CE 17.0] Help needed with client search on budgets
byFrancesco Ballerini -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byJose Luis Baños Consulting, S.L.U., Alejandro Párraga Alcázar -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byJose Luis Baños Consulting, S.L.U., Alejandro Párraga Alcázar -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byHolger Brunn -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byFrancesco Ballerini -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byClosingAp Open Source Integrators Europe, LDA, Daniel Reis -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byFrancesco Ballerini -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byMoaHub, Graeme Gellatly -
Re: [Odoo CE 17.0] Help needed with client search on budgets
byIntero Technologies GmbH, C. Zoellner
-