[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#80755 X-original-commit: 2860051b3cbfa7bcd7df76d05b4e5770e9a4c2d0 Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- 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):
|
||||
|
||||
Reference in New Issue
Block a user