Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
account_asset_transfer/models/__init__.py
Executable file
3
account_asset_transfer/models/__init__.py
Executable file
@@ -0,0 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from . import account_asset
|
||||
from . import account_asset_profile
|
||||
104
account_asset_transfer/models/account_asset.py
Executable file
104
account_asset_transfer/models/account_asset.py
Executable file
@@ -0,0 +1,104 @@
|
||||
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountAsset(models.Model):
|
||||
_inherit = "account.asset"
|
||||
|
||||
can_transfer = fields.Boolean(
|
||||
compute="_compute_can_transfer",
|
||||
search="_search_can_transfer",
|
||||
help="Allow transfer AUC (running) to Asset",
|
||||
)
|
||||
is_transfer = fields.Boolean(
|
||||
help="flag indicating if the asset has been transferred from/to another asset."
|
||||
)
|
||||
|
||||
def _compute_can_transfer(self):
|
||||
for asset in self:
|
||||
asset.can_transfer = (
|
||||
not asset.method_number
|
||||
and asset.value_residual
|
||||
and asset.state == "open"
|
||||
)
|
||||
|
||||
def _search_can_transfer(self, operator, value):
|
||||
if operator == "=":
|
||||
return [
|
||||
("method_number", "=", 0),
|
||||
("value_residual", ">", 0),
|
||||
("state", "=", "open"),
|
||||
]
|
||||
if operator == "!=":
|
||||
return [
|
||||
"|",
|
||||
"|",
|
||||
"|",
|
||||
("method_number", ">", 0),
|
||||
("value_residual", "=", 0),
|
||||
("state", "!=", "open"),
|
||||
]
|
||||
|
||||
def _check_can_transfer(self):
|
||||
if not all(self.mapped("can_transfer")):
|
||||
raise ValidationError(
|
||||
self.env._(
|
||||
"Only running assets without depreciation (AUC) can transfer"
|
||||
)
|
||||
)
|
||||
|
||||
def transfer(self):
|
||||
ctx = dict(self.env.context, active_ids=self.ids)
|
||||
self._check_can_transfer()
|
||||
return {
|
||||
"name": self.env._("Transfer AUC to Asset & Create Transfer Journal Entry"),
|
||||
"view_mode": "form",
|
||||
"res_model": "account.asset.transfer",
|
||||
"target": "new",
|
||||
"type": "ir.actions.act_window",
|
||||
"context": ctx,
|
||||
}
|
||||
|
||||
def open_assets(self):
|
||||
self.ensure_one()
|
||||
moves = self.account_move_line_ids.mapped("move_id")
|
||||
assets = self.env["account.asset"]
|
||||
asset_from = self._context.get("asset_from")
|
||||
asset_to = self._context.get("asset_to")
|
||||
for move in moves:
|
||||
# Source Assets, we check from move that create this asset
|
||||
if (
|
||||
asset_from
|
||||
and self.id
|
||||
not in move.line_ids.filtered(lambda line: line.credit)
|
||||
.mapped("asset_id")
|
||||
.ids
|
||||
):
|
||||
assets = move.line_ids.filtered(lambda line: line.credit).mapped(
|
||||
"asset_id"
|
||||
)
|
||||
break
|
||||
# Destination Assets, we check from move that create destination asset
|
||||
elif (
|
||||
asset_to
|
||||
and self.id
|
||||
in move.line_ids.filtered(lambda line: line.credit)
|
||||
.mapped("asset_id")
|
||||
.ids
|
||||
):
|
||||
assets = move.line_ids.filtered(lambda line: line.debit).mapped(
|
||||
"asset_id"
|
||||
)
|
||||
break
|
||||
return {
|
||||
"name": self.env._("Assets"),
|
||||
"view_mode": "tree,form",
|
||||
"res_model": "account.asset",
|
||||
"view_id": False,
|
||||
"type": "ir.actions.act_window",
|
||||
"context": self._context,
|
||||
"domain": [("id", "in", assets.ids)],
|
||||
}
|
||||
14
account_asset_transfer/models/account_asset_profile.py
Executable file
14
account_asset_transfer/models/account_asset_profile.py
Executable file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AccountAssetProfile(models.Model):
|
||||
_inherit = "account.asset.profile"
|
||||
|
||||
transfer_journal_id = fields.Many2one(
|
||||
comodel_name="account.journal",
|
||||
domain="[('type', '=', 'general'), ('company_id', '=', company_id)]",
|
||||
check_company=True,
|
||||
)
|
||||
Reference in New Issue
Block a user