-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
[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()] |
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 |
# prefetch the fields used by the `display_name` | ||
domain = [ | ||
("product_tmpl_id", "in", product_template_ids), | ||
("product_id", "=", False), |
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 this should not be product_id=false or if you define a specific record for a variant it does not work correctly, right?
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.
When creating a record from product.product
or product.template
, the product_id
field is always empty by default. It is only set when the user explicitly selects a variant in this field. In such cases, the customer info should be linked specifically to that variant. Therefore, from my perspective, it is correct that this record is not considered here.
- Changed invisible to column_invisible in list views. - Show or hide product_id and product_template_id depending on whether the view is for product.template or product.product. - Created a specific view for product.product to pass default values via context to product_tmpl_id and prevent errors when passing an ID from product.product to product.template. - Removed group="base.group_multi_company" from product_tmpl_id as it was incorrectly applied.
/ocabot merge minor |
What a great day to merge this nice PR. Let's do it! |
Congratulations, your PR was merged at 3951d49. Thanks a lot for contributing to OCA. ❤️ |
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.