Merge PR #1162 into 13.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2021-04-20 16:09:23 +00:00
4 changed files with 58 additions and 14 deletions

View File

@@ -204,7 +204,9 @@ class AccountAsset(models.Model):
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",
"for the depreciation.\n"
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n",
)
days_calc = fields.Boolean(
string="Calculate by days",
@@ -388,10 +390,12 @@ class AccountAsset(models.Model):
_("Degressive-Linear is only supported for Time Method = Year.")
)
@api.constrains("date_start", "method_end", "method_time")
@api.constrains("date_start", "method_end", "method_number", "method_time")
def _check_dates(self):
if self.filtered(
lambda a: a.method_time == "end" and a.method_end <= a.date_start
lambda a: a.method_time == "year"
and not a.method_number
and a.method_end <= a.date_start
):
raise UserError(_("The Start Date must precede the Ending Date."))

View File

@@ -119,7 +119,9 @@ class AccountAssetProfile(models.Model):
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",
"for the depreciation.\n"
" * Number of Depreciations: Fix the number of "
"depreciation lines and the time between 2 depreciations.\n",
)
days_calc = fields.Boolean(
string="Calculate by days",
@@ -186,7 +188,10 @@ class AccountAssetProfile(models.Model):
Install the 'account_asset_management_method_number_end' to enable the
'Number' and 'End' Time Methods.
"""
return [("year", _("Number of Years or end date"))]
return [
("year", _("Number of Years or end date")),
("number", _("Number of Depreciations")),
]
@api.constrains("method", "method_time")
def _check_method(self):

View File

@@ -5,6 +5,7 @@ import logging
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tests.common import Form
_logger = logging.getLogger(__name__)
@@ -81,20 +82,25 @@ class AccountMove(models.Model):
vals = {
"name": aml.name,
"code": move.name,
"profile_id": aml.asset_profile_id.id,
"profile_id": aml.asset_profile_id,
"purchase_value": depreciation_base,
"partner_id": aml.partner_id.id,
"partner_id": aml.partner_id,
"date_start": move.date,
"account_analytic_id": aml.analytic_account_id.id,
"analytic_tag_ids": aml.analytic_tag_ids.id,
"account_analytic_id": aml.analytic_account_id,
}
if self.env.context.get("company_id"):
vals["company_id"] = self.env.context["company_id"]
asset = (
self.env["account.asset"]
.with_context(create_asset_from_move_line=True, move_id=move.id)
.create(vals)
vals["company_id"] = self.env["res.company"].browse(
self.env.context["company_id"]
)
asset_form = Form(
self.env["account.asset"].with_context(
create_asset_from_move_line=True, move_id=move.id
)
)
for key, val in vals.items():
setattr(asset_form, key, val)
asset = asset_form.save()
asset.analytic_tag_ids = aml.analytic_tag_ids
aml.with_context(allow_asset=True).asset_id = asset.id
refs = [
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"

View File

@@ -721,3 +721,32 @@ class TestAssetManagement(SavepointCase):
[(group_tfa.id, "Tangible Fixed A...")],
)
self.assertFalse(self.env["account.asset.group"]._name_search("stessA dexiF"))
def test_16_use_number_of_depreciations(self):
# When you run a depreciation with method = 'number'
profile = self.env.ref("account_asset_management.account_asset_profile_car_5Y")
profile.method_time = "number"
asset = self.asset_model.create(
{
"name": "test asset",
"profile_id": profile.id,
"purchase_value": 10000,
"salvage_value": 0,
"date_start": time.strftime("2019-01-01"),
"method_time": "year",
"method_number": 5,
"method_period": "month",
"prorata": False,
"days_calc": False,
"use_leap_years": False,
}
)
asset.compute_depreciation_board()
asset.refresh()
for _i in range(1, 11):
self.assertAlmostEqual(
asset.depreciation_line_ids[1].amount, 166.67, places=2
)
# In the last month of the fiscal year we compensate for the small
# deviations if that is necessary.
self.assertAlmostEqual(asset.depreciation_line_ids[12].amount, 166.63, places=2)