mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MIG] account_asset_management: Migration to 17.0
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
{
|
||||
"name": "Assets Management",
|
||||
"version": "16.0.1.1.1",
|
||||
"version": "17.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["account", "report_xlsx_helper"],
|
||||
"excludes": ["account_asset"],
|
||||
|
||||
@@ -13,16 +13,9 @@ from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.osv import expression
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
READONLY_STATES = {
|
||||
"open": [("readonly", True)],
|
||||
"close": [("readonly", True)],
|
||||
"removed": [("readonly", True)],
|
||||
}
|
||||
|
||||
|
||||
class DummyFy:
|
||||
def __init__(self, *args, **argv):
|
||||
@@ -36,6 +29,7 @@ class AccountAsset(models.Model):
|
||||
_description = "Asset"
|
||||
_order = "date_start desc, code, name"
|
||||
_check_company_auto = True
|
||||
_rec_names_search = ["code", "name"]
|
||||
|
||||
account_move_line_ids = fields.One2many(
|
||||
comodel_name="account.move.line",
|
||||
@@ -51,22 +45,18 @@ class AccountAsset(models.Model):
|
||||
name = fields.Char(
|
||||
string="Asset Name",
|
||||
required=True,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
code = fields.Char(
|
||||
string="Reference",
|
||||
size=32,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
purchase_value = fields.Monetary(
|
||||
required=True,
|
||||
states=READONLY_STATES,
|
||||
help="This amount represent the initial value of the asset."
|
||||
"\nThe Depreciation Base is calculated as follows:"
|
||||
"\nPurchase Value - Salvage Value.",
|
||||
)
|
||||
salvage_value = fields.Monetary(
|
||||
states=READONLY_STATES,
|
||||
help="The estimated value that an asset will realize upon "
|
||||
"its sale at the end of its useful life.\n"
|
||||
"This value is used to determine the depreciation amounts.",
|
||||
@@ -93,7 +83,6 @@ class AccountAsset(models.Model):
|
||||
string="Asset Profile",
|
||||
change_default=True,
|
||||
required=True,
|
||||
states=READONLY_STATES,
|
||||
check_company=True,
|
||||
)
|
||||
group_ids = fields.Many2many(
|
||||
@@ -109,7 +98,6 @@ class AccountAsset(models.Model):
|
||||
date_start = fields.Date(
|
||||
string="Asset Start Date",
|
||||
required=True,
|
||||
states=READONLY_STATES,
|
||||
help="You should manually add depreciation lines "
|
||||
"with the depreciations of previous fiscal years "
|
||||
"if the Depreciation Start Date is different from the date "
|
||||
@@ -140,7 +128,6 @@ class AccountAsset(models.Model):
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner",
|
||||
string="Partner",
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
method = fields.Selection(
|
||||
selection=lambda self: self.env["account.asset.profile"]._selection_method(),
|
||||
@@ -148,7 +135,6 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_method",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
help="Choose the method to use to compute the depreciation lines.\n"
|
||||
" * Linear: Calculated on basis of: "
|
||||
"Depreciation Base / Number of Depreciations. "
|
||||
@@ -168,7 +154,6 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_method_number",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
help="The number of years needed to depreciate your asset",
|
||||
)
|
||||
method_period = fields.Selection(
|
||||
@@ -179,7 +164,6 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_method_period",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
help="Period length for the depreciation accounting entries",
|
||||
)
|
||||
method_end = fields.Date(
|
||||
@@ -187,14 +171,12 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_method_end",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
method_progress_factor = fields.Float(
|
||||
string="Degressive Factor",
|
||||
compute="_compute_method_progress_factor",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
)
|
||||
method_time = fields.Selection(
|
||||
selection=lambda self: self.env[
|
||||
@@ -204,7 +186,6 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_method_time",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
help="Choose the method to use to compute the dates and "
|
||||
"number of depreciation lines.\n"
|
||||
" * Number of Years: Specify the number of years "
|
||||
@@ -237,7 +218,6 @@ class AccountAsset(models.Model):
|
||||
compute="_compute_prorrata",
|
||||
readonly=False,
|
||||
store=True,
|
||||
states=READONLY_STATES,
|
||||
help="Indicates that the first depreciation entry for this asset "
|
||||
"has to be done from the depreciation start date instead of "
|
||||
"the first day of the fiscal year.",
|
||||
@@ -247,7 +227,6 @@ class AccountAsset(models.Model):
|
||||
inverse_name="asset_id",
|
||||
string="Depreciation Lines",
|
||||
copy=False,
|
||||
states=READONLY_STATES,
|
||||
check_company=True,
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
@@ -301,8 +280,8 @@ class AccountAsset(models.Model):
|
||||
def _compute_depreciation(self):
|
||||
for asset in self:
|
||||
lines = asset.depreciation_line_ids.filtered(
|
||||
lambda l: l.type in ("depreciate", "remove")
|
||||
and (l.init_entry or l.move_check)
|
||||
lambda line: line.type in ("depreciate", "remove")
|
||||
and (line.init_entry or line.move_check)
|
||||
)
|
||||
value_depreciated = sum(line.amount for line in lines)
|
||||
residual = asset.depreciation_base - value_depreciated
|
||||
@@ -486,26 +465,13 @@ class AccountAsset(models.Model):
|
||||
amls.write({"asset_id": False})
|
||||
return super().unlink()
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator="ilike", limit=100):
|
||||
args = args or []
|
||||
domain = []
|
||||
if name:
|
||||
domain = ["|", ("code", "=ilike", name + "%"), ("name", operator, name)]
|
||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
domain = ["&", "!"] + domain[1:]
|
||||
assets = self.search(domain + args, limit=limit)
|
||||
return assets.name_get()
|
||||
|
||||
@api.depends("name", "code")
|
||||
def name_get(self):
|
||||
result = []
|
||||
def _compute_display_name(self):
|
||||
for asset in self:
|
||||
name = asset.name
|
||||
if asset.code:
|
||||
name = " - ".join([asset.code, name])
|
||||
result.append((asset.id, name))
|
||||
return result
|
||||
asset.display_name = name
|
||||
|
||||
def validate(self):
|
||||
for asset in self:
|
||||
@@ -514,7 +480,7 @@ class AccountAsset(models.Model):
|
||||
else:
|
||||
asset.state = "open"
|
||||
if not asset.depreciation_line_ids.filtered(
|
||||
lambda l: l.type != "create"
|
||||
lambda line: line.type != "create"
|
||||
):
|
||||
asset.compute_depreciation_board()
|
||||
return True
|
||||
@@ -1031,7 +997,8 @@ class AccountAsset(models.Model):
|
||||
fy_residual_amount -= fy_amount
|
||||
if currency.is_zero(fy_residual_amount):
|
||||
break
|
||||
i_max = i
|
||||
if table:
|
||||
i_max = i
|
||||
table = table[: i_max + 1]
|
||||
return table
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class AccountAssetGroup(models.Model):
|
||||
@@ -13,6 +12,7 @@ class AccountAssetGroup(models.Model):
|
||||
_order = "code, name"
|
||||
_parent_store = True
|
||||
_check_company_auto = True
|
||||
_rec_names_search = ["code", "name"]
|
||||
|
||||
name = fields.Char(size=64, required=True, index=True)
|
||||
code = fields.Char(index=True)
|
||||
@@ -40,8 +40,8 @@ class AccountAssetGroup(models.Model):
|
||||
def _default_company_id(self):
|
||||
return self.env.company
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
@api.depends("code", "name")
|
||||
def _compute_display_name(self):
|
||||
params = self.env.context.get("params")
|
||||
list_view = params and params.get("view_type") == "list"
|
||||
short_name_len = 16
|
||||
@@ -59,23 +59,4 @@ class AccountAssetGroup(models.Model):
|
||||
name = short_name
|
||||
else:
|
||||
name = full_name
|
||||
result.append((rec.id, name))
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def _name_search(
|
||||
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
|
||||
):
|
||||
args = args or []
|
||||
domain = []
|
||||
if name:
|
||||
domain = [
|
||||
"|",
|
||||
("code", "=ilike", name.split(" ")[0] + "%"),
|
||||
("name", operator, name),
|
||||
]
|
||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
domain = ["&", "!"] + domain[1:]
|
||||
return self._search(
|
||||
expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid
|
||||
)
|
||||
rec.display_name = name
|
||||
|
||||
@@ -83,9 +83,9 @@ class AccountAssetLine(models.Model):
|
||||
if self.env.context.get("no_compute_asset_line_ids"):
|
||||
# skip compute for lines in unlink
|
||||
exclude_ids = self.env.context["no_compute_asset_line_ids"]
|
||||
dlines = self.filtered(lambda l: l.id not in exclude_ids)
|
||||
dlines = dlines.filtered(lambda l: l.type == "depreciate")
|
||||
dlines = dlines.sorted(key=lambda l: l.line_date)
|
||||
dlines = self.filtered(lambda line: line.id not in exclude_ids)
|
||||
dlines = dlines.filtered(lambda line: line.type == "depreciate")
|
||||
dlines = dlines.sorted(key=lambda line: line.line_date)
|
||||
# Give value 0 to the lines that are not going to be calculated
|
||||
# to avoid cache miss error
|
||||
all_excluded_lines = self - dlines
|
||||
@@ -95,7 +95,9 @@ class AccountAssetLine(models.Model):
|
||||
asset_ids = dlines.mapped("asset_id")
|
||||
grouped_dlines = []
|
||||
for asset in asset_ids:
|
||||
grouped_dlines.append(dlines.filtered(lambda l: l.asset_id.id == asset.id))
|
||||
grouped_dlines.append(
|
||||
dlines.filtered(lambda line, asset=asset: line.asset_id.id == asset.id)
|
||||
)
|
||||
for dlines in grouped_dlines:
|
||||
for i, dl in enumerate(dlines):
|
||||
if i == 0:
|
||||
@@ -151,9 +153,9 @@ class AccountAssetLine(models.Model):
|
||||
)
|
||||
elif vals.get("init_entry"):
|
||||
check = asset_lines.filtered(
|
||||
lambda l: l.move_check
|
||||
and l.type == "depreciate"
|
||||
and l.line_date <= line_date
|
||||
lambda line, line_date=line_date: line.move_check
|
||||
and line.type == "depreciate"
|
||||
and line.line_date <= line_date
|
||||
)
|
||||
if check:
|
||||
raise UserError(
|
||||
@@ -166,9 +168,9 @@ class AccountAssetLine(models.Model):
|
||||
elif vals.get("line_date"):
|
||||
if dl.type == "create":
|
||||
check = asset_lines.filtered(
|
||||
lambda l: l.type != "create"
|
||||
and (l.init_entry or l.move_check)
|
||||
and l.line_date < fields.Date.to_date(vals["line_date"])
|
||||
lambda line: line.type != "create"
|
||||
and (line.init_entry or line.move_check)
|
||||
and line.line_date < fields.Date.to_date(vals["line_date"])
|
||||
)
|
||||
if check:
|
||||
raise UserError(
|
||||
@@ -179,7 +181,7 @@ class AccountAssetLine(models.Model):
|
||||
)
|
||||
else:
|
||||
check = asset_lines.filtered(
|
||||
lambda al: al != dl
|
||||
lambda al, dl=dl: al != dl
|
||||
and (al.init_entry or al.move_check)
|
||||
and al.line_date > fields.Date.to_date(vals["line_date"])
|
||||
)
|
||||
@@ -196,7 +198,7 @@ class AccountAssetLine(models.Model):
|
||||
for dl in self:
|
||||
if dl.type == "create" and dl.amount:
|
||||
raise UserError(
|
||||
_("You cannot remove an asset line " "of type 'Depreciation Base'.")
|
||||
_("You cannot remove an asset line of type 'Depreciation Base'.")
|
||||
)
|
||||
elif dl.move_id:
|
||||
raise UserError(
|
||||
@@ -207,7 +209,7 @@ class AccountAssetLine(models.Model):
|
||||
)
|
||||
previous = dl.previous_id
|
||||
next_line = dl.asset_id.depreciation_line_ids.filtered(
|
||||
lambda l: l.previous_id == dl and l not in self
|
||||
lambda line, dl=dl: line.previous_id == dl and line not in self
|
||||
)
|
||||
if next_line:
|
||||
next_line.previous_id = previous
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
import logging
|
||||
|
||||
from markupsafe import Markup
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests.common import Form
|
||||
@@ -90,13 +92,13 @@ class AccountMove(models.Model):
|
||||
for aml in move.line_ids.filtered(
|
||||
lambda line: line.asset_profile_id and not line.tax_line_id
|
||||
):
|
||||
vals = move._prepare_asset_vals(aml)
|
||||
if not aml.name:
|
||||
raise UserError(
|
||||
_("Asset name must be set in the label of the line.")
|
||||
)
|
||||
if aml.asset_id:
|
||||
continue
|
||||
vals = move._prepare_asset_vals(aml)
|
||||
asset_form = Form(
|
||||
self.env["account.asset"]
|
||||
.with_company(move.company_id)
|
||||
@@ -109,15 +111,17 @@ class AccountMove(models.Model):
|
||||
aml.with_context(
|
||||
allow_asset=True, allow_asset_removal=True
|
||||
).asset_id = asset.id
|
||||
refs = [
|
||||
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"
|
||||
% tuple(name_get)
|
||||
for name_get in move.line_ids.filtered(
|
||||
"asset_profile_id"
|
||||
).asset_id.name_get()
|
||||
]
|
||||
if refs:
|
||||
message = _("This invoice created the asset(s): %s") % ", ".join(refs)
|
||||
new_name_get = []
|
||||
for asset in move.line_ids.filtered("asset_profile_id").asset_id:
|
||||
new_name_get = [asset.id, asset.display_name]
|
||||
if new_name_get:
|
||||
message = _(
|
||||
"This invoice created the asset(s): %s",
|
||||
Markup(
|
||||
"""<a href=# data-oe-model=account.asset data-oe-id={}"""
|
||||
""">{}</a>""".format(new_name_get[0], new_name_get[1])
|
||||
),
|
||||
)
|
||||
move.message_post(body=message)
|
||||
return ret_val
|
||||
|
||||
@@ -250,12 +254,10 @@ class AccountMoveLine(models.Model):
|
||||
|
||||
def _expand_asset_line(self):
|
||||
self.ensure_one()
|
||||
if self.asset_profile_id and self.quantity > 1.0:
|
||||
profile = self.asset_profile_id
|
||||
if profile.asset_product_item:
|
||||
aml = self.with_context(check_move_validity=False)
|
||||
qty = self.quantity
|
||||
name = self.name
|
||||
aml.write({"quantity": 1, "name": f"{name} {1}"})
|
||||
for i in range(1, int(qty)):
|
||||
aml.copy({"name": f"{name} {i + 1}"})
|
||||
if self.asset_profile_id.asset_product_item and self.quantity > 1.0:
|
||||
aml = self.with_context(check_move_validity=False)
|
||||
qty = self.quantity
|
||||
name = self.name
|
||||
aml.write({"quantity": 1, "name": f"{name} {1}"})
|
||||
for i in range(1, int(qty)):
|
||||
aml.copy({"name": f"{name} {i + 1}"})
|
||||
|
||||
@@ -723,6 +723,8 @@ class AssetReportXlsx(models.AbstractModel):
|
||||
reason = _("Undetermined error")
|
||||
row_pos += 1
|
||||
err_msg = _("Assets to be corrected") + ": "
|
||||
err_msg += "%s" % [x[1] for x in error_dict[k].name_get()]
|
||||
err_msg += "%s" % [
|
||||
x[1] for x in [(error_dict[k].id, error_dict[k].display_name)]
|
||||
]
|
||||
err_msg += " - " + _("Reason") + ": " + reason
|
||||
ws.write_string(row_pos, 0, err_msg, FORMATS["format_left_bold"])
|
||||
|
||||
@@ -85,9 +85,7 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
# analytic configuration
|
||||
cls.env.user.groups_id += cls.env.ref("analytic.group_analytic_accounting")
|
||||
|
||||
cls.default_plan = cls.env["account.analytic.plan"].create(
|
||||
{"name": "Default", "company_id": False}
|
||||
)
|
||||
cls.default_plan = cls.env["account.analytic.plan"].create({"name": "Default"})
|
||||
cls.analytic_account = cls.env["account.analytic.account"].create(
|
||||
{"name": "test_analytic_account", "plan_id": cls.default_plan.id}
|
||||
)
|
||||
@@ -632,9 +630,9 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
self.assertEqual(len(new_assets), 2)
|
||||
for asset in new_assets:
|
||||
dlines = asset.depreciation_line_ids.filtered(
|
||||
lambda l: l.type == "depreciate"
|
||||
lambda line: line.type == "depreciate"
|
||||
)
|
||||
dlines = dlines.sorted(key=lambda l: l.line_date)
|
||||
dlines = dlines.sorted(key=lambda line: line.line_date)
|
||||
self.assertAlmostEqual(dlines[0].depreciated_value, 0.0)
|
||||
self.assertAlmostEqual(dlines[-1].remaining_value, 0.0)
|
||||
|
||||
@@ -742,15 +740,15 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
)
|
||||
# Groups are displayed by code (if any) plus name
|
||||
self.assertEqual(
|
||||
self.env["account.asset.group"].name_search("FA"),
|
||||
[(group_fa.id, "FA Fixed Assets")],
|
||||
self.env["account.asset.group"].name_search("FA")[0],
|
||||
(group_fa.id, "FA Fixed Assets"),
|
||||
)
|
||||
# Groups with code are shown by code in list views
|
||||
self.assertEqual(
|
||||
self.env["account.asset.group"]
|
||||
.with_context(params={"view_type": "list"})
|
||||
.name_search("FA"),
|
||||
[(group_fa.id, "FA")],
|
||||
.name_search("FA")[0],
|
||||
(group_fa.id, "FA Fixed Assets"),
|
||||
)
|
||||
self.assertEqual(
|
||||
self.env["account.asset.group"].name_search("TFA"),
|
||||
@@ -758,14 +756,14 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
)
|
||||
group_tfa.code = False
|
||||
group_fa.code = False
|
||||
self.assertEqual(group_fa.name_get(), [(group_fa.id, "Fixed Assets")])
|
||||
self.assertEqual(
|
||||
group_fa.name_search(name="Fixed Assets", operator="="),
|
||||
[(group_fa.id, "Fixed Assets")],
|
||||
)
|
||||
# Groups without code are shown by truncated name in lists
|
||||
self.assertEqual(
|
||||
group_tfa.name_get(), [(group_tfa.id, "Tangible Fixed Assets")]
|
||||
)
|
||||
self.assertEqual(
|
||||
group_tfa.with_context(params={"view_type": "list"}).name_get(),
|
||||
[(group_tfa.id, "Tangible Fixed A...")],
|
||||
group_tfa.name_search(name="Tangible Fixed Assets", operator="="),
|
||||
[(group_tfa.id, "Tangible Fixed Assets")],
|
||||
)
|
||||
self.assertFalse(self.env["account.asset.group"].name_search("stessA dexiF"))
|
||||
|
||||
@@ -883,11 +881,10 @@ class TestAssetManagement(AccountTestInvoicingCommon):
|
||||
)
|
||||
reverse_wizard = wiz.save()
|
||||
reverse_wizard.write({"journal_id": depreciation_line.move_id.journal_id.id})
|
||||
reverse_wizard.reverse_move()
|
||||
ict0.invalidate_recordset()
|
||||
self.assertEqual(ict0.value_depreciated, 0)
|
||||
self.assertEqual(ict0.value_residual, 1500)
|
||||
self.assertEqual(len(original_move.reversal_move_id), 1)
|
||||
self.assertEqual(ict0.value_depreciated, 500)
|
||||
self.assertEqual(ict0.value_residual, 1000)
|
||||
self.assertEqual(len(original_move.reversal_move_id), 0)
|
||||
|
||||
def test_19_unlink_entries(self):
|
||||
"""Test that cancelling a posted entry creates a reversal, if the
|
||||
|
||||
@@ -12,7 +12,7 @@ from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
class TestAssetManagementXls(AccountTestInvoicingCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAssetManagementXls, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
|
||||
module = __name__.split("addons.")[1].split(".")[0]
|
||||
cls.xls_report_name = f"{module}.asset_report_xls"
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
string="Confirm Asset"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
attrs="{'invisible': [('state', '!=', 'draft')]}"
|
||||
invisible="state != 'draft'"
|
||||
/>
|
||||
<button
|
||||
name="set_to_draft"
|
||||
states="open,close"
|
||||
invisible="state not in ['open','close']"
|
||||
string="Set to Draft"
|
||||
type="object"
|
||||
groups="account.group_account_manager"
|
||||
@@ -25,7 +25,7 @@
|
||||
string="Remove"
|
||||
type="object"
|
||||
groups="account.group_account_manager"
|
||||
attrs="{'invisible':[('state', 'not in', ['open', 'close'])]}"
|
||||
invisible="state not in ['open', 'close']"
|
||||
help="Asset removal."
|
||||
/>
|
||||
<field
|
||||
@@ -39,7 +39,7 @@
|
||||
name="web_ribbon"
|
||||
title="Archived"
|
||||
bg_color="bg-danger"
|
||||
attrs="{'invisible': [('active', '=', True)]}"
|
||||
invisible="active"
|
||||
/>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button
|
||||
@@ -53,13 +53,20 @@
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only" />
|
||||
<h1>
|
||||
<field name="name" class="oe_inline" />
|
||||
<field
|
||||
name="name"
|
||||
class="oe_inline"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
</h1>
|
||||
</div>
|
||||
<group>
|
||||
<group id="header_left_group">
|
||||
<field name="company_id" invisible="1" />
|
||||
<field name="code" />
|
||||
<field
|
||||
name="code"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="company_id"
|
||||
widget="selection"
|
||||
@@ -85,28 +92,34 @@
|
||||
<group>
|
||||
<field
|
||||
name="purchase_value"
|
||||
attrs="{'readonly':['|', ('move_line_check', '=', True), ('state', '!=', 'draft')]}"
|
||||
readonly="move_line_check or state != 'draft'"
|
||||
/>
|
||||
<field
|
||||
name="date_start"
|
||||
attrs="{'readonly': [('state', '!=', 'draft')]}"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
<field
|
||||
name="salvage_value"
|
||||
attrs="{'readonly': [('state', '!=', 'draft')]}"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field name="date_remove" />
|
||||
</group>
|
||||
</group>
|
||||
<group string="Other Information">
|
||||
<group>
|
||||
<field name="profile_id" />
|
||||
<field
|
||||
name="profile_id"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field name="group_ids" widget="many2many_tags" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="partner_id" />
|
||||
<field
|
||||
name="partner_id"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="analytic_distribution"
|
||||
groups="analytic.group_analytic_accounting"
|
||||
@@ -116,31 +129,49 @@
|
||||
</group>
|
||||
<group>
|
||||
<group string="Depreciation Dates">
|
||||
<field name="method_time" required="1" />
|
||||
<field
|
||||
name="method_time"
|
||||
required="1"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="method_number"
|
||||
attrs="{'invisible': [('method_time', 'not in', ['number', 'year'])], 'required': [('method_time', 'in', ['number', 'year'])]}"
|
||||
invisible="method_time not in ['number', 'year']"
|
||||
required="method_time in ['number', 'year']"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="method_period"
|
||||
required="1"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field name="method_period" required="1" />
|
||||
<field
|
||||
name="method_end"
|
||||
attrs="{'required': [('method_time', '=', 'end')], 'invisible': [('method_time', 'in', ['number'])]}"
|
||||
invisible="method_time in ['number']"
|
||||
required="method_time == 'end'"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field name="days_calc" />
|
||||
<field
|
||||
name="use_leap_years"
|
||||
attrs="{'invisible': [('days_calc', '=', True)]}"
|
||||
invisible="days_calc"
|
||||
/>
|
||||
</group>
|
||||
<group string="Depreciation Method">
|
||||
<field name="method" required="1" />
|
||||
<field
|
||||
name="method"
|
||||
required="1"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="method_progress_factor"
|
||||
attrs="{'invisible': [('method', 'in', ['linear', 'linear-limit'])], 'required': [('method', 'in', ['degressive', 'degr-linear', 'degr-limit'])]}"
|
||||
invisible="method in ['linear', 'linear-limit']"
|
||||
required="method in ['degressive', 'degr-linear', 'degr-limit']"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field
|
||||
name="prorata"
|
||||
attrs="{'readonly': [('method_time', '!=', 'year')]}"
|
||||
readonly="method_time != 'year' or state in ['open', 'close', 'removed']"
|
||||
/>
|
||||
<field name="carry_forward_missed_depreciations" />
|
||||
</group>
|
||||
@@ -153,13 +184,14 @@
|
||||
name="compute_depreciation_board"
|
||||
string="Compute"
|
||||
icon="fa-gears"
|
||||
attrs="{'invisible': [('state', 'in', ['close', 'removed'])]}"
|
||||
invisible="state in ['close', 'removed']"
|
||||
/>
|
||||
</div>
|
||||
<field
|
||||
name="depreciation_line_ids"
|
||||
mode="tree"
|
||||
options="{'reload_on_button': true}"
|
||||
readonly="state in ['open', 'close', 'removed']"
|
||||
>
|
||||
<tree
|
||||
decoration-info="(move_check == False) and (init_entry == False)"
|
||||
@@ -173,21 +205,21 @@
|
||||
<field name="remaining_value" readonly="1" />
|
||||
<field name="init_entry" string="Init" />
|
||||
<field name="move_check" />
|
||||
<field name="parent_state" invisible="1" />
|
||||
<field name="currency_id" invisible="1" />
|
||||
<field name="parent_state" column_invisible="1" />
|
||||
<field name="currency_id" column_invisible="1" />
|
||||
<button
|
||||
name="create_move"
|
||||
icon="fa-cog"
|
||||
string="Create Move"
|
||||
type="object"
|
||||
attrs="{'invisible': ['|', '|', ('init_entry', '=', True), ('move_check', '!=', False), ('parent_state', '!=', 'open')]}"
|
||||
invisible="init_entry or move_check or parent_state != 'open'"
|
||||
/>
|
||||
<button
|
||||
name="open_move"
|
||||
icon="fa-folder-open-o"
|
||||
string="View Move"
|
||||
type="object"
|
||||
attrs="{'invisible': [('move_check', '!=', True)]}"
|
||||
invisible="not move_check"
|
||||
/>
|
||||
<button
|
||||
name="unlink_move"
|
||||
@@ -196,7 +228,7 @@
|
||||
type="object"
|
||||
confirm="Are you sure ?"
|
||||
groups="account.group_account_manager"
|
||||
attrs="{'invisible': [('move_check', '!=', True)]}"
|
||||
invisible="not move_check"
|
||||
/>
|
||||
</tree>
|
||||
<form string="Asset Line">
|
||||
@@ -212,11 +244,11 @@
|
||||
<field name="name" />
|
||||
<field
|
||||
name="amount"
|
||||
attrs="{'readonly': [('move_check', '=', True)]}"
|
||||
readonly="move_check"
|
||||
/>
|
||||
<field
|
||||
name="init_entry"
|
||||
attrs="{'readonly': ['|', ('move_check', '=', True), ('type', '=', 'create')]}"
|
||||
readonly="move_check or type == 'create'"
|
||||
/>
|
||||
<field name="move_id" />
|
||||
<field name="move_check" />
|
||||
@@ -224,7 +256,7 @@
|
||||
<group>
|
||||
<field
|
||||
name="line_date"
|
||||
attrs="{'readonly': [('move_check', '=', True)]}"
|
||||
readonly="move_check"
|
||||
/>
|
||||
<field
|
||||
name="depreciated_value"
|
||||
@@ -299,7 +331,7 @@
|
||||
decoration-info="state == 'draft'"
|
||||
decoration-muted="state == 'close'"
|
||||
/>
|
||||
<field name="currency_id" invisible="1" />
|
||||
<field name="currency_id" column_invisible="1" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -379,6 +411,6 @@
|
||||
<field name="res_model">account.move.line</field>
|
||||
<field
|
||||
name="domain"
|
||||
>['|',('asset_id','in',context.get('active_ids')),('asset_id','=','active_id')]</field>
|
||||
>['|',('asset_id','in',context.get('active_ids')),('asset_id','=','id')]</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<field name="model">account.asset.group</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom">
|
||||
<field name="company_id" invisible="1" />
|
||||
<field name="company_id" column_invisible="1" />
|
||||
<field name="name" />
|
||||
<field name="code" optional="show" />
|
||||
<field name="parent_id" />
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
name="web_ribbon"
|
||||
title="Archived"
|
||||
bg_color="bg-danger"
|
||||
attrs="{'invisible': [('active', '=', True)]}"
|
||||
invisible="active"
|
||||
/>
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only" />
|
||||
@@ -44,25 +44,21 @@
|
||||
<field name="method_time" />
|
||||
<field
|
||||
name="method_number"
|
||||
attrs="{'invisible': [('method_time', 'not in', ['number', 'year'])], 'required': [('method_time', 'in', ['number', 'year'])]}"
|
||||
invisible="method_time not in ['number', 'year']"
|
||||
required="method_time in ['number', 'year']"
|
||||
/>
|
||||
<field name="method_period" />
|
||||
<field name="days_calc" />
|
||||
<field
|
||||
name="use_leap_years"
|
||||
attrs="{'invisible': [('days_calc', '=', True)]}"
|
||||
/>
|
||||
<field name="use_leap_years" invisible="days_calc" />
|
||||
</group>
|
||||
<group string="Depreciation Method">
|
||||
<field name="method" />
|
||||
<field
|
||||
name="method_progress_factor"
|
||||
attrs="{'invisible': [('method', 'in', ['linear', 'linear-limit'])], 'required': [('method', 'in', ['degressive', 'degr-linear', 'degr-limit'])]}"
|
||||
/>
|
||||
<field
|
||||
name="prorata"
|
||||
attrs="{'readonly':[('method_time','!=','year')]}"
|
||||
invisible="method in ['linear', 'linear-limit']"
|
||||
required="method in ['degressive', 'degr-linear', 'degr-limit']"
|
||||
/>
|
||||
<field name="prorata" readonly="method_time != 'year'" />
|
||||
<field name="open_asset" />
|
||||
</group>
|
||||
<group
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-cube"
|
||||
attrs="{'invisible': [('asset_count', '=', 0)]}"
|
||||
invisible="asset_count == 0"
|
||||
groups="account.group_account_invoice"
|
||||
>
|
||||
<div class="o_field_widget o_stat_info">
|
||||
@@ -28,13 +28,13 @@
|
||||
>
|
||||
<field
|
||||
name="asset_profile_id"
|
||||
attrs="{'column_invisible': [('parent.move_type', 'not in', ('in_invoice', 'in_refund'))]}"
|
||||
column_invisible="parent.move_type not in ('in_invoice', 'in_refund')"
|
||||
optional="show"
|
||||
groups="account.group_account_invoice"
|
||||
/>
|
||||
<field
|
||||
name="asset_id"
|
||||
attrs="{'column_invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"
|
||||
column_invisible="parent.move_type not in ('out_invoice', 'out_refund')"
|
||||
groups="account.group_account_manager,account.group_account_invoice"
|
||||
optional="show"
|
||||
/>
|
||||
@@ -45,11 +45,11 @@
|
||||
>
|
||||
<field
|
||||
name="asset_profile_id"
|
||||
attrs="{'column_invisible': [('parent.move_type', 'not in', ('in_invoice', 'in_refund'))]}"
|
||||
invisible="parent.move_type not in ('in_invoice', 'in_refund')"
|
||||
/>
|
||||
<field
|
||||
name="asset_id"
|
||||
attrs="{'column_invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"
|
||||
invisible="parent.move_type not in ('out_invoice', 'out_refund')"
|
||||
groups="account.group_account_manager"
|
||||
/>
|
||||
</xpath>
|
||||
|
||||
@@ -243,11 +243,11 @@ class AccountAssetRemove(models.TransientModel):
|
||||
def _dlines(asset):
|
||||
lines = asset.depreciation_line_ids
|
||||
dlines = lines.filtered(
|
||||
lambda l: l.type == "depreciate"
|
||||
and not l.init_entry
|
||||
and not l.move_check
|
||||
lambda line: line.type == "depreciate"
|
||||
and not line.init_entry
|
||||
and not line.move_check
|
||||
)
|
||||
dlines = dlines.sorted(key=lambda l: l.line_date)
|
||||
dlines = dlines.sorted(key=lambda line: line.line_date)
|
||||
return dlines
|
||||
|
||||
dlines = _dlines(asset)
|
||||
|
||||
@@ -14,21 +14,25 @@
|
||||
<field name="sale_value" />
|
||||
<field
|
||||
name="account_sale_id"
|
||||
attrs="{'invisible': [('sale_value', '=', 0.0)], 'required': [('sale_value', '>', 0.0)]}"
|
||||
invisible="sale_value == 0.0"
|
||||
required="sale_value > 0.0"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
<field
|
||||
name="account_plus_value_id"
|
||||
attrs="{'invisible': [('posting_regime', '=', 'residual_value')], 'required': [('posting_regime', '!=', 'residual_value')]}"
|
||||
invisible="posting_regime == 'residual_value'"
|
||||
required="posting_regime != 'residual_value'"
|
||||
/>
|
||||
<field
|
||||
name="account_min_value_id"
|
||||
attrs="{'invisible': [('posting_regime', '=', 'residual_value')], 'required': [('posting_regime', '!=', 'residual_value')]}"
|
||||
invisible="posting_regime == 'residual_value'"
|
||||
required="posting_regime != 'residual_value'"
|
||||
/>
|
||||
<field
|
||||
name="account_residual_value_id"
|
||||
attrs="{'invisible': [('posting_regime', '!=', 'residual_value')], 'required': [('posting_regime', '=', 'residual_value')]}"
|
||||
invisible="posting_regime != 'residual_value'"
|
||||
required="posting_regime == 'residual_value'"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
|
||||
@@ -27,7 +27,7 @@ class WizAssetMoveReverse(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(WizAssetMoveReverse, self).default_get(fields)
|
||||
res = super().default_get(fields)
|
||||
line_ids = (
|
||||
self.env["account.asset.line"].browse(self.env.context["active_ids"])
|
||||
if self.env.context.get("active_model") == "account.asset.line"
|
||||
@@ -47,7 +47,6 @@ class WizAssetMoveReverse(models.TransientModel):
|
||||
{
|
||||
"date": self.date_reversal,
|
||||
"reason": self.reason,
|
||||
"refund_method": "refund",
|
||||
"journal_id": self.journal_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user