diff --git a/smile_account_asset/data/account_asset_depreciation_methods.xml b/smile_account_asset/data/account_asset_depreciation_methods.xml
index f04e403ce..a5a1694f9 100644
--- a/smile_account_asset/data/account_asset_depreciation_methods.xml
+++ b/smile_account_asset/data/account_asset_depreciation_methods.xml
@@ -48,6 +48,7 @@
book_value
first_day_of_purchase_month
+ last_day_of_previous_sale_month
max(rate, annuity_number <= length and 100 / (length - annuity_number + 1) or 0)
diff --git a/smile_account_asset/models/account_asset_asset.py b/smile_account_asset/models/account_asset_asset.py
index 326122ee7..6e0d96ddf 100644
--- a/smile_account_asset/models/account_asset_asset.py
+++ b/smile_account_asset/models/account_asset_asset.py
@@ -477,13 +477,6 @@ def _compute_depreciation_lines(self, depreciation_type='accounting'):
# Create new lines
line_infos = self.env['account.asset.depreciation.method']. \
compute_depreciation_board(**kwargs)
- # Round dot because of Python float limit decimal
- rounding = self.currency_id.display_rounding
- for line_info in line_infos:
- for key, value in line_info.items():
- if isinstance(value, (int, float)):
- value = int(value * (1 / rounding)) / (1 / rounding)
- line_info[key] = value
return self._update_or_create_depreciation_lines(
line_infos, depreciation_type)
@@ -533,8 +526,9 @@ def _get_depreciation_arguments(self, depreciation_type):
'last_day_of_previous_sale_month':
last_day_of_previous_sale_month = True
sale_date = fields.Date.to_string(
- fields.Date.from_string(sale_date, '%Y-%m-%d') +
- relativedelta(day=1) + relativedelta(days=-1))
+ fields.Date.from_string(sale_date)
+ + relativedelta(day=1)
+ + relativedelta(days=-1))
return {
'code': method,
'purchase_value': self.purchase_value,
@@ -706,6 +700,7 @@ def _get_move_line_vals(self, journal_type, amount_excl_tax, tax_amount,
lines = []
if amount_excl_tax:
debit, credit = abs(amount_excl_tax), 0.0
+ # TODO: fix journal type `purchase_refund` that is deprecated
if (amount_excl_tax < 0.0) ^ (
journal_type in ('sale', 'purchase_refund')):
debit, credit = abs(credit), abs(debit)
@@ -739,6 +734,7 @@ def _get_move_line_vals(self, journal_type, amount_excl_tax, tax_amount,
accounts['analytic_account_id'], default))
if amount_excl_tax + tax_amount:
debit, credit = 0.0, abs(amount_excl_tax + tax_amount)
+ # TODO: fix journal type `purchase_refund` that is deprecated
if (amount_excl_tax + tax_amount < 0.0) ^ \
(journal_type in ('sale', 'purchase_refund')):
debit, credit = credit, debit
diff --git a/smile_account_asset/models/account_invoice_line.py b/smile_account_asset/models/account_invoice_line.py
index ed787f1fd..d000c3ba7 100644
--- a/smile_account_asset/models/account_invoice_line.py
+++ b/smile_account_asset/models/account_invoice_line.py
@@ -120,8 +120,8 @@ def _get_asset_vals(self):
asset_type = 'purchase'
amount = quantity = 0.0
for line in self:
- sign = line.invoice_id.journal_id.type == 'purchase_refund' and \
- -1.0 or 1.0
+ sign = (line.invoice_id.journal_id.type == 'purchase'
+ and line.invoice_id.type == 'in_refund') and -1.0 or 1.0
amount += line.price_subtotal * sign
quantity += line.quantity * sign
if amount < 0.0:
diff --git a/smile_account_asset/report/account_asset_depreciations_report.py b/smile_account_asset/report/account_asset_depreciations_report.py
index f9ffe1f32..cab248d25 100644
--- a/smile_account_asset/report/account_asset_depreciations_report.py
+++ b/smile_account_asset/report/account_asset_depreciations_report.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-from odoo import api, models
+from odoo import api, fields, models
class ReportAccountAssetDepreciations(models.AbstractModel):
@@ -93,5 +93,42 @@ def _get_asset_infos(
asset_infos['fiscal_total'] = last_fiscal_line. \
previous_years_accumulated_value_sign
asset_infos['fiscal_year'] = 0.0
+ self._adjust_previous_amounts(asset_infos, asset, date_to, is_posted)
return self._convert_to_currency(
asset_infos, from_currency, to_currency)
+
+ def _adjust_previous_amounts(self, asset_infos, asset, date_to, is_posted):
+ """
+ Ensure that depreciation lines having depreciation date on
+ a previous year but that related to an asset having Entry
+ into service date on the current year are displayed
+ with a null amount on the previous year.
+ """
+ DepreciationLine = self.env['account.asset.depreciation.line']
+ domain = [
+ ('asset_id', '=', asset.id),
+ ('depreciation_date', '<=', date_to),
+ ]
+ if is_posted:
+ domain += [('is_posted', '=', True)]
+ depreciation_lines = DepreciationLine.search(
+ domain, order='depreciation_date asc')
+ if not depreciation_lines:
+ return
+ in_service_account_date_year = fields.Date.from_string(
+ asset.in_service_account_date).year
+ first_line_year = fields.Date.from_string(
+ depreciation_lines[0].depreciation_date).year
+ date_to_year = fields.Date.from_string(date_to).year
+ if first_line_year == date_to_year - 1 and \
+ in_service_account_date_year == date_to_year:
+ accounting_total = asset_infos['accounting_total']
+ fiscal_total = asset_infos['fiscal_total']
+ asset_infos.update({
+ 'accounting_previous': 0.0,
+ 'fiscal_previous': 0.0,
+ 'accounting_period': fiscal_total,
+ 'fiscal_period': fiscal_total,
+ 'accounting_year': accounting_total,
+ 'fiscal_year': fiscal_total,
+ })
diff --git a/smile_account_asset/report/account_asset_depreciations_report.xml b/smile_account_asset/report/account_asset_depreciations_report.xml
index ac50051f8..bf164d3a1 100644
--- a/smile_account_asset/report/account_asset_depreciations_report.xml
+++ b/smile_account_asset/report/account_asset_depreciations_report.xml
@@ -100,7 +100,7 @@
|
|
|
- |
+ |
|
|
|
diff --git a/smile_account_asset/report/account_asset_report.py b/smile_account_asset/report/account_asset_report.py
index a6a35ec4e..0092e63f5 100644
--- a/smile_account_asset/report/account_asset_report.py
+++ b/smile_account_asset/report/account_asset_report.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-from odoo import api, models
+from odoo import api, fields, models
from ..tools import get_fiscalyear_start_date
@@ -80,6 +80,10 @@ def _get_asset_infos(self, asset, to_currency, date_to, is_posted):
current_year_accumulated_value_sign,
'book': depreciation_line.book_value_sign,
}
+ # We only have to adjust amounts in this case, because
+ # when we read values inside asset history, previous value
+ # is already set to 0
+ self._adjust_previous_amounts(res, asset, date_to, is_posted)
else:
for history in asset.asset_history_ids.sorted('date_to'):
if history.date_to > date_to:
@@ -101,3 +105,34 @@ def _get_asset_infos(self, asset, to_currency, date_to, is_posted):
}
res['next'] = res['previous'] + res['current']
return self._convert_to_currency(res, from_currency, to_currency)
+
+ def _adjust_previous_amounts(self, asset_infos, asset, date_to, is_posted):
+ """
+ Ensure that depreciation lines having depreciation date on
+ a previous year but that related to an asset having Entry
+ into service date on the current year are displayed
+ with a null amount on the previous year.
+ """
+ DepreciationLine = self.env['account.asset.depreciation.line']
+ domain = [
+ ('asset_id', '=', asset.id),
+ ('depreciation_date', '<=', date_to),
+ ]
+ if is_posted:
+ domain += [('is_posted', '=', True)]
+ depreciation_lines = DepreciationLine.search(
+ domain, order='depreciation_date asc')
+ if not depreciation_lines:
+ return
+ in_service_account_date_year = fields.Date.from_string(
+ asset.in_service_account_date).year
+ first_line_year = fields.Date.from_string(
+ depreciation_lines[0].depreciation_date).year
+ date_to_year = fields.Date.from_string(date_to).year
+ if first_line_year == date_to_year - 1 and \
+ in_service_account_date_year == date_to_year:
+ current = asset_infos['previous'] + asset_infos['current']
+ asset_infos.update({
+ 'previous': 0.0,
+ 'current': current,
+ })
diff --git a/smile_account_asset/report/account_asset_report.xml b/smile_account_asset/report/account_asset_report.xml
index 94ab9fab7..fef4de58d 100644
--- a/smile_account_asset/report/account_asset_report.xml
+++ b/smile_account_asset/report/account_asset_report.xml
@@ -85,7 +85,7 @@
|
|
|
- |
+ |
|
|
|
diff --git a/smile_account_asset/views/account_invoice_line_view.xml b/smile_account_asset/views/account_invoice_line_view.xml
index a217b29de..de5540721 100644
--- a/smile_account_asset/views/account_invoice_line_view.xml
+++ b/smile_account_asset/views/account_invoice_line_view.xml
@@ -133,7 +133,7 @@
tree,form
- [('invoice_id.state', 'not in', ('draft', 'cancel')),('asset_category_id','!=',False),('invoice_id.journal_id.type', 'in',('purchase','purchase_refund'))]
+ [('invoice_id.state', 'not in', ('draft', 'cancel')),('asset_category_id','!=',False),('invoice_id.journal_id.type', '=', 'purchase')]
{'search_default_asset': True}