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

[11.0][MIG] account_asset_management_method_number_end : Migration to v11 #704

50 changes: 50 additions & 0 deletions account_asset_management_method_number_end/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

================================================
Financial asset management - method Number & End
================================================

This module enables the Time Methods 'Number of Depreciations' and 'Ending Date' for the Financial Assets.

By doing so, you can use the depreciation table calculation and posting functionality
for e.g. Cost/Revenue spreading purposes.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/92/10.0

This comment was marked as resolved.


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------
- Luc De Meyer (Noviat)


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit http://odoo-community.org.
1 change: 1 addition & 0 deletions account_asset_management_method_number_end/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions account_asset_management_method_number_end/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Financial asset management - method Number & End',
'version': '11.0.1.0.0',
'license': 'AGPL-3',
'author': "Noviat,Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/account-financial-tools',
'category': 'Accounting & Finance',
'depends': [
'account_asset_management',
],
'installable': True,
}
3 changes: 3 additions & 0 deletions account_asset_management_method_number_end/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_asset_method_number_end
from . import account_asset
from . import account_asset_profile
10 changes: 10 additions & 0 deletions account_asset_management_method_number_end/models/account_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class AccountAsset(models.Model):

_name = 'account.asset'
_inherit = ['account.asset', 'account.asset.method.number.end.mixin']
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields


class AccountAssetMethodNumberEnd(models.AbstractModel):

_name = 'account.asset.method.number.end.mixin'

method_number = fields.Integer(
string='Number',
help="The meaning of this parameter depends on the Time Method.\n"
" * Number of Years: Specify the number of years "
"for the depreciation.\n"
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n"
" * Ending Date: Choose the time between 2 depreciations "
"and the date the depreciations won't go beyond.")

method_time = fields.Selection(
selection=lambda self: self.env[
'account.asset.profile']._selection_method_time(),
help="Choose the method to use to compute the dates and "
"number of depreciation lines.\n"
" * Number of Years: Specify the number of years "
"for the depreciation.\n"
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n"
" * Ending Date: Choose the time between 2 depreciations "
"and the date the depreciations won't go beyond.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models, _


class AccountAssetProfile(models.Model):

_name = 'account.asset.profile'
_inherit = [
'account.asset.profile', 'account.asset.method.number.end.mixin'
]

@api.model
def _selection_method_time(self):
res = super(AccountAssetProfile, self)._selection_method_time()
res += [
('number', _('Number of Depreciations')),
('end', _('Ending Date'))]
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Luc De Meyer (Noviat)
* Akim Juillerat <akim.juillerat@camptocamp.com>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module enables the Time Methods 'Number of Depreciations' and 'Ending Date' for the Financial Assets.

By doing so, you can use the depreciation table calculation and posting functionality
for e.g. Cost/Revenue spreading purposes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_asset_management
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2009-2018 Noviat.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import time

from odoo.tests.common import SavepointCase
from odoo import tools
from odoo.modules.module import get_resource_path


class TestAssetManagement(SavepointCase):

@classmethod
def _load(cls, module, *args):
tools.convert_file(cls.cr, module,
get_resource_path(module, *args),
{}, 'init', False, 'test',
cls.registry._assertion_report)

@classmethod
def setUpClass(cls):
super(TestAssetManagement, cls).setUpClass()

cls._load('account', 'test', 'account_minimal_test.xml')
cls._load('account_asset_management', 'tests',
'account_asset_test_data.xml')

cls.asset_model = cls.env['account.asset']
cls.dl_model = cls.env['account.asset.line']

def test_1_linear_number(self):
"""Linear with Method Time 'Number'."""
asset = self.asset_model.create({
'name': 'test asset',
'profile_id': self.ref('account_asset_management.'
'account_asset_profile_car_5Y'),
'purchase_value': 1000,
'salvage_value': 0,
'date_start': time.strftime('%Y-07-07'),
'method_time': 'number',
'method': 'linear',
'method_number': 12,
'method_period': 'month',
'prorata': True,
})
asset.compute_depreciation_board()
asset.refresh()

# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 13)
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount,
83.33, places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[-1].amount,
83.37, places=2)

def test_2_linear_end(self):
"""Linear with Method Time End Date."""
asset = self.asset_model.create({
'name': 'test asset',
'profile_id': self.ref('account_asset_management.'
'account_asset_profile_car_5Y'),
'purchase_value': 1000,
'salvage_value': 0,
'date_start': time.strftime('%Y-01-30'),
'method_time': 'end',
'method': 'linear',
'method_end': time.strftime('%Y-06-30'),
'method_period': 'month',
'prorata': True,
})
asset.compute_depreciation_board()
asset.refresh()

# check values in the depreciation board
self.assertEqual(len(asset.depreciation_line_ids), 7)
self.assertAlmostEqual(asset.depreciation_line_ids[1].amount,
166.67, places=2)
self.assertAlmostEqual(asset.depreciation_line_ids[-1].amount,
166.65, places=2)