-
-
Notifications
You must be signed in to change notification settings - Fork 723
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
base: 18.0
Are you sure you want to change the base?
[18.0][IMP] product_customerinfo: Allow searching product templates by customer info #1912
Conversation
Hi @luisg123v, |
|
||
@api.model | ||
def name_search(self, name, args=None, operator="ilike", limit=100): | ||
res = super().name_search(name, args=args, operator=operator, limit=limit) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
product-attribute/product_customerinfo/models/product_product.py
Lines 20 to 41 in 0f082a3
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
0b26681
to
544a7bf
Compare
Note that both |
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.