Skip to content

Commit

Permalink
[IMP] l10n_it_asset_management: Default asset for recharge
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Aug 19, 2024
1 parent f5a3577 commit 1bc3c8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 12 additions & 2 deletions l10n_it_asset_management/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
5 changes: 3 additions & 2 deletions l10n_it_asset_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 5 additions & 1 deletion l10n_it_asset_management/wizard/account_move_manage_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1bc3c8b

Please sign in to comment.