The open_action_with_context was not using _for_xml_id, producing an error when reading the action content. In open_action, the action_name was taken from the context and needs sanity checks. Ensure only actions from the account module can be read and only if the user has access to the target model. This is a limitation of the previous behaviour but, at the moment, all known calls are made refering to an action from the account module. Limit the scope of this method while the 14.0 is still early to avoid having a door open to ready any action, and difficult to close later. Remove old action fetching from the context in create_move that is no longer used. closes odoo/odoo#61602 X-original-commit: a39e94f7e4dc74e850650ac90bbc5f85af130bc8 Related: odoo/enterprise#14695 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com> Co-authored-by: Xavier Morel <xmo@odoo.com>
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models, fields
|
|
|
|
|
|
class FleetVehicle(models.Model):
|
|
_inherit = 'fleet.vehicle'
|
|
|
|
bill_count = fields.Integer(compute='_compute_move_ids', string="Bills Count")
|
|
account_move_ids = fields.One2many('account.move', compute='_compute_move_ids')
|
|
|
|
def _compute_move_ids(self):
|
|
if not self.env.user.has_group('account.group_account_readonly'):
|
|
self.account_move_ids = False
|
|
self.bill_count = 0
|
|
return
|
|
|
|
for vehicle in self:
|
|
vehicle.account_move_ids = self.env['account.move.line'].search([('vehicle_id', '=', self.id), ('move_id.state', '!=', 'cancel')]).move_id
|
|
vehicle.bill_count = len(vehicle.account_move_ids)
|
|
|
|
def action_view_bills(self):
|
|
self.ensure_one()
|
|
|
|
form_view_ref = self.env.ref('account.view_move_form', False)
|
|
tree_view_ref = self.env.ref('account.view_move_tree', False)
|
|
|
|
result = self.env['ir.actions.act_window']._for_xml_id('account.action_move_in_invoice_type')
|
|
result.update({
|
|
'domain': [('id', 'in', self.account_move_ids.ids)],
|
|
'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')],
|
|
})
|
|
return result
|