From b044cd643dec4a7d17aaef3d1e9b054f8ceed5cb Mon Sep 17 00:00:00 2001 From: Saran440 Date: Thu, 30 Jun 2022 11:16:46 +0700 Subject: [PATCH] [FIX] account_asset_management: Allow to write on moves with no asset permission Steps to reproduce the problem: - User (Not accountant) create an invoice. - Create invoice plan with Deposit on 1st Invoice - Confirm Order > Register Deposit > Create and View bills - It throws a permission error That's because the search on asset lines is done always for each write on the account.move if certain fields (like the date) are written. --- account_asset_management/models/account_move.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account_asset_management/models/account_move.py b/account_asset_management/models/account_move.py index 932dda7be..6d2b6a741 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -60,8 +60,10 @@ class AccountMove(models.Model): def write(self, vals): if set(vals).intersection(FIELDS_AFFECTS_ASSET_MOVE): - deprs = self.env["account.asset.line"].search( - [("move_id", "in", self.ids), ("type", "=", "depreciate")] + deprs = ( + self.env["account.asset.line"] + .sudo() + .search([("move_id", "in", self.ids), ("type", "=", "depreciate")]) ) if deprs: raise UserError(