Initial commit: Odoo 18.0-20251222 extra-addons
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled

This commit is contained in:
tocmo0nlord
2026-03-13 20:43:25 +00:00
parent 36e847a7df
commit adbe430761
9472 changed files with 1265727 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from . import account_asset
from . import account_asset_line
from . import account_move_line

View File

@@ -0,0 +1,72 @@
# Copyright 2024 Bernat Obrador(APSL-Nagarro)<bobrador@apsl.net>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class AccountAsset(models.Model):
_inherit = "account.asset"
account_asset_id = fields.Many2one(
comodel_name="account.account",
string="Asset Account",
compute="_compute_account_asset_id",
help="The account used to record the value of the asset.",
store=True,
)
account_depreciation_id = fields.Many2one(
comodel_name="account.account",
string="Depreciation Account",
domain="[('deprecated', '=', False), ('company_ids', '=', company_id)]",
help="The account used to record depreciation for the asset.",
required=True,
)
account_expense_depreciation_id = fields.Many2one(
comodel_name="account.account",
string="Depreciation Expense Account",
domain="[('deprecated', '=', False), ('company_ids', '=', company_id)]",
help="The account used to record the expense of the depreciation.",
required=True,
)
@api.onchange("profile_id")
def _onchange_profile_id(self):
# To avoid changes when the asset is confirmed
if self.profile_id and self.state == "draft":
self.account_depreciation_id = self.profile_id.account_depreciation_id
self.account_expense_depreciation_id = (
self.profile_id.account_expense_depreciation_id
)
self._compute_account_asset_id()
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("profile_id"):
profile = self.env["account.asset.profile"].browse(vals["profile_id"])
if not vals.get("account_depreciation_id"):
vals["account_depreciation_id"] = profile.account_depreciation_id.id
if not vals.get("account_expense_depreciation_id"):
vals["account_expense_depreciation_id"] = (
profile.account_expense_depreciation_id.id
)
return super().create(vals_list)
@api.depends("account_move_line_ids", "profile_id")
def _compute_account_asset_id(self):
for record in self:
# Cannot update the account_asset_id if the asset is not in draft state
if record.state != "draft":
continue
# Looks if the asset comes from an invoice, if so, takes the account
# from the invoice
if len(record.account_move_line_ids.account_id) != 0:
invoice_line = record.account_move_line_ids.filtered(
lambda line: line.move_id.move_type == "in_invoice"
)
if invoice_line:
record.account_asset_id = invoice_line.account_id
continue
# If not, takes the account from the profile
record.account_asset_id = record.profile_id.account_asset_id

View File

@@ -0,0 +1,17 @@
# Copyright 2024 Bernat Obrador(APSL-Nagarro)<bobrador@apsl.net>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountAssetLine(models.Model):
_inherit = "account.asset.line"
def _setup_move_line_data(self, depreciation_date, account, ml_type, move):
res = super()._setup_move_line_data(depreciation_date, account, ml_type, move)
asset = self.asset_id
if ml_type == "depreciation" and asset.account_depreciation_id:
res["account_id"] = asset.account_depreciation_id.id
if ml_type == "expense" and asset.account_expense_depreciation_id:
res["account_id"] = asset.account_expense_depreciation_id.id
return res

View File

@@ -0,0 +1,13 @@
# Copyright 2024 Bernat Obrador(APSL-Nagarro)<bobrador@apsl.net>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
@api.onchange("asset_profile_id")
def _onchange_asset_profile_id(self):
if self.account_id and self.account_id.account_type == "asset_fixed":
return
super()._onchange_asset_profile_id()