- Mailing Lists
- Contributors
- Re: [Odoo CE 17.0] Help needed with client search on budgets
Archives
- By thread 1419
-
By date
- August 2019 59
- September 2019 118
- October 2019 165
- November 2019 97
- December 2019 35
- January 2020 58
- February 2020 204
- March 2020 121
- April 2020 172
- May 2020 50
- June 2020 158
- July 2020 85
- August 2020 94
- September 2020 193
- October 2020 277
- November 2020 100
- December 2020 159
- January 2021 38
- February 2021 87
- March 2021 146
- April 2021 73
- May 2021 90
- June 2021 86
- July 2021 123
- August 2021 50
- September 2021 68
- October 2021 66
- November 2021 74
- December 2021 75
- January 2022 98
- February 2022 77
- March 2022 68
- April 2022 31
- May 2022 59
- June 2022 87
- July 2022 141
- August 2022 38
- September 2022 73
- October 2022 152
- November 2022 39
- December 2022 50
- January 2023 93
- February 2023 49
- March 2023 106
- April 2023 47
- May 2023 69
- June 2023 92
- July 2023 64
- August 2023 103
- September 2023 91
- October 2023 101
- November 2023 94
- December 2023 46
- January 2024 75
- February 2024 79
- March 2024 104
- April 2024 63
- May 2024 40
- June 2024 160
- July 2024 80
- August 2024 70
- September 2024 62
- October 2024 121
- November 2024 117
- December 2024 89
- January 2025 59
- February 2025 104
- March 2025 96
- April 2025 107
- May 2025 52
- June 2025 72
- July 2025 60
- August 2025 81
- September 2025 124
- October 2025 63
- November 2025 22
Contributors
Re: [Odoo CE 17.0] Help needed with client search on budgets
Hello everyone,after making a custom module with Francescos' code and fixing the search function, I came across a problem related to how the partner is displayed at the sales order form:When searching for a customer, they are displayed with the following format: "[x_cliente_interno] + customer name", which is the exact format I needed. But the problem is that when I select any customer, it doesn't show it's address and neither it's VAT below the customer anymore.Here I send my version of the code from Francesco:from odoo import models, fields, api
class ResPartner(models.Model):_inherit = “res.partner”
x_cliente_interno = fields.Integer() # use a standard field for consistency
@api.depends(“name”, “x_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.x_cliente_interno}] " if partner.x_cliente_interno else ""# !! Disclaimer !!# If 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 # It's replacing the whole field
@api.modeldef _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):“""Add custom field `cliente_interno` to the search domain""”domain = domain or []if name:domain += ['|', '|', ('name', operator, name),('email', operator, name),('x_cliente_interno', '=', name)]return self._search(domain, limit=limit, order=order)I tried fixing it by myself, and even if I wasn't able to, I discovered the field "partner.display_name" is the one causing this problem.Thanks in advance for the help.El 20/11/2024 9:21 CET Redes Sociales JLBBERP <redes_sociales@jlbberp.com> escribió:Hello Francesco,
I 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.I rely on the community because I am in my beginnings and because of everything that my company JLBB ERP has given me through good collaboration, I am now checking it out. Do not doubt that everything I can contribute, you will find me here.Thank you Francesco for the help.Salutations to the community.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![]()
![]()
_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
by Francesco Ballerini - 02:01 - 27 Nov 2024
Reference
-
[Odoo CE 17.0] Help needed with client search on budgets
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.
by Alejandro Párraga Alcázar - 10:21 - 19 Nov 2024-
Re: [Odoo CE 17.0] Help needed with client search on budgets
Hi @Redes Sociales JLBBERPI didn't noticed at first but indeed you're right, thank you for pointing that out.The fact that you see those info about VAT and address is basically due to the field context (defined in XML field definition) which contains key values like 'show_vat': 1. That context is propagated to the python context which will be evaluated in odoo 17 _compute_display_name method.The code I gave you was totally overriding that context evaluation but this issue can be easily avoided by extending the _get_complete_name() hook instead, which is called in the first lines of _compute_display_name and can be extended to add values without overriding the context evaluation part. So I suggest to remove the _compute_display_name() override and replace it with the followingx_cliente_interno = fields.Integer() # use a standard field for consistencydef _get_complete_name(self):"""@override: add `x_cliente_interno` field to the complete name"""complete_name = super()._get_complete_name()cliente_interno = f"[{self.x_cliente_interno}] " if self.x_cliente_interno else ""complete_name_add_cliente_interno = cliente_interno + complete_namereturn complete_name_add_cliente_internoI made a quick test locally and this should be able to fix the issueKindly regards--FrancescoIl giorno mar 26 nov 2024 alle ore 09:47 Redes Sociales JLBBERP <notifications@odoo-community.org> ha scritto:Hello everyone,after making a custom module with Francescos' code and fixing the search function, I came across a problem related to how the partner is displayed at the sales order form:When searching for a customer, they are displayed with the following format: "[x_cliente_interno] + customer name", which is the exact format I needed. But the problem is that when I select any customer, it doesn't show it's address and neither it's VAT below the customer anymore.Here I send my version of the code from Francesco:from odoo import models, fields, api
class ResPartner(models.Model):_inherit = “res.partner”
x_cliente_interno = fields.Integer() # use a standard field for consistency
@api.depends(“name”, “x_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.x_cliente_interno}] " if partner.x_cliente_interno else ""# !! Disclaimer !!# If 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 # It's replacing the whole field
@api.modeldef _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):“""Add custom field `cliente_interno` to the search domain""”domain = domain or []if name:domain += ['|', '|', ('name', operator, name),('email', operator, name),('x_cliente_interno', '=', name)]return self._search(domain, limit=limit, order=order)I tried fixing it by myself, and even if I wasn't able to, I discovered the field "partner.display_name" is the one causing this problem.Thanks in advance for the help.El 20/11/2024 9:21 CET Redes Sociales JLBBERP <redes_sociales@jlbberp.com> escribió:Hello Francesco,
I 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.I rely on the community because I am in my beginnings and because of everything that my company JLBB ERP has given me through good collaboration, I am now checking it out. Do not doubt that everything I can contribute, you will find me here.Thank you Francesco for the help.Salutations to the community.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_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe
by Francesco Ballerini - 02:01 - 27 Nov 2024 -
Re: [Odoo CE 17.0] Help needed with client search on budgets
Hello everyone,after making a custom module with Francescos' code and fixing the search function, I came across a problem related to how the partner is displayed at the sales order form:When searching for a customer, they are displayed with the following format: "[x_cliente_interno] + customer name", which is the exact format I needed. But the problem is that when I select any customer, it doesn't show it's address and neither it's VAT below the customer anymore.Here I send my version of the code from Francesco:from odoo import models, fields, api
class ResPartner(models.Model):_inherit = “res.partner”
x_cliente_interno = fields.Integer() # use a standard field for consistency
@api.depends(“name”, “x_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.x_cliente_interno}] " if partner.x_cliente_interno else ""# !! Disclaimer !!# If 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 # It's replacing the whole field
@api.modeldef _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):“""Add custom field `cliente_interno` to the search domain""”domain = domain or []if name:domain += ['|', '|', ('name', operator, name),('email', operator, name),('x_cliente_interno', '=', name)]return self._search(domain, limit=limit, order=order)I tried fixing it by myself, and even if I wasn't able to, I discovered the field "partner.display_name" is the one causing this problem.Thanks in advance for the help.El 20/11/2024 9:21 CET Redes Sociales JLBBERP <redes_sociales@jlbberp.com> escribió:Hello Francesco,
I 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.I rely on the community because I am in my beginnings and because of everything that my company JLBB ERP has given me through good collaboration, I am now checking it out. Do not doubt that everything I can contribute, you will find me here.Thank you Francesco for the help.Salutations to the community.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
by Alejandro Párraga Alcázar - 09:46 - 26 Nov 2024 -
Re: [Odoo CE 17.0] Help needed with client search on budgets
Hello Francesco,
I 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.I rely on the community because I am in my beginnings and because of everything that my company JLBB ERP has given me through good collaboration, I am now checking it out. Do not doubt that everything I can contribute, you will find me here.Thank you Francesco for the help.Salutations to the community.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
by Alejandro Párraga Alcázar - 09:26 - 20 Nov 2024 -
Re: [Odoo CE 17.0] Help needed with client search on budgets
> 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. anybody interested in only the searching part can use https://apps.odoo.com/apps/modules/16.0/base_name_search_improved without typing any code. The migration to v17 happened in https://github.com/OCA/server-tools/pull/2831 Could be worthwhile to add a companion to this module allowing to configure the display name via UI too. -- Your partner for the hard Odoo problems https://hunki-enterprises.com
by Holger Brunn - 02:55 - 20 Nov 2024 -
Re: [Odoo CE 17.0] Help needed with client search on budgets
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 expressionclass 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
by Francesco Ballerini - 12:00 - 20 Nov 2024
-