Skip to content

Commit

Permalink
Merge PR #3010 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by sergiocorato
  • Loading branch information
OCA-git-bot committed Aug 4, 2023
2 parents c37d5ca + 61e3c87 commit 6f9e3af
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets_management/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
* Silvio Gregorini <[email protected]>
* Stefano Pezzini <[email protected]>
* Lorenzo Battistini <[email protected]>
* `TAKOBI <https://takobi.online>`_:

* Simone Rubino <[email protected]>

Base icon made by `surang <https://www.flaticon.com/authors/surang>`_ from `www.flaticon.com <https://www.flaticon.com/>`_.
7 changes: 7 additions & 0 deletions assets_management/report/asset_journal.py
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 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from collections import OrderedDict
Expand Down Expand Up @@ -360,6 +361,12 @@ def generate_totals(self):
if fy_start <= report_date <= fy_end:
totals_by_dep_type[dep_type][fname] += \
line_curr.compute(last_line[fname], curr)
elif fy_end < report_date:
totals_by_dep_type[dep_type][fname] += \
line_curr.compute(
last_line['amount_depreciation_fund_curr_year'],
curr,
)
elif fname in (
'amount_in_total',
'amount_out_total',
Expand Down
7 changes: 7 additions & 0 deletions assets_management/report/asset_previsional.py
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 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from collections import OrderedDict
Expand Down Expand Up @@ -391,6 +392,12 @@ def generate_totals(self):
if fy_start <= report_date <= fy_end:
totals_by_dep_type[dep_type][fname] += \
line_curr.compute(last_line[fname], curr)
elif fy_end < report_date:
totals_by_dep_type[dep_type][fname] += \
line_curr.compute(
last_line['amount_depreciation_fund_curr_year'],
curr,
)
elif fname in (
'amount_in_total',
'amount_out_total',
Expand Down
93 changes: 93 additions & 0 deletions assets_management/tests/test_assets_management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright 2021 Sergio Corato <https://github.com/sergiocorato>
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import date

from odoo import fields
from odoo.fields import first
from odoo.tests.common import TransactionCase
from dateutil.relativedelta import relativedelta

Expand Down Expand Up @@ -75,3 +79,92 @@ def test_create_depreciation(self):
wiz_vals['context']
).create({})
wiz.do_generate()

def _civil_depreciate_asset(self, asset):
# Keep only one civil depreciation
civil_depreciation_type = self.env.ref(
'assets_management.ad_type_civilistico')
civil_depreciation = first(asset.depreciation_ids.filtered(
lambda d: d.type_id == civil_depreciation_type
))
(asset.depreciation_ids - civil_depreciation).unlink()

civil_depreciation.line_ids = [
(5, 0, 0),
(0, 0, {
'name': '2019',
'date': date(2019, 12, 31),
'move_type': 'depreciated',
'amount': 500,
}),
(0, 0, {
'name': '2020',
'date': date(2020, 12, 31),
'move_type': 'depreciated',
'amount': 500,
}),
]
return True

def _generate_fiscal_years(self, start_date, end_date):
fiscal_years = range(
start_date.year,
end_date.year,
)
fiscal_years_values = list()
for fiscal_year in fiscal_years:
fiscal_year_values = {
"name": "Fiscal Year %d" % fiscal_year,
"date_from": date(fiscal_year, 1, 1),
"date_to": date(fiscal_year, 12, 31),
}
fiscal_years_values.append(fiscal_year_values)
return self.env['account.fiscal.year'].create(fiscal_years_values)

def _get_report_values(self, report_type):
if report_type == 'previsional':
wizard_model = 'wizard.asset.previsional.report'
report_model = 'report_asset_previsional'
export_method = 'export_asset_previsional_report'
elif report_type == 'journal':
wizard_model = 'wizard.asset.journal.report'
report_model = 'report_asset_journal'
export_method = 'export_asset_journal_report'
else:
raise Exception("Report can only be 'journal' or 'previsional'")
return export_method, report_model, wizard_model

def _get_report(self, report_date, report_type):
export_method, report_model, wizard_model = \
self._get_report_values(report_type)

wiz = self.env[wizard_model].create({
'date': report_date,
})
report_result = getattr(wiz, export_method)()
report_ids = report_result['context']['active_ids']
report = self.env[report_model].browse(report_ids)
return report

def test_journal_prev_year(self):
"""
Previous year depreciation considers depreciation of all previous years
"""
# Arrange: Create an asset bought in 2019
# and totally depreciated in 2019 and 2020
asset = self._create_asset()
purchase_date = date(2019, 1, 1)
asset.purchase_date = purchase_date
self.assertEqual(asset.purchase_amount, 1000)
self._civil_depreciate_asset(asset)
self.assertEqual(asset.state, 'totally_depreciated')

# Act: Generate the asset journal report for 2022
report_date = date(2022, 11, 7)
self._generate_fiscal_years(purchase_date, report_date)
report = self._get_report(report_date, 'journal')

# Assert: The previous year depreciation counts.the depreciation of 2020
total = report.report_total_ids
self.assertEqual(total.amount_depreciation_fund_curr_year, 1000)
self.assertEqual(total.amount_depreciation_fund_prev_year, 1000)

0 comments on commit 6f9e3af

Please sign in to comment.