Skip to content
Snippets Groups Projects
Commit 23e54113 authored by Denis Ledoux's avatar Denis Ledoux
Browse files

[IMP] pos_sale: `pos_order_amount_total` performances using read_group


Using `read_group` to gather such a sum is always more performant
than a `search` followed by a `mapped`.

In the case of the studied database,
the computation never ended,
while it ends in a few seconds
using `read_group`.

upg-7528

closes odoo/odoo#66502

X-original-commit: 8547bb6145c3ddf9c7205ea10deef22473362cce
Signed-off-by: default avatarDenis Ledoux (dle) <dle@odoo.com>
parent 7fdec660
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,9 @@ class CrmTeam(models.Model):
def _compute_pos_order_amount_total(self):
for team in self:
team.pos_order_amount_total = sum(self.env['report.pos.order'].search(
[('session_id', 'in', team.pos_config_ids.mapped('session_ids').filtered(lambda s: s.state == 'opened').ids)]
).mapped('price_total'))
res = self.env['report.pos.order'].read_group(
[("config_id.crm_team_id", "=", team.id), ("session_id.state", "=", "opened")],
["price_total"],
[],
)
team.pos_order_amount_total = sum(r["price_total"] for r in res if r["price_total"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment