Skip to content
Snippets Groups Projects
Commit 2860051b authored by Nicolas (vin)'s avatar Nicolas (vin)
Browse files

[FIX] account_fleet: Improve performances


Performances issues have been noticed in account_fleet when computing
the move_ids of vehicles.
This change has been made in order to fix this issue.

Task id #2700407

closes odoo/odoo#80683

Signed-off-by: default avatarWilliam André (wan) <wan@odoo.com>
parent 4fb3b4d2
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ class AccountMove(models.Model):
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle')
vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle', index=True)
need_vehicle = fields.Boolean(compute='_compute_need_vehicle',
help="Technical field to decide whether the vehicle_id field is editable")
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields
from odoo import Command, models, fields
class FleetVehicle(models.Model):
......@@ -16,8 +16,14 @@ class FleetVehicle(models.Model):
self.bill_count = 0
return
moves = self.env['account.move.line'].read_group(
domain=[('vehicle_id', 'in', self.ids), ('move_id.state', '!=', 'cancel')],
fields=['vehicle_id', 'move_id:array_agg'],
groupby=['vehicle_id'],
)
vehicle_move_mapping = {move['vehicle_id'][0]: set(move['move_id']) for move in moves}
for vehicle in self:
vehicle.account_move_ids = self.env['account.move.line'].search([('vehicle_id', '=', vehicle.id), ('move_id.state', '!=', 'cancel')]).move_id
vehicle.account_move_ids = [Command.set(vehicle_move_mapping.get(vehicle.id, []))]
vehicle.bill_count = len(vehicle.account_move_ids)
def action_view_bills(self):
......
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