From 0e34c8bd8c45ab4c4edb291455fa88fe1aed20b3 Mon Sep 17 00:00:00 2001
From: Saran
Date: Mon, 8 Jul 2019 18:21:20 +0700
Subject: [PATCH] [12.0][IMP] account_asset_management
---
account_asset_management/README.rst | 7 +++
account_asset_management/__manifest__.py | 2 +-
.../models/account_asset.py | 47 +++++++++++++++----
.../models/account_asset_line.py | 4 ++
.../models/account_asset_profile.py | 4 ++
.../readme/CONTRIBUTORS.rst | 2 +
account_asset_management/readme/HISTORY.rst | 5 ++
.../static/description/index.html | 45 +++++++++++-------
.../tests/test_account_asset_management.py | 39 +++++++++++++++
.../views/account_asset.xml | 2 +
.../views/account_asset_profile.xml | 1 +
11 files changed, 130 insertions(+), 28 deletions(-)
diff --git a/account_asset_management/README.rst b/account_asset_management/README.rst
index 51da1743e..615fb150c 100644
--- a/account_asset_management/README.rst
+++ b/account_asset_management/README.rst
@@ -58,6 +58,11 @@ The module in NOT compatible with the standard account_asset module.
Changelog
=========
+12.0.1.1.0 (2019-07-08)
+~~~~~~~~~~~~~~~~~~~~~~~
+
+* [IMP] Add option to calculate depreciation table by days
+
12.0.1.0.0 (2019-01-13)
~~~~~~~~~~~~~~~~~~~~~~~
@@ -94,6 +99,8 @@ Contributors
- Akim Juillerat
- Henrik Norlin (Apps2GROW)
- Maxence Groine
+- Kitti Upariphutthiphong
+- Saran Lim.
Maintainers
~~~~~~~~~~~
diff --git a/account_asset_management/__manifest__.py b/account_asset_management/__manifest__.py
index 32d504301..57385e6cd 100644
--- a/account_asset_management/__manifest__.py
+++ b/account_asset_management/__manifest__.py
@@ -4,7 +4,7 @@
{
'name': 'Assets Management',
- 'version': '12.0.2.0.0',
+ 'version': '12.0.2.1.0',
'license': 'AGPL-3',
'depends': [
'account',
diff --git a/account_asset_management/models/account_asset.py b/account_asset_management/models/account_asset.py
index c2ef18192..645fb71e7 100644
--- a/account_asset_management/models/account_asset.py
+++ b/account_asset_management/models/account_asset.py
@@ -162,6 +162,11 @@ class AccountAsset(models.Model):
# " * Ending Date: Choose the time between 2 depreciations "
# "and the date the depreciations won't go beyond."
)
+ days_calc = fields.Boolean(
+ string='Calculate by days',
+ default=False,
+ help="Use number of days to calculate depreciation amount",
+ )
prorata = fields.Boolean(
string='Prorata Temporis', readonly=True,
states={'draft': [('readonly', False)]},
@@ -276,6 +281,7 @@ class AccountAsset(models.Model):
'method_number': profile.method_number,
'method_time': profile.method_time,
'method_period': profile.method_period,
+ 'days_calc': profile.days_calc,
'method_progress_factor': profile.method_progress_factor,
'prorata': profile.prorata,
'account_analytic_id': profile.account_analytic_id,
@@ -558,6 +564,7 @@ class AccountAsset(models.Model):
'asset_id': asset.id,
'name': name,
'line_date': line['date'],
+ 'line_days': line['days'],
'init_entry': entry['init'],
}
depreciated_value += amount
@@ -750,15 +757,25 @@ class AccountAsset(models.Model):
# last entry
if not (self.method_time == 'number' and
len(line_dates) == self.method_number):
- line_dates.append(line_date)
+ if self.days_calc:
+ line_dates.append(stop_date)
+ else:
+ line_dates.append(line_date)
return line_dates
- def _compute_depreciation_amount_per_fiscal_year(self, table, line_dates):
+ def _compute_depreciation_amount_per_fiscal_year(
+ self, table, line_dates, depreciation_start_date,
+ depreciation_stop_date):
digits = self.env['decimal.precision'].precision_get('Account')
fy_residual_amount = self.depreciation_base
i_max = len(table) - 1
asset_sign = self.depreciation_base >= 0 and 1 or -1
+ day_amount = 0.0
+ if self.days_calc:
+ days = (depreciation_stop_date - depreciation_start_date).days + 1
+ day_amount = self.depreciation_base / days
+
for i, entry in enumerate(table):
if self.method_time == 'year':
year_amount = self._compute_year_amount(fy_residual_amount)
@@ -792,6 +809,7 @@ class AccountAsset(models.Model):
entry.update({
'period_amount': period_amount,
'fy_amount': fy_amount,
+ 'day_amount': day_amount,
})
if self.method_time == 'year':
fy_residual_amount -= fy_amount
@@ -816,26 +834,36 @@ class AccountAsset(models.Model):
fy_amount_check = 0.0
fy_amount = entry['fy_amount']
li_max = len(line_dates) - 1
+ prev_date = max(entry['date_start'], depreciation_start_date)
for li, line_date in enumerate(line_dates):
-
+ line_days = (line_date - prev_date).days + 1
if round(remaining_value, digits) == 0.0:
break
if (line_date > min(entry['date_stop'],
depreciation_stop_date) and not
(i == i_max and li == li_max)):
+ prev_date = line_date
break
+ else:
+ prev_date = line_date + relativedelta(days=1)
if self.method == 'degr-linear' \
and asset_sign * (fy_amount - fy_amount_check) < 0:
break
if i == 0 and li == 0:
- amount = self._get_first_period_amount(
- table, entry, depreciation_start_date, line_dates)
- amount = round(amount, digits)
+ if entry.get('day_amount') > 0.0:
+ amount = line_days * entry.get('day_amount')
+ else:
+ amount = self._get_first_period_amount(
+ table, entry, depreciation_start_date, line_dates)
+ amount = round(amount, digits)
else:
- amount = entry.get('period_amount')
+ if entry.get('day_amount') > 0.0:
+ amount = line_days * entry.get('day_amount')
+ else:
+ amount = entry.get('period_amount')
# last year, last entry
# Handle rounding deviations.
@@ -847,6 +875,7 @@ class AccountAsset(models.Model):
fy_amount_check += amount
line = {
'date': line_date,
+ 'days': line_days,
'amount': amount,
'depreciated_value': depreciated_value,
'remaining_value': remaining_value,
@@ -862,7 +891,7 @@ class AccountAsset(models.Model):
# was compensated in the first FY depreciation line.
# The code has now been simplified with compensation
# always in last FT depreciation line.
- if self.method_time == 'year':
+ if self.method_time == 'year' and not entry.get('day_amount'):
if round(fy_amount_check - fy_amount, digits) != 0:
diff = fy_amount_check - fy_amount
amount = amount - diff
@@ -922,7 +951,7 @@ class AccountAsset(models.Model):
line_dates = self._compute_line_dates(
table, depreciation_start_date, depreciation_stop_date)
table = self._compute_depreciation_amount_per_fiscal_year(
- table, line_dates,
+ table, line_dates, depreciation_start_date, depreciation_stop_date
)
# Step 2:
# Spread depreciation amount per fiscal year
diff --git a/account_asset_management/models/account_asset_line.py b/account_asset_management/models/account_asset_line.py
index 5fda7e66a..326f9c7a2 100644
--- a/account_asset_management/models/account_asset_line.py
+++ b/account_asset_management/models/account_asset_line.py
@@ -43,6 +43,10 @@ class AccountAssetLine(models.Model):
string='Amount Already Depreciated',
store=True)
line_date = fields.Date(string='Date', required=True)
+ line_days = fields.Integer(
+ string='Days',
+ readonly=True,
+ )
move_id = fields.Many2one(
comodel_name='account.move',
string='Depreciation Entry', readonly=True)
diff --git a/account_asset_management/models/account_asset_profile.py b/account_asset_management/models/account_asset_profile.py
index f2f03fa17..b6c192b16 100644
--- a/account_asset_management/models/account_asset_profile.py
+++ b/account_asset_management/models/account_asset_profile.py
@@ -90,6 +90,10 @@ class AccountAssetProfile(models.Model):
"number of depreciation lines.\n"
" * Number of Years: Specify the number of years "
"for the depreciation.\n")
+ days_calc = fields.Boolean(
+ string='Calculate by days',
+ default=False,
+ help="Use number of days to calculate depreciation amount")
prorata = fields.Boolean(
string='Prorata Temporis',
help="Indicates that the first depreciation entry for this asset "
diff --git a/account_asset_management/readme/CONTRIBUTORS.rst b/account_asset_management/readme/CONTRIBUTORS.rst
index bf16c0bbd..6afc965f8 100644
--- a/account_asset_management/readme/CONTRIBUTORS.rst
+++ b/account_asset_management/readme/CONTRIBUTORS.rst
@@ -7,3 +7,5 @@
- Akim Juillerat
- Henrik Norlin (Apps2GROW)
- Maxence Groine
+- Kitti Upariphutthiphong
+- Saran Lim.
diff --git a/account_asset_management/readme/HISTORY.rst b/account_asset_management/readme/HISTORY.rst
index c192efa62..d68c9d780 100644
--- a/account_asset_management/readme/HISTORY.rst
+++ b/account_asset_management/readme/HISTORY.rst
@@ -1,3 +1,8 @@
+12.0.2.1.0 (2019-10-21)
+~~~~~~~~~~~~~~~~~~~~~~~
+
+* [IMP] Add option to calculate depreciation table by days
+
12.0.1.0.0 (2019-01-13)
~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/account_asset_management/static/description/index.html b/account_asset_management/static/description/index.html
index 02e2eba13..20dd2d65e 100644
--- a/account_asset_management/static/description/index.html
+++ b/account_asset_management/static/description/index.html
@@ -380,34 +380,41 @@ the standard account_asset module from Odoo.
Table of contents
-
+
It is recommended to configure your Purchase Journal with “Group Invoice Lines” to avoid the
creation of separate assets per Supplier Invoice Line.
-
+
The module in NOT compatible with the standard account_asset module.
-
+
-
+
+
+- [IMP] Add option to calculate depreciation table by days
+
+
+
+
- [BREAKING] account.asset: parent_path has replaced parent_left & parent_right (TODO: migration script)
- [BREAKING] account.asset.recompute.trigger: depends on date_range.py (TODO: re-implement in account_fiscal_year.py)
@@ -415,7 +422,7 @@ creation of separate assets per Supplier Invoice Line.
-
+
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 smashing it by providing a detailed and welcomed
@@ -423,15 +430,15 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
Do not contact contributors directly about support or help with technical issues.
-
+
-
+
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
diff --git a/account_asset_management/tests/test_account_asset_management.py b/account_asset_management/tests/test_account_asset_management.py
index 2cc5622b0..199089356 100644
--- a/account_asset_management/tests/test_account_asset_management.py
+++ b/account_asset_management/tests/test_account_asset_management.py
@@ -515,3 +515,42 @@ class TestAssetManagement(SavepointCase):
dlines = dlines.sorted(key=lambda l: l.line_date)
self.assertAlmostEqual(dlines[0].depreciated_value, 0.0)
self.assertAlmostEqual(dlines[-1].remaining_value, 0.0)
+
+ def test_12_prorata_days_calc(self):
+ """Prorata temporis depreciation with days calc option."""
+ asset = self.asset_model.create({
+ 'name': 'test asset',
+ 'profile_id': self.ref('account_asset_management.'
+ 'account_asset_profile_car_5Y'),
+ 'purchase_value': 3333,
+ 'salvage_value': 0,
+ 'date_start': time.strftime('%Y-07-07'),
+ 'method_time': 'year',
+ 'method_number': 5,
+ 'method_period': 'month',
+ 'prorata': True,
+ 'days_calc': True,
+ })
+ asset.compute_depreciation_board()
+ asset.refresh()
+ day_rate = 0.0
+ if calendar.isleap(date.today().year) or \
+ calendar.isleap(date.today().year + 1):
+ day_rate = 1.8243 # 3333 / 1827 depreciation days
+ else:
+ day_rate = 1.8253 # 3333 / 1826 depreciation days
+ for i in range(1, 10):
+ self.assertAlmostEqual(
+ asset.depreciation_line_ids[i].amount,
+ asset.depreciation_line_ids[i].line_days * day_rate, places=2)
+
+ # Last depreciation remaining
+ self.assertAlmostEqual(
+ asset.depreciation_line_ids[-1].amount, 10.95, places=2)
+ # if calendar.isleap(date.today().year) or \
+ # calendar.isleap(date.today().year + 1):
+ # self.assertAlmostEqual(
+ # asset.depreciation_line_ids[-1].amount, 10.95, places=2)
+ # else:
+ # self.assertAlmostEqual(
+ # asset.depreciation_line_ids[-1].amount, 2.4, places=2)
diff --git a/account_asset_management/views/account_asset.xml b/account_asset_management/views/account_asset.xml
index 8c28fe939..de68cc59f 100644
--- a/account_asset_management/views/account_asset.xml
+++ b/account_asset_management/views/account_asset.xml
@@ -66,6 +66,7 @@
+
@@ -86,6 +87,7 @@
+
diff --git a/account_asset_management/views/account_asset_profile.xml b/account_asset_management/views/account_asset_profile.xml
index b6053505b..2f684a17d 100644
--- a/account_asset_management/views/account_asset_profile.xml
+++ b/account_asset_management/views/account_asset_profile.xml
@@ -29,6 +29,7 @@
+