Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][IMP] product_customerinfo: Allow searching product templates by customer info #1912

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

carlos-lopez-tecnativa
Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa commented Mar 10, 2025

Now, in the sale order, the product template is displayed by default. This update adds the ability to search for product templates using customer info.

Reference: odoo/odoo#155449

TT54233
@Tecnativa @pedrobaeza @victoralmau could you please review this.

@OCA-git-bot
Copy link
Contributor

Hi @luisg123v,
some modules you are maintaining are being modified, check this out!


@api.model
def name_search(self, name, args=None, operator="ilike", limit=100):
res = super().name_search(name, args=args, operator=operator, limit=limit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should control the extra search by a context key activated in the sales order, and give priority to the result of product.customerinfo records. How is this handled in purchase by core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In purchase.order, the partner_id is passed by context, similar to how it is done in sale.order.

In this module, when searching for product.product, the name_search does not expect any specific context(just partner_id). For product.template, it follows the same logic as product.product. What exactly needs to be changed? Please provide more details.

product.product

def name_search(self, name, args=None, operator="ilike", limit=100):
res = super().name_search(name, args=args, operator=operator, limit=limit)
res_ids_len = len(res)
if (
not name
and limit
or not self._context.get("partner_id")
or res_ids_len >= limit
):
return res
limit -= res_ids_len
supplier_domain = [
("partner_id", "=", self._context.get("partner_id")),
"|",
("product_code", operator, name),
("product_name", operator, name),
]
match_domain = [("product_tmpl_id.customer_ids", "any", supplier_domain)]
products = self.search_fetch(
expression.AND([args or [], match_domain]), ["display_name"], limit=limit
)
return res + [(product.id, product.display_name) for product in products.sudo()]

product.template
https://github.com/Tecnativa/product-attribute/blob/0b2668128d84949bff76d553e0f4d93fb7e8dfb4/product_customerinfo/models/product_template.py#L95-L96

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see the context key. It seems enough.

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can part of this code reused in product.product for not duplicating it?

…omer info

Now, in the sale order, the product template is displayed by default. This update adds the ability to search for product templates using customer info.

Reference: odoo/odoo#155449
@carlos-lopez-tecnativa carlos-lopez-tecnativa force-pushed the 18.0-product_customerinfo-name-search branch from 0b26681 to 544a7bf Compare March 10, 2025 17:48
@carlos-lopez-tecnativa
Copy link
Contributor Author

Can part of this code reused in product.product for not duplicating it?

Note that both name_search implementations are different in terms of the fields used: product.product relies on product_tmpl_id.customer_ids, while product.template uses customer_ids. I don’t believe it is necessary to create a new AbstractModel here. Please let me know if this solution is sufficient or if the abstract model is needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants