diff --git a/account_asset_force_account/README.rst b/account_asset_force_account/README.rst new file mode 100644 index 000000000..2ab0c66b5 --- /dev/null +++ b/account_asset_force_account/README.rst @@ -0,0 +1,109 @@ +=================== +Asset Force Account +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1eb4e22468a624d5f2d627b3ea38ad1b92264324736d1e8071e8e048da712da2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/17.0/account_asset_force_account + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-0-account_asset_force_account + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module enables the ability to override default accounts directly +from the asset form. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. | **Create an Asset Profile**: + | Navigate to **Configuration -> Asset Profiles** and create a new + profile. + +2. **Create a Vendor Bill**: + + - Go to **Vendors -> Bills** and create a new bill. + - Add a product and select the asset profile you just created. + - The Asset Account will be derived from the profile or can be + manually updated at this step (the invoice account will be used as + the Asset Account). + - Set the product price and confirm the bill. + +3. | **Asset Creation**: + | Once the bill is confirmed, the asset will be created and populated + with the associated accounts. You can now manually adjust the + **Depreciation Account** and **Depreciation Expense Account** if + necessary. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Bernat Obrador (APSL-Nagarro) + +Contributors +------------ + +- `APSL-Nagarro `__: + + - Bernat Obrador + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-BernatObrador| image:: https://github.com/BernatObrador.png?size=40px + :target: https://github.com/BernatObrador + :alt: BernatObrador + +Current `maintainer `__: + +|maintainer-BernatObrador| + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_asset_force_account/__init__.py b/account_asset_force_account/__init__.py new file mode 100644 index 000000000..3275ac2ad --- /dev/null +++ b/account_asset_force_account/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/account_asset_force_account/__manifest__.py b/account_asset_force_account/__manifest__.py new file mode 100644 index 000000000..3fba5b7c7 --- /dev/null +++ b/account_asset_force_account/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Bernat Obrador(APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Asset Force Account", + "summary": "This module allows you to enforce specific accounts for assets, including depreciation and expense accounts, through asset profiles and forms.", + "version": "17.0.1.0.0", + "website": "https://github.com/OCA/account-financial-tools", + "author": "Bernat Obrador (APSL-Nagarro), Odoo Community Association (OCA)", + "category": "Accounting & Finance", + "maintainers": ["BernatObrador"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "account_asset_management", + ], + "data": [ + "views/account_asset.xml", + ], +} diff --git a/account_asset_force_account/i18n/ca_ES.po b/account_asset_force_account/i18n/ca_ES.po new file mode 100644 index 000000000..72946ffae --- /dev/null +++ b/account_asset_force_account/i18n/ca_ES.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_force_accounts +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-18 09:41+0000\n" +"PO-Revision-Date: 2024-09-18 09:41+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_asset_force_accounts +#: model:ir.model,name:account_asset_force_accounts.model_account_asset +msgid "Asset" +msgstr "Actiu" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_asset_id +msgid "Asset Account" +msgstr "Compte de l'actiu" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_depreciation_id +msgid "Depreciation Account" +msgstr "Compte d'amortització" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_expense_depreciation_id +msgid "Depreciation Expense Account" +msgstr "Compte de despeses d'amortització" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_depreciation_id +msgid "The account used to record depreciation for the asset." +msgstr "El compte utilitzat per registrar l'amortització de l'actiu." + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_expense_depreciation_id +msgid "The account used to record the expense of the depreciation." +msgstr "El compte utilitzat per registrar la despesa per amortització." + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_asset_id +msgid "The account used to record the value of the asset." +msgstr "El compte utilitzat per registrar el valor de l'actiu." diff --git a/account_asset_force_account/i18n/es.po b/account_asset_force_account/i18n/es.po new file mode 100644 index 000000000..7111021aa --- /dev/null +++ b/account_asset_force_account/i18n/es.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_force_accounts +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-18 09:43+0000\n" +"PO-Revision-Date: 2024-09-18 09:43+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_asset_force_accounts +#: model:ir.model,name:account_asset_force_accounts.model_account_asset +msgid "Asset" +msgstr "Activo" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_asset_id +msgid "Asset Account" +msgstr "Cuenta de activo" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_depreciation_id +msgid "Depreciation Account" +msgstr "Cuenta de amortización" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,field_description:account_asset_force_accounts.field_account_asset__account_expense_depreciation_id +msgid "Depreciation Expense Account" +msgstr "Cuenta de gastos de amortización" + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_depreciation_id +msgid "The account used to record depreciation for the asset." +msgstr "La cuenta utilizada para registrar la depreciación del activo." + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_expense_depreciation_id +msgid "The account used to record the expense of the depreciation." +msgstr "La cuenta utilizada para registrar el gasto por depreciación." + +#. module: account_asset_force_accounts +#: model:ir.model.fields,help:account_asset_force_accounts.field_account_asset__account_asset_id +msgid "The account used to record the value of the asset." +msgstr "La cuenta utilizada para registrar el valor del activo." \ No newline at end of file diff --git a/account_asset_force_account/models/__init__.py b/account_asset_force_account/models/__init__.py new file mode 100644 index 000000000..4a3257809 --- /dev/null +++ b/account_asset_force_account/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_asset +from . import account_asset_line +from . import account_move_line diff --git a/account_asset_force_account/models/account_asset.py b/account_asset_force_account/models/account_asset.py new file mode 100644 index 000000000..7b44839f0 --- /dev/null +++ b/account_asset_force_account/models/account_asset.py @@ -0,0 +1,60 @@ +# Copyright 2024 Bernat Obrador(APSL-Nagarro) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class AccountAsset(models.Model): + _inherit = "account.asset" + + account_asset_id = fields.Many2one( + comodel_name="account.account", + string="Asset Account", + compute="_compute_account_asset_id", + help="The account used to record the value of the asset.", + ) + + account_depreciation_id = fields.Many2one( + comodel_name="account.account", + string="Depreciation Account", + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + help="The account used to record depreciation for the asset.", + required=True, + ) + + account_expense_depreciation_id = fields.Many2one( + comodel_name="account.account", + string="Depreciation Expense Account", + domain="[('deprecated', '=', False), ('company_id', '=', company_id)]", + help="The account used to record the expense of the depreciation.", + required=True, + ) + + @api.onchange("profile_id") + def _onchange_profile_id(self): + # To avoid changes when the asset is confirmed + if self.profile_id and self.state == "draft": + self.account_depreciation_id = self.profile_id.account_depreciation_id + self.account_expense_depreciation_id = ( + self.profile_id.account_expense_depreciation_id + ) + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("profile_id"): + profile = self.env["account.asset.profile"].browse(vals["profile_id"]) + if not vals.get("account_depreciation_id"): + vals["account_depreciation_id"] = profile.account_depreciation_id.id + if not vals.get("account_expense_depreciation_id"): + vals[ + "account_expense_depreciation_id" + ] = profile.account_expense_depreciation_id.id + return super().create(vals_list) + + def _compute_account_asset_id(self): + if len(self.account_move_line_ids.account_id) != 0: + self.account_asset_id = self.account_move_line_ids.sorted( + lambda line: line.create_date + ).account_id[0] + return + self.account_asset_id = self.profile_id.account_asset_id diff --git a/account_asset_force_account/models/account_asset_line.py b/account_asset_force_account/models/account_asset_line.py new file mode 100644 index 000000000..700d65821 --- /dev/null +++ b/account_asset_force_account/models/account_asset_line.py @@ -0,0 +1,17 @@ +# Copyright 2024 Bernat Obrador(APSL-Nagarro) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountAssetLine(models.Model): + _inherit = "account.asset.line" + + def _setup_move_line_data(self, depreciation_date, account, ml_type, move): + res = super()._setup_move_line_data(depreciation_date, account, ml_type, move) + asset = self.asset_id + if ml_type == "depreciation" and asset.account_depreciation_id: + res["account_id"] = asset.account_depreciation_id.id + if ml_type == "expense" and asset.account_expense_depreciation_id: + res["account_id"] = asset.account_expense_depreciation_id.id + return res diff --git a/account_asset_force_account/models/account_move_line.py b/account_asset_force_account/models/account_move_line.py new file mode 100644 index 000000000..5870d1595 --- /dev/null +++ b/account_asset_force_account/models/account_move_line.py @@ -0,0 +1,13 @@ +# Copyright 2024 Bernat Obrador(APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + @api.onchange("asset_profile_id") + def _onchange_asset_profile_id(self): + if self.account_id and self.account_id.account_type == "asset_fixed": + return + super()._onchange_asset_profile_id() diff --git a/account_asset_force_account/pyproject.toml b/account_asset_force_account/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_asset_force_account/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_asset_force_account/readme/CONTRIBUTORS.md b/account_asset_force_account/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..fee8cce2c --- /dev/null +++ b/account_asset_force_account/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [APSL-Nagarro](): + - Bernat Obrador \<\> \ No newline at end of file diff --git a/account_asset_force_account/readme/DESCRIPTION.md b/account_asset_force_account/readme/DESCRIPTION.md new file mode 100644 index 000000000..5a7762d51 --- /dev/null +++ b/account_asset_force_account/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module enables the ability to override default accounts directly from the asset form. \ No newline at end of file diff --git a/account_asset_force_account/readme/USAGE.md b/account_asset_force_account/readme/USAGE.md new file mode 100644 index 000000000..8d49d7463 --- /dev/null +++ b/account_asset_force_account/readme/USAGE.md @@ -0,0 +1,11 @@ +1. **Create an Asset Profile**: + Navigate to **Configuration -> Asset Profiles** and create a new profile. + +2. **Create a Vendor Bill**: + - Go to **Vendors -> Bills** and create a new bill. + - Add a product and select the asset profile you just created. + - The Asset Account will be derived from the profile or can be manually updated at this step (the invoice account will be used as the Asset Account). + - Set the product price and confirm the bill. + +3. **Asset Creation**: + Once the bill is confirmed, the asset will be created and populated with the associated accounts. You can now manually adjust the **Depreciation Account** and **Depreciation Expense Account** if necessary. diff --git a/account_asset_force_account/static/description/icon.png b/account_asset_force_account/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_asset_force_account/static/description/icon.png differ diff --git a/account_asset_force_account/static/description/icon.svg b/account_asset_force_account/static/description/icon.svg new file mode 100644 index 000000000..a7a26d093 --- /dev/null +++ b/account_asset_force_account/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/account_asset_force_account/static/description/index.html b/account_asset_force_account/static/description/index.html new file mode 100644 index 000000000..6a20c7664 --- /dev/null +++ b/account_asset_force_account/static/description/index.html @@ -0,0 +1,459 @@ + + + + + +Asset Force Account + + + +
+

