-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[IMP] sale_order_product_assortment: performance in so #3467
base: 14.0
Are you sure you want to change the base?
Conversation
Hi @CarlosRoca13, |
Hi @aleuffre, first of all thanks for the changes 😄 can you show a comparison of the times between the current version and after adding these changes? ping @carlosdauden |
Thank you for checking the PR @CarlosRoca13 ! I tried using This is tested on a production database that is having some performance issues, that's why we're doing a performance pass on a handful of modules Before:
After:
To add to this, when pressing "create" from the interface, and the partner is still empty, the new function checks that the partner is not set and is not executed, whereas the old function still performs the full search. |
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.
It seems to be ok 😄
can you review too @carlosdauden @pedrobaeza
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.
LGTM
This commit improves performance when computing the products allowed in a Sales Order, especially when creating an order and the partner is empty
114c716
to
10c5cfc
Compare
Sorry, I made a new change, specifically filters_partner_domain = filters_partner_domain.filtered(
lambda x, partner=partner: partner in x.partner_ids
or partner.filtered_domain(x._get_eval_partner_domain())
) This lets us skip computing |
I need to fix the tests. |
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.
This version does not have the changes applied properly, this backport was made, but it was not quite right:
#3135
as in addition to these changes there were others that did not carry over.
Just take a look at the file in 15.0:
sale-workflow/sale_order_product_assortment/models/sale_order.py
Lines 18 to 38 in ad9d3f6
@api.depends("partner_id", "partner_shipping_id", "partner_invoice_id") | |
def _compute_product_assortment_ids(self): | |
self.allowed_product_ids = False | |
self.has_allowed_products = False | |
partner_field = ( | |
self.env["ir.config_parameter"] | |
.sudo() | |
.get_param("sale_order_product_assortment.partner_field", "partner_id") | |
) | |
partner = self[partner_field] | |
product_domain = [] | |
if partner: | |
for ir_filter in partner.applied_assortment_ids: | |
product_domain = expression.AND( | |
[product_domain, ir_filter._get_eval_domain()] | |
) | |
if product_domain: | |
self.allowed_product_ids = self.env["product.product"].search( | |
product_domain | |
) | |
self.has_allowed_products = True |
Test the performance with these changes by simply copying and pasting.
You need changes in product_assortment which I see are not at 14.0 either: |
I have vague memories of this PR. I think the problem, as you pointed out, was that there were changes not ported in another module in another repo, and due to the fact it can take a while to get PRs merged and we were in a hurry, it was decided to adapt the changes to the module as is. Having to compute I'll check the PRs you mentioned. Thank you for your time! |
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'm going to approve the changes anyway in case you want to merge this, as I understand it works better than what is currently there and I don't want to block in this version either.
I still need to fix the tests, but thank you |
This commit improves performance when computing the products allowed in a Sales Order, especially when creating an order and the partner is empty