[16.0][REF] sale_advance_payment: remove widget dependency#3799
Conversation
Improve performance by searching directly the related invoice lines
| continue | ||
|
|
||
| # Domain search (most efficient for large datasets) | ||
| advance_payment_lines = self.env["account.move.line"].search( |
There was a problem hiding this comment.
@ljsalvatierra-factorlibre For a better performance, do the search before the loop, then, filter records on payment_move_ids.
There was a problem hiding this comment.
Hi! Thank you for your review! You mean like this?
def _post(self, soft=True):
# Automatic reconciliation of payment when invoice confirmed.
res = super()._post(soft=soft)
sale_orders = self.mapped("line_ids.sale_line_ids.order_id")
all_payment_move_ids = sale_orders.mapped("account_payment_ids.move_id").ids
advance_payment_lines = self.env["account.move.line"].search(
[
("move_id", "in", all_payment_move_ids),
(
"account_id.account_type",
"in",
("asset_receivable", "liability_payable"),
),
("reconciled", "=", False),
("parent_state", "=", "posted"),
]
)
for move in self:
sale_order = move.mapped("line_ids.sale_line_ids.order_id")
if not sale_order:
continue
payment_move_ids = sale_order.account_payment_ids.move_id.ids
if not payment_move_ids:
continue
payment_lines = advance_payment_lines.filtered(
lambda x: x.move_id.id in payment_move_ids
)
for line in payment_lines:
move.js_assign_outstanding_line(line_id=line.id)
return resThere was a problem hiding this comment.
Hi @rousseldenis did you have time to review my proposed solution?
|
But @ljsalvatierra-factorlibre, this is great as I thought also computing things on widget values was a nonsense! 😃 |
PabloMartFL
left a comment
There was a problem hiding this comment.
Functional review okey, tested on a local enviroment.
To validate an invoice, before the fix, it took about 7-8 seconds
With the fix, invoice validation takes less than 1 second.
ValentinVinagre
left a comment
There was a problem hiding this comment.
Have sense. Will you bring it to higher versions?
There is already a PR for 18.0 migration. I dont have plans nor time to do it honestly. |
So I won't validate it if it doesn't move to the rest of the versions. |
Ok |
|
This PR has the |
|
/ocabot merge minor |
|
This PR looks fantastic, let's merge it! |
|
Congratulations, your PR was merged at 74e209f. Thanks a lot for contributing to OCA. ❤️ |
Improve performance by searching directly the related invoice lines