Asset Force Account

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

This module enables the ability to override default accounts directly +from the asset form.

+

Table of contents

+ +
+

Usage

+
    +
  1. +
    Create an Asset Profile:
    +
    Navigate to Configuration -> Asset Profiles and create a new +profile.
    +
    +
  2. +
  3. Create a Vendor Bill:

    +
      +
    • Go to Vendors -> Bills and create a new bill.
    • +
    • Add a product and select the asset profile you just created.
    • +
    • The Asset Account will be derived from the profile or can be +manually updated at this step (the invoice account will be used as +the Asset Account).
    • +
    • Set the product price and confirm the bill.
    • +
    +
  4. +
  5. +
    Asset Creation:
    +
    Once the bill is confirmed, the asset will be created and populated +with the associated accounts. You can now manually adjust the +Depreciation Account and Depreciation Expense Account if +necessary.
    +
    +
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Bernat Obrador (APSL-Nagarro)
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

BernatObrador

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_asset_force_account/tests/__init__.py b/account_asset_force_account/tests/__init__.py new file mode 100644 index 000000000..1f9552781 --- /dev/null +++ b/account_asset_force_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_asset_management_force_account diff --git a/account_asset_force_account/tests/test_account_asset_management_force_account.py b/account_asset_force_account/tests/test_account_asset_management_force_account.py new file mode 100644 index 000000000..83a0d6b09 --- /dev/null +++ b/account_asset_force_account/tests/test_account_asset_management_force_account.py @@ -0,0 +1,188 @@ +# Copyright 2024 Bernat Obrador(APSL-Nagarro) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import time + +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAssetManagement(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.asset_model = cls.env["account.asset"] + cls.asset_profile_model = cls.env["account.asset.profile"] + + cls.account_depreciation_car = cls.env["account.account"].create( + { + "name": "Fixed Asset - Vehicle", + "code": "151001", + "account_type": "asset_fixed", + } + ) + + cls.account_expense_laptop = cls.env["account.account"].create( + { + "name": "Depreciation Expense Account - Laptop", + "code": "600001", + "account_type": "expense", + } + ) + + # Asset Profile 1 + cls.ict3Y = cls.asset_profile_model.create( + { + "account_expense_depreciation_id": cls.company_data[ + "default_account_expense" + ].id, + "account_asset_id": cls.company_data["default_account_assets"].id, + "account_depreciation_id": cls.company_data[ + "default_account_assets" + ].id, + "journal_id": cls.company_data["default_journal_purchase"].id, + "name": "Hardware - 3 Years", + "method_time": "year", + "method_number": 3, + "method_period": "year", + } + ) + # Asset Profile 2 + cls.car5y = cls.asset_profile_model.create( + { + "account_expense_depreciation_id": cls.company_data[ + "default_account_expense" + ].id, + "account_asset_id": cls.company_data["default_account_assets"].id, + "account_depreciation_id": cls.company_data[ + "default_account_assets" + ].id, + "journal_id": cls.company_data["default_journal_purchase"].id, + "name": "Cars - 5 Years", + "method_time": "year", + "method_number": 5, + "method_period": "year", + } + ) + + def test_change_asset_accounts(self): + ict0 = self.asset_model.create( + { + "name": "test asset", + "profile_id": self.ict3Y.id, + "purchase_value": 1500, + "date_start": "1901-02-01", + "method_time": "year", + "method_number": 3, + "method_period": "year", + "account_depreciation_id": self.ict3Y.account_depreciation_id.id, + "account_expense_depreciation_id": self.account_expense_laptop.id, + } + ) + + self.assertEqual(ict0.state, "draft") + self.assertEqual(ict0.purchase_value, 1500) + self.assertEqual(ict0.salvage_value, 0) + self.assertEqual(ict0.depreciation_base, 1500) + self.assertEqual(len(ict0.depreciation_line_ids), 1) + self.assertEqual(ict0.account_asset_id.id, ict0.profile_id.account_asset_id.id) + self.assertEqual( + ict0.account_depreciation_id.id, ict0.profile_id.account_depreciation_id.id + ) + self.assertEqual( + ict0.account_expense_depreciation_id.id, self.account_expense_laptop.id + ) + + vehicle0 = self.asset_model.create( + { + "state": "draft", + "method_time": "year", + "method_number": 5, + "method_period": "year", + "name": "CEO's Car", + "purchase_value": 12000.0, + "salvage_value": 2000.0, + "profile_id": self.car5y.id, + "date_start": time.strftime("%Y-01-01"), + "account_depreciation_id": self.account_depreciation_car.id, + "account_expense_depreciation_id": self.car5y.account_expense_depreciation_id.id, + } + ) + self.assertEqual(vehicle0.state, "draft") + self.assertEqual(vehicle0.purchase_value, 12000) + self.assertEqual(vehicle0.salvage_value, 2000) + self.assertEqual(vehicle0.depreciation_base, 10000) + self.assertEqual(len(vehicle0.depreciation_line_ids), 1) + self.assertEqual( + vehicle0.account_asset_id.id, vehicle0.profile_id.account_asset_id.id + ) + self.assertEqual( + vehicle0.account_depreciation_id.id, self.account_depreciation_car.id + ) + self.assertEqual( + vehicle0.account_expense_depreciation_id.id, + vehicle0.profile_id.account_expense_depreciation_id.id, + ) + + ict0.compute_depreciation_board() + ict0.invalidate_recordset() + self.assertEqual(len(ict0.depreciation_line_ids), 4) + self.assertEqual(ict0.depreciation_line_ids[1].amount, 500) + + vehicle0.compute_depreciation_board() + vehicle0.invalidate_recordset() + self.assertEqual(len(vehicle0.depreciation_line_ids), 6) + self.assertEqual(vehicle0.depreciation_line_ids[1].amount, 2000) + + ict0.validate() + ict0_created_moves_ids = ict0.depreciation_line_ids[1].create_move() + ict0.invalidate_recordset() + + for move_id in ict0_created_moves_ids: + move = self.env["account.move"].browse(move_id) + + # Validate that the profile account is used + depr_line = move.line_ids.filtered( + lambda line: line.account_id == self.ict3Y.account_depreciation_id + ) + self.assertTrue(depr_line) + + # Validate that the forced expense depreciation account is being used + expense_line = move.line_ids.filtered( + lambda line: line.account_id == self.account_expense_laptop + ) + self.assertTrue(expense_line) + + # Check that the asset is now open and depreciation is posted correctly + self.assertEqual(ict0.state, "open") + self.assertEqual(ict0.value_depreciated, 500) + self.assertEqual(ict0.value_residual, 1000) + + vehicle0.validate() + vehicle0_created_move_ids = vehicle0.depreciation_line_ids[1].create_move() + for move_id in vehicle0_created_move_ids: + move = self.env["account.move"].browse(move_id) + + # Validate that the forced depreciation account is being used + depr_line = move.line_ids.filtered( + lambda line: line.account_id == self.account_depreciation_car + ) + self.assertTrue(depr_line) + + # Validate that the profile account is used + expense_line = move.line_ids.filtered( + lambda line: line.account_id + == self.car5y.account_expense_depreciation_id + ) + self.assertTrue(expense_line) + + vehicle0.invalidate_recordset() + + # Ensure the asset's state and values are correct after depreciation posting + self.assertEqual(vehicle0.state, "open") + self.assertEqual(vehicle0.value_depreciated, 2000) + self.assertEqual(vehicle0.value_residual, 8000) + + vehicle0.invalidate_recordset() diff --git a/account_asset_force_account/views/account_asset.xml b/account_asset_force_account/views/account_asset.xml new file mode 100644 index 000000000..2d71e2a35 --- /dev/null +++ b/account_asset_force_account/views/account_asset.xml @@ -0,0 +1,28 @@ + + + + + account.asset.form.inherit + account.asset + + + + + + + + + +