[FIX] account_asset_management: Avoid error

Steps to reproduce the problem:

* Go to assets view
* Group by profile
* Unfold a group and click on an asset
* Click on "Journal Entries" smart-button
* Go back to the asset list
* Click again on the same asset (or another).
* Click on "Journal Entries" smart-button

Current behavior:

Error saying "KeyError: 'profile_id'"

Expected behavior:

No error

The cause for this is that Odoo stores in the context the key `group_by` with the
value `profile_id` in the specified chain of steps. That context entry is used for
grouping records in the list, and system tries to group the journal entries also
by that field, which doesn't exists in the other model, and thus the error.

We avoided it copying the context to be passes and leaving out that entry.
This commit is contained in:
Pedro M. Baeza
2020-03-18 19:25:11 +01:00
parent 0bb6165bb0
commit 36f38adf06
2 changed files with 5 additions and 2 deletions

View File

@@ -4,7 +4,7 @@
{
'name': 'Assets Management',
'version': '12.0.2.2.2',
'version': '12.0.2.2.3',
'license': 'AGPL-3',
'depends': [
'account',

View File

@@ -446,6 +446,9 @@ class AccountAsset(models.Model):
amls = self.env['account.move.line'].search(
[('asset_id', '=', self.id)], order='date ASC')
am_ids = [l.move_id.id for l in amls]
# needed for avoiding errors after grouping in assets
context = dict(self.env.context)
context.pop('group_by', None)
return {
'name': _("Journal Entries"),
'view_type': 'form',
@@ -453,7 +456,7 @@ class AccountAsset(models.Model):
'res_model': 'account.move',
'view_id': False,
'type': 'ir.actions.act_window',
'context': self.env.context,
'context': context,
'domain': [('id', 'in', am_ids)],
}