Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Calcolare il valore del fondo ammortamento durante la dismissione parziale #4365

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_it_asset_management/tests/test_asset_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def test_depreciate_partial_sale_loss_coefficient(self):
"partial_dismiss",
wiz_values={
"asset_id": asset,
"depreciated_fund_amount": depreciated_fund_amount,
"asset_purchase_amount": asset_purchase_amount,
"depreciated_fund_amount": depreciated_fund_amount,
},
)

Expand Down
64 changes: 63 additions & 1 deletion l10n_it_asset_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from odoo import fields
from odoo.exceptions import ValidationError
from odoo.fields import Command
from odoo.fields import Command, first
from odoo.tests import Form
from odoo.tools.date_utils import relativedelta

from .common import Common
Expand Down Expand Up @@ -731,3 +732,64 @@ def test_same_asset_report_residual_partial_depreciation(self):
self.assertEqual(
asset_report_depreciation_line.amount_residual, expected_residual_amount
)

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
Loading