Skip to content

Commit

Permalink
[FIX]assets_management: properly open wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
PicchiSeba committed Sep 6, 2024
1 parent 0f05d07 commit d0861e5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets_management/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def open_wizard_manage_asset(self):
raise ValidationError(_("Every line is already linked to an asset."))

xmlid = "assets_management.action_wizard_account_move_manage_asset"
act = self.env.ref(xmlid).read()[0]
act = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
ctx = dict(self._context)
ctx.update(
{
Expand Down
14 changes: 14 additions & 0 deletions assets_management/tests/test_assets_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def setUpClass(cls):
company_id=cls.company_1.id,
company_ids=[(6, 0, [cls.company_1.id, cls.company_2.id])],
)
groups = ",".join(
[
"base.group_multi_company",
"account.group_account_user",
"assets_management.group_asset_user",
]
)
cls.account_user = new_test_user(
cls.env,
"user_account",
groups=groups,
company_id=cls.company_1.id,
company_ids=[(6, 0, [cls.company_1.id, cls.company_2.id])],
)
# Asset depreciation types
cls.ad_type_civ_company_1 = cls.env.ref("assets_management.ad_type_civilistico")
cls.ad_type_fis_company_1 = cls.env.ref("assets_management.ad_type_fiscale")
Expand Down
31 changes: 30 additions & 1 deletion assets_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import date

from odoo import fields
from odoo.exceptions import ValidationError
from odoo.exceptions import AccessError, ValidationError
from odoo.fields import first
from odoo.tools.date_utils import relativedelta

Expand Down Expand Up @@ -561,3 +561,32 @@ def test_journal_prev_year(self):
total = report.report_total_ids
self.assertEqual(total.amount_depreciation_fund_curr_year, 1000)
self.assertEqual(total.amount_depreciation_fund_prev_year, 1000)

def test_open_manage_asset_wiz(self):
manager_user = self.user
account_user = self.account_user
forbidden_user = self.env.ref("base.user_demo")

invoice = self.env["account.move"].search([])[0]
with self.assertRaises(AccessError):
invoice.with_user(forbidden_user).open_wizard_manage_asset()
invoice.with_user(manager_user).open_wizard_manage_asset()
invoice.with_user(account_user).open_wizard_manage_asset()

asset_category = self.env["asset.category"].search([])[0]
asset_category.asset_account_id = invoice.invoice_line_ids.mapped("account_id")
asset_wiz = self.env["wizard.account.move.manage.asset"].create(
[
{
"name": "Test Asset Name",
"category_id": asset_category.id,
"management_type": "create",
"move_ids": [(6, 0, invoice.ids)],
"move_line_ids": [(6, 0, invoice.invoice_line_ids.ids)],
}
]
)
with self.assertRaises(AccessError):
asset_wiz.with_user(forbidden_user).link_asset()
asset_wiz.with_user(manager_user).link_asset()
asset_wiz.with_user(account_user).link_asset()
2 changes: 1 addition & 1 deletion assets_management/wizard/account_move_manage_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def link_asset(self):

if self._context.get("show_asset"):
act_xmlid = "assets_management.action_asset"
act = self.env.ref(act_xmlid).read()[0]
act = self.env["ir.actions.act_window"]._for_xml_id(act_xmlid)

Check warning on line 227 in assets_management/wizard/account_move_manage_asset.py

View check run for this annotation

Codecov / codecov/patch

assets_management/wizard/account_move_manage_asset.py#L227

Added line #L227 was not covered by tests
form_xmlid = "assets_management.asset_form_view"
form = self.env.ref(form_xmlid)
act.update(
Expand Down

0 comments on commit d0861e5

Please sign in to comment.