fix bug in asset

This commit is contained in:
esraa 2024-11-03 12:03:25 +02:00
parent 9bd1ace149
commit aee1fb3cb6
1 changed files with 3 additions and 3 deletions

View File

@ -390,7 +390,7 @@ class AccountAsset(models.Model):
# no need of amount field, as it is computed and we don't want to trigger its inverse function
del (newline_vals['amount_total'])
newline_vals_list.append(newline_vals)
new_moves = self.env['account.move'].create(newline_vals_list)
new_moves = self.env['account.move'].sudo().create(newline_vals_list)
for move in new_moves:
commands.append((4, move.id))
return self.write({'depreciation_move_ids': commands})
@ -692,7 +692,7 @@ class AccountAsset(models.Model):
if changes:
asset.message_post(body=_('Asset sold or disposed. Accounting entry awaiting for validation.'),
tracking_value_ids=tracking_value_ids)
move_ids += self.env['account.move'].search([('asset_id', '=', asset.id), ('state', '=', 'draft')]).ids
move_ids += self.env['account.move'].sudo().search([('asset_id', '=', asset.id), ('state', '=', 'draft')]).ids
return move_ids
@ -791,7 +791,7 @@ class AccountAsset(models.Model):
@api.depends('depreciation_move_ids.state', 'parent_id')
def _entry_count(self):
for asset in self:
res = self.env['account.move'].search_count(
res = self.env['account.move'].sudo().search_count(
[('asset_id', '=', asset.id), ('state', '=', 'posted'), ('reversal_move_id', '=', False)])
asset.depreciation_entries_count = res or 0
asset.total_depreciation_entries_count = len(asset.depreciation_move_ids)