From a2807321b2ba608df68d0eae189f253c93e73e1f 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 52dc5c36..d4eeeb66 100644 --- a/account_asset_management/models/account_move.py +++ b/account_asset_management/models/account_move.py @@ -59,8 +59,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(