diff --git a/l10n_it_asset_management/tests/common.py b/l10n_it_asset_management/tests/common.py index 6dfda61b3c77..14f874176ac6 100644 --- a/l10n_it_asset_management/tests/common.py +++ b/l10n_it_asset_management/tests/common.py @@ -347,8 +347,9 @@ def _create_entry(self, account, amount, post=True): self.assertEqual(entry.move_type, "entry") return entry - def _link_asset_move(self, move, link_management_type, wiz_values=None): - """Link `move` to an asset with mode `link_management_type`. + def _get_move_asset_wizard(self, move, link_management_type, wiz_values=None): + """Get the wizard that links `move` to an asset + with mode `link_management_type`. `wiz_values` are values to be set in the wizard. """ if wiz_values is None: @@ -364,4 +365,13 @@ def _link_asset_move(self, move, link_management_type, wiz_values=None): for field_name, field_value in wiz_values.items(): setattr(wiz_form, field_name, field_value) wiz = wiz_form.save() + return wiz + + def _link_asset_move(self, move, link_management_type, wiz_values=None): + """Link `move` to an asset with mode `link_management_type`. + `wiz_values` are values to be set in the wizard. + """ + wiz = self._get_move_asset_wizard( + move, link_management_type, wiz_values=wiz_values + ) return wiz.link_asset() diff --git a/l10n_it_asset_management/tests/test_assets_management.py b/l10n_it_asset_management/tests/test_assets_management.py index 0af9f867aec3..7e05eabe0474 100644 --- a/l10n_it_asset_management/tests/test_assets_management.py +++ b/l10n_it_asset_management/tests/test_assets_management.py @@ -601,15 +601,16 @@ def test_purchase_sale_refund_recharge(self): sale_invoice, ref_date=datetime.date(2020, month=7, day=1) ) recharge_purchase_amount = recharge_fund_amount = 1000 - self._link_asset_move( + wizard = self._get_move_asset_wizard( sale_refund, "partial_recharge", wiz_values={ - "asset_id": asset, "recharge_purchase_amount": recharge_purchase_amount, "recharge_fund_amount": recharge_fund_amount, }, ) + wizard.link_asset() + self.assertEqual(wizard.asset_id, asset) civ_depreciation_lines = civ_depreciation.line_ids - civ_depreciation_lines self.assertRecordValues( civ_depreciation_lines.sorted("move_type"), diff --git a/l10n_it_asset_management/wizard/account_move_manage_asset.py b/l10n_it_asset_management/wizard/account_move_manage_asset.py index a6babac2d6de..ca2c3c3e0fe7 100644 --- a/l10n_it_asset_management/wizard/account_move_manage_asset.py +++ b/l10n_it_asset_management/wizard/account_move_manage_asset.py @@ -5,7 +5,7 @@ from odoo import _, api, fields, models from odoo.exceptions import ValidationError -from odoo.fields import Command +from odoo.fields import Command, first from odoo.tools.float_utils import float_compare, float_is_zero @@ -139,6 +139,10 @@ def onchange_depreciation_type_ids(self): ) else: self.depreciation_type_ids = False + elif self.management_type == "partial_recharge": + reversed_assets = self.move_ids.reversed_entry_id.asset_ids + if reversed_assets and self.asset_id not in reversed_assets: + self.asset_id = first(reversed_assets) else: self.depreciation_type_ids = False if self.asset_id: