diff --git a/assets_management/README.rst b/assets_management/README.rst index 5894368850d1..696ad6627e8a 100644 --- a/assets_management/README.rst +++ b/assets_management/README.rst @@ -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 `_: * Simone Rubino +* `Aion Tech `_: + + * Simone Rubino Base icon made by `surang `_ from `www.flaticon.com `_. diff --git a/assets_management/__manifest__.py b/assets_management/__manifest__.py index 2ef541e07c3b..eb3f66e96cfe 100644 --- a/assets_management/__manifest__.py +++ b/assets_management/__manifest__.py @@ -1,5 +1,6 @@ # Author(s): Silvio Gregorini (silviogregorini@openforce.it) # 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). { diff --git a/assets_management/readme/CONTRIBUTORS.rst b/assets_management/readme/CONTRIBUTORS.rst index 590545f2f237..8194c5b3dce2 100644 --- a/assets_management/readme/CONTRIBUTORS.rst +++ b/assets_management/readme/CONTRIBUTORS.rst @@ -5,5 +5,8 @@ * `TAKOBI `_: * Simone Rubino +* `Aion Tech `_: + + * Simone Rubino Base icon made by `surang `_ from `www.flaticon.com `_. diff --git a/assets_management/static/description/index.html b/assets_management/static/description/index.html index 109309b5f4b4..8675d8291f7b 100644 --- a/assets_management/static/description/index.html +++ b/assets_management/static/description/index.html @@ -366,7 +366,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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

This modules allows account management of companies’ assets.

@@ -422,6 +422,10 @@

Contributors

  • Simone Rubino <sir@takobi.online>
  • +
  • Aion Tech: +
  • Base icon made by surang from www.flaticon.com.

    diff --git a/assets_management/tests/test_assets_common.py b/assets_management/tests/test_assets_common.py index 10a1db87dee6..043395b5003d 100644 --- a/assets_management/tests/test_assets_common.py +++ b/assets_management/tests/test_assets_common.py @@ -1,7 +1,8 @@ # Copyright 2021 Sergio Corato +# Copyright 2024 Simone Rubino - Aion Tech # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.tests import new_test_user -from odoo.tests.common import SavepointCase +from odoo.tests.common import Form, SavepointCase class TestAssets(SavepointCase): @@ -119,6 +120,13 @@ def setUpClass(cls): cls.loss_account_company_2 = cls.loss_account_company_1.copy( {"company_id": cls.company_2.id} ) + cls.bank_account = cls.env["account.account"].create( + { + "code": "TBA", + "name": "Test Bank Account", + "user_type_id": cls.env.ref("account.data_account_type_liquidity").id, + } + ) # Journals cls.journal_company_1 = cls.env["account.journal"].search( [("type", "=", "general"), ("company_id", "=", cls.company_1.id)], @@ -251,7 +259,7 @@ def setUpClass(cls): } ) - def _create_asset(self, asset_date): + def _create_asset(self, asset_date=None): asset = self.env["asset.asset"].create( { "name": "Test asset", @@ -308,3 +316,32 @@ def _create_purchase_invoice(self, invoice_date, tax_ids=False, amount=7000): purchase_invoice.action_post() self.assertEqual(purchase_invoice.state, "posted") return purchase_invoice + + def _create_entry(self, account, amount, post=True): + """Create an entry that adds `amount` to `account`.""" + entry_form = Form(self.env["account.move"]) + with entry_form.line_ids.new() as asset_line: + asset_line.account_id = account + asset_line.debit = amount + with entry_form.line_ids.new() as bank_line: + bank_line.account_id = self.bank_account + entry = entry_form.save() + + if post: + entry.action_post() + + self.assertEqual(entry.move_type, "entry") + return entry + + def _update_asset(self, entry, asset): + """Execute the wizard on `entry` to update `asset`.""" + wizard_action = entry.open_wizard_manage_asset() + wizard_model = self.env[wizard_action["res_model"]] + wizard_context = wizard_action["context"] + + wizard_form = Form(wizard_model.with_context(**wizard_context)) + wizard_form.management_type = "update" + wizard_form.asset_id = asset + wizard = wizard_form.save() + + return wizard.link_asset() diff --git a/assets_management/tests/test_assets_management.py b/assets_management/tests/test_assets_management.py index 9fb9a9da4bf0..321c6aa4c4bf 100644 --- a/assets_management/tests/test_assets_management.py +++ b/assets_management/tests/test_assets_management.py @@ -1,6 +1,7 @@ # Copyright 2021 Sergio Corato # Copyright 2022 Simone Rubino - TAKOBI # Copyright 2023 Nextev Srl +# 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") diff --git a/assets_management/wizard/account_move_manage_asset.py b/assets_management/wizard/account_move_manage_asset.py index e322fe57de05..e0a51deb3082 100644 --- a/assets_management/wizard/account_move_manage_asset.py +++ b/assets_management/wizard/account_move_manage_asset.py @@ -1,5 +1,6 @@ # Author(s): Silvio Gregorini (silviogregorini@openforce.it) # 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,15 +650,6 @@ 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 @@ -665,23 +657,19 @@ def get_update_asset_vals(self): # 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))