-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] assets_management: Update asset with entry
Deciding the depreciation type based on the move type does not work with entries because they could be either "in" or "out". Everything depends on the sign of the account move lines amount: if it is positive then it is an "in" depreciation, otherwise "out".
- Loading branch information
1 parent
546c2d6
commit 700dae8
Showing
7 changed files
with
107 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ ITA - Gestione Cespiti | |
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:93205b17d62b5a84274c015b11036ed38fb43141d50ec244673f1f0c03f9da43 | ||
!! source digest: sha256:11430ad54191b2a10124159348728f931698a5f729cf69ee5fbb7f56ff2aa595 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
|
@@ -84,6 +84,9 @@ Contributors | |
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
|
||
Base icon made by `surang <https://www.flaticon.com/authors/surang>`_ from `www.flaticon.com <https://www.flaticon.com/>`_. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Author(s): Silvio Gregorini ([email protected]) | ||
# Copyright 2019 Openforce Srls Unipersonale (www.openforce.it) | ||
# Copyright 2024 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,8 @@ | |
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
* `Aion Tech <https://aiontech.company/>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
|
||
Base icon made by `surang <https://www.flaticon.com/authors/surang>`_ from `www.flaticon.com <https://www.flaticon.com/>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright 2021 Sergio Corato <https://github.com/sergiocorato> | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# Copyright 2023 Nextev Srl <[email protected]> | ||
# Copyright 2024 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from datetime import date | ||
|
||
|
@@ -422,6 +423,46 @@ def test_04_asset_partial_depreciate_from_purchase_invoice_increment(self): | |
sum(civ_dep_lines.mapped("amount")), 7000 * 0.6 + 9000 * 0.4 | ||
) | ||
|
||
def test_entry_in_update_asset(self): | ||
"""An entry adding to the asset account | ||
creates a positive accounting info.""" | ||
asset = self._create_asset() | ||
added_amount = 100 | ||
entry = self._create_entry(asset.category_id.asset_account_id, added_amount) | ||
# pre-condition | ||
self.assertFalse(asset.asset_accounting_info_ids) | ||
|
||
# Act | ||
self._update_asset(entry, asset) | ||
|
||
# Assert | ||
accounting_info = asset.asset_accounting_info_ids | ||
self.assertEqual(accounting_info.move_type, "in") | ||
depreciation_info = asset.depreciation_ids | ||
self.assertEqual( | ||
depreciation_info.amount_residual, asset.purchase_amount + added_amount | ||
) | ||
|
||
def test_entry_out_update_asset(self): | ||
"""An entry removing from the asset account | ||
creates a negative accounting info.""" | ||
asset = self._create_asset() | ||
removed_amount = 100 | ||
entry = self._create_entry(asset.category_id.asset_account_id, -removed_amount) | ||
# pre-condition | ||
self.assertFalse(asset.asset_accounting_info_ids) | ||
|
||
# Act | ||
self._update_asset(entry, asset) | ||
|
||
# Assert | ||
accounting_info = asset.asset_accounting_info_ids | ||
self.assertEqual(accounting_info.move_type, "out") | ||
depreciation_info = asset.depreciation_ids | ||
self.assertEqual( | ||
depreciation_info.amount_residual, asset.purchase_amount - removed_amount | ||
) | ||
|
||
def _civil_depreciate_asset(self, asset): | ||
# Keep only one civil depreciation | ||
civil_depreciation_type = self.env.ref("assets_management.ad_type_civilistico") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Author(s): Silvio Gregorini ([email protected]) | ||
# Copyright 2019 Openforce Srls Unipersonale (www.openforce.it) | ||
# Copyright 2024 Simone Rubino - Aion Tech | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
|
@@ -649,39 +650,26 @@ def get_update_asset_vals(self): | |
for move, lines in grouped_move_lines.items(): | ||
move_num = move.name | ||
|
||
move_type = "in" if move.is_outbound() else "out" | ||
if not move_type: | ||
raise ValidationError( | ||
_( | ||
"Could not retrieve depreciation line type from" | ||
" move `{}` (type `{}`)." | ||
).format(move_num, move_type) | ||
) | ||
|
||
# Compute amount and sign to preview how much the line | ||
# balance will be: if it's going to write off the | ||
# whole residual amount and more, making it become lower | ||
# than zero, raise error | ||
# todo probabilmente si può evitare questo calcolo | ||
amount = 0 | ||
if lines: | ||
amount = abs( | ||
sum( | ||
line.currency_id._convert( | ||
line.debit - line.credit, | ||
dep.currency_id, | ||
line.company_id, | ||
line.date, | ||
) | ||
for line in lines | ||
amount = sum( | ||
line.currency_id._convert( | ||
line.debit - line.credit, | ||
dep.currency_id, | ||
line.company_id, | ||
line.date, | ||
) | ||
for line in lines | ||
) | ||
sign = 1 | ||
if move_type == "out": | ||
sign = -1 | ||
sign = 1 if float_compare(amount, 0, digits) > 0 else -1 | ||
# Block updates if the amount to be written off is higher than | ||
# the residual amount | ||
if sign < 0 and float_compare(residual, amount, digits) < 0: | ||
if sign < 0 and float_compare(residual, abs(amount), digits) < 0: | ||
raise ValidationError( | ||
_( | ||
"Could not update `{}`: not enough residual amount" | ||
|
@@ -691,9 +679,10 @@ def get_update_asset_vals(self): | |
" instead?" | ||
).format(asset_name, move_num, -amount, residual) | ||
) | ||
balances += sign * amount | ||
balances += amount | ||
# end todo | ||
|
||
dep_type = "in" if sign > 0 else "out" | ||
dep_line_vals = { | ||
"asset_accounting_info_ids": [ | ||
( | ||
|
@@ -706,9 +695,9 @@ def get_update_asset_vals(self): | |
) | ||
for line in lines | ||
], | ||
"amount": amount, | ||
"amount": abs(amount), | ||
"date": move.date, | ||
"move_type": move_type, | ||
"move_type": dep_type, | ||
"name": _("From move(s) ") + move_num, | ||
} | ||
dep_vals["line_ids"].append((0, 0, dep_line_vals)) | ||
|