Skip to content

Commit b88811a

Browse files
author
Thierry Ducrest
committed
[IMP] sale_exception: too many write on sale.order.line
Although the ORM will properly handle multiple write (as mentioned in the comment) Without the filtering the write method will still be called many time without need.
1 parent 33807d0 commit b88811a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sale_exception/models/sale_order_line.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def _detect_exceptions(self, rule):
5656
# Thanks to the new flush of odoo 13.0, queries will be optimized
5757
# together at the end even if we update the exception_ids many times.
5858
# On previous versions, this could be unoptimized.
59-
(self - records).exception_ids = [Command.unlink(rule.id)]
60-
records.exception_ids = [Command.link(rule.id)]
59+
lines_to_remove_exception = (self - records).filtered(
60+
lambda line: rule.id in line.exception_ids.ids
61+
)
62+
lines_to_remove_exception.exception_ids = [Command.unlink(rule.id)]
63+
lines_to_add_exception = records.filtered(
64+
lambda line: rule.id not in line.exception_ids.ids
65+
)
66+
lines_to_add_exception.exception_ids = [Command.link(rule.id)]
6167
return records.mapped("order_id")

0 commit comments

Comments
 (0)