mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-22 11:32:08 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import hr_employee
|
||||
from . import hr_employee_public
|
||||
from . import ir_rule
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# Copyright 2018 Brainbean Apps (https://brainbeanapps.com)
|
||||
# Copyright 2023 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class HrEmployeeBase(models.AbstractModel):
|
||||
_inherit = "hr.employee.base"
|
||||
|
||||
document_count = fields.Integer(
|
||||
compute="_compute_document_count",
|
||||
)
|
||||
|
||||
def _compute_document_count(self):
|
||||
self.document_count = 0
|
||||
attachment_groups = self.env["ir.attachment"].read_group(
|
||||
[("res_model", "=", "hr.employee"), ("res_id", "in", self.ids)],
|
||||
["res_id"],
|
||||
["res_id"],
|
||||
)
|
||||
count_dict = {x["res_id"]: x["res_id_count"] for x in attachment_groups}
|
||||
for record in self:
|
||||
record.document_count = count_dict.get(record.id, 0)
|
||||
|
||||
@api.model
|
||||
def check_access_rights(self, operation, raise_exception=True):
|
||||
"""Return access to the hr.employee model if we pass a specific context,
|
||||
is a trick to list the attachments related to an employee."""
|
||||
if (
|
||||
not self.env.is_superuser()
|
||||
and not self.env.user.has_group("hr.group_hr_user")
|
||||
and operation == "read"
|
||||
and self._name == "hr.employee"
|
||||
):
|
||||
if (
|
||||
self.env.context.get("search_attachments_from_hr_employee")
|
||||
or self in self.env.user.employee_ids
|
||||
):
|
||||
return True
|
||||
return super().check_access_rights(
|
||||
operation=operation, raise_exception=raise_exception
|
||||
)
|
||||
|
||||
def action_get_attachment_tree_view(self):
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id("base.action_attachment")
|
||||
action["context"] = {
|
||||
"default_res_model": self._name,
|
||||
"default_res_id": self.ids[0],
|
||||
"search_attachments_from_hr_employee": True,
|
||||
}
|
||||
action["domain"] = [("res_model", "=", self._name), ("res_id", "in", self.ids)]
|
||||
action["search_view_id"] = (
|
||||
self.env.ref("hr_employee_document.ir_attachment_view_search").id,
|
||||
)
|
||||
return action
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright 2020 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrEmployeePublic(models.Model):
|
||||
_inherit = "hr.employee.public"
|
||||
|
||||
is_logged = fields.Boolean(compute="_compute_is_logged", store=False)
|
||||
|
||||
def _compute_is_logged(self):
|
||||
self.is_logged = False
|
||||
for record in self:
|
||||
if self.env.user == record.user_id:
|
||||
record.is_logged = True
|
||||
|
||||
def action_get_attachment_tree_view(self):
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id("base.action_attachment")
|
||||
action["context"] = {
|
||||
"default_res_model": "hr.employee",
|
||||
"default_res_id": self.env.user.employee_id.id,
|
||||
"search_attachments_from_hr_employee": True,
|
||||
}
|
||||
action["domain"] = [
|
||||
("res_model", "=", "hr.employee"),
|
||||
("res_id", "=", self.env.user.employee_id.id),
|
||||
]
|
||||
action["search_view_id"] = (
|
||||
self.env.ref("hr_employee_document.ir_attachment_view_search").id,
|
||||
)
|
||||
return action
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright 2023 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import api, models, tools
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import config
|
||||
|
||||
|
||||
class IrRule(models.Model):
|
||||
_inherit = "ir.rule"
|
||||
|
||||
@api.model
|
||||
@tools.conditional(
|
||||
"xml" not in config["dev_mode"],
|
||||
tools.ormcache(
|
||||
"self.env.uid",
|
||||
"self.env.su",
|
||||
"model_name",
|
||||
"mode",
|
||||
"tuple(self._compute_domain_context_values())",
|
||||
),
|
||||
)
|
||||
def _compute_domain(self, model_name, mode="read"):
|
||||
"""We need to add for security purposes an extra domain in the hr.employee
|
||||
model to restrict only the user's employees when search employee attachments."""
|
||||
res = super()._compute_domain(model_name, mode=mode)
|
||||
user = self.env.user
|
||||
if (
|
||||
model_name == "hr.employee"
|
||||
and not self.env.su
|
||||
and not user.has_group("hr.group_hr_manager")
|
||||
and self.env.context.get("search_attachments_from_hr_employee")
|
||||
):
|
||||
extra_domain = [[("id", "in", user.employee_ids.ids)]]
|
||||
res = expression.AND(extra_domain + [res])
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue