2019-10-06 23:24:00 +02:00
|
|
|
# Copyright 2009-2020 Noviat
|
2019-08-31 12:14:51 +02:00
|
|
|
# Copyright 2019 Tecnativa - Pedro M. Baeza
|
2021-04-30 11:37:17 +02:00
|
|
|
# Copyright 2021 Tecnativa - Víctor Martínez
|
2019-08-26 21:28:27 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import api, fields, models
|
2019-10-06 23:24:00 +02:00
|
|
|
from odoo.osv import expression
|
2019-08-26 21:28:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AccountAssetGroup(models.Model):
|
2020-01-29 18:34:31 +01:00
|
|
|
_name = "account.asset.group"
|
|
|
|
_description = "Asset Group"
|
2019-10-06 23:24:00 +02:00
|
|
|
_order = "code, name"
|
2019-08-31 12:14:51 +02:00
|
|
|
_parent_store = True
|
2021-02-11 11:48:48 +01:00
|
|
|
_check_company_auto = True
|
2019-08-26 21:28:27 +02:00
|
|
|
|
2022-04-13 12:18:36 +02:00
|
|
|
name = fields.Char(size=64, required=True, index=True)
|
2019-08-31 12:14:51 +02:00
|
|
|
code = fields.Char(index=True)
|
|
|
|
parent_path = fields.Char(index=True)
|
2019-08-26 21:28:27 +02:00
|
|
|
company_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="res.company",
|
|
|
|
string="Company",
|
2019-08-31 12:14:51 +02:00
|
|
|
required=True,
|
2020-01-29 18:34:31 +01:00
|
|
|
default=lambda self: self._default_company_id(),
|
|
|
|
)
|
2019-08-26 21:28:27 +02:00
|
|
|
parent_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.asset.group",
|
|
|
|
string="Parent Asset Group",
|
|
|
|
ondelete="restrict",
|
2021-02-11 11:48:48 +01:00
|
|
|
check_company=True,
|
2020-01-29 18:34:31 +01:00
|
|
|
)
|
2019-10-06 23:24:00 +02:00
|
|
|
child_ids = fields.One2many(
|
|
|
|
comodel_name="account.asset.group",
|
|
|
|
inverse_name="parent_id",
|
|
|
|
string="Child Asset Groups",
|
2021-02-11 11:48:48 +01:00
|
|
|
check_company=True,
|
2019-10-06 23:24:00 +02:00
|
|
|
)
|
2019-08-26 21:28:27 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _default_company_id(self):
|
2020-01-29 18:37:08 +01:00
|
|
|
return self.env.company
|
2019-10-06 23:24:00 +02:00
|
|
|
|
|
|
|
def name_get(self):
|
|
|
|
result = []
|
|
|
|
params = self.env.context.get("params")
|
|
|
|
list_view = params and params.get("view_type") == "list"
|
|
|
|
short_name_len = 16
|
|
|
|
for rec in self:
|
|
|
|
if rec.code:
|
|
|
|
full_name = rec.code + " " + rec.name
|
|
|
|
short_name = rec.code
|
|
|
|
else:
|
|
|
|
full_name = rec.name
|
|
|
|
if len(full_name) > short_name_len:
|
|
|
|
short_name = full_name[:16] + "..."
|
|
|
|
else:
|
|
|
|
short_name = full_name
|
|
|
|
if list_view:
|
|
|
|
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:]
|
2021-04-30 11:37:17 +02:00
|
|
|
return self._search(
|
2019-10-06 23:24:00 +02:00
|
|
|
expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid
|
|
|
|
)
|