Skip to content

Commit

Permalink
[IMP] l10n_it_asset_management: Compute depreciated fund
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Oct 9, 2024
1 parent 9076c72 commit da433bf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
61 changes: 61 additions & 0 deletions l10n_it_asset_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,3 +1014,64 @@ def test_override_journal(self):
# Assert
account_move = asset.depreciation_ids.line_ids.move_id
self.assertEqual(account_move.journal_id, depreciate_asset_wizard.journal_id)

def test_wizard_compute_depreciated_fund(self):
"""
When partially dismissing an asset,
the fund amount in wizard is computed based on
the purchased amount and civil depreciation amounts.
"""
# Arrange
civil_depreciation_type = self.env.ref(
"l10n_it_asset_management.ad_type_civilistico"
)
purchase_date = date(2019, 1, 1)
depreciation_date = date(2020, 1, 1)
civil_depreciable_amount = 1000
civil_depreciated_amount = 250
purchase_amount = 300

asset = self._create_asset(purchase_date)
civil_depreciation = first(
asset.depreciation_ids.filtered(
lambda d: d.type_id == civil_depreciation_type
)
)
civil_depreciation.mode_id.line_ids.unlink()
civil_depreciation.percentage = 25.0
self._depreciate_asset(asset, depreciation_date)

invoice_form = Form(
self.env["account.move"].with_context(default_move_type="out_invoice")
)
invoice_form.partner_id = self.env.ref("base.partner_demo")
with invoice_form.invoice_line_ids.new() as line:
line.account_id = asset.category_id.asset_account_id
line.price_unit = 100
invoice = invoice_form.save()
invoice.action_post()

self.assertEqual(
civil_depreciation.amount_depreciable, civil_depreciable_amount
)
self.assertEqual(
civil_depreciation.amount_depreciated, civil_depreciated_amount
)

# Act
wizard_action = invoice.open_wizard_manage_asset()
wizard_form = Form(
self.env[wizard_action["res_model"]].with_context(
**wizard_action["context"]
)
)
wizard_form.management_type = "partial_dismiss"
wizard_form.asset_id = asset
wizard_form.asset_purchase_amount = purchase_amount
wizard = wizard_form.save()

# Assert
self.assertEqual(
wizard.depreciated_fund_amount,
purchase_amount * civil_depreciated_amount / civil_depreciable_amount,
)
35 changes: 34 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 @@ -47,7 +47,11 @@ def get_default_move_ids(self):
string="Currency",
)

depreciated_fund_amount = fields.Monetary()
depreciated_fund_amount = fields.Monetary(
compute="_compute_depreciated_fund_amount",
store=True,
readonly=False,
)

depreciation_type_ids = fields.Many2many(
"asset.depreciation.type", string="Depreciation Types"
Expand Down Expand Up @@ -122,6 +126,35 @@ def get_default_move_ids(self):
"update": lambda w: w.update_asset(),
}

@api.depends(
"asset_id",
"asset_purchase_amount",
"management_type",
)
def _compute_depreciated_fund_amount(self):
civil_depreciation_type = self.env.ref(
"l10n_it_asset_management.ad_type_civilistico",
raise_if_not_found=False,
)
for wizard in self:
depreciated_fund_amount = 0
if civil_depreciation_type and wizard.management_type == "partial_dismiss":
asset = wizard.asset_id
civil_depreciation = asset.depreciation_ids.filtered(
lambda dep: dep.type_id == civil_depreciation_type
)
civil_depreciable_amount = civil_depreciation.amount_depreciable
if civil_depreciation and civil_depreciable_amount:
# Resolve
# depreciated : depreciable = fund_amount : purchase_amount
# for fund_amount
depreciated_fund_amount = (
wizard.asset_purchase_amount
* civil_depreciation.amount_depreciated
/ civil_depreciable_amount
)
wizard.depreciated_fund_amount = depreciated_fund_amount

@api.onchange("asset_id", "management_type")
def onchange_depreciation_type_ids(self):
if self.management_type == "update":
Expand Down

0 comments on commit da433bf

Please sign in to comment.