Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
web_quick_start_screen/models/__init__.py
Executable file
3
web_quick_start_screen/models/__init__.py
Executable file
@@ -0,0 +1,3 @@
|
||||
from . import quick_start_screen
|
||||
from . import quick_start_screen_action
|
||||
from . import res_users
|
||||
68
web_quick_start_screen/models/quick_start_screen.py
Executable file
68
web_quick_start_screen/models/quick_start_screen.py
Executable file
@@ -0,0 +1,68 @@
|
||||
# Copyright 2024 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models, tools
|
||||
|
||||
|
||||
class QuicktStartScreen(models.Model):
|
||||
_name = "quick.start.screen"
|
||||
_description = "Quick action selection screen"
|
||||
|
||||
name = fields.Char(translate=True)
|
||||
action_ids = fields.Many2many(comodel_name="quick.start.screen.action")
|
||||
|
||||
@api.model
|
||||
@tools.ormcache("frozenset(self.env.user.groups_id.ids)")
|
||||
def _visible_action_ids(self):
|
||||
"""Inspired on how menus visibility work in core"""
|
||||
screen_actions = self.action_ids.search([]).sudo()
|
||||
visible = self.action_ids.browse()
|
||||
access = self.env["ir.model.access"]
|
||||
MODEL_BY_TYPE = {
|
||||
"ir.actions.act_window": "res_model",
|
||||
"ir.actions.report": "model",
|
||||
"ir.actions.server": "model_name",
|
||||
}
|
||||
# performance trick: determine the ids to prefetch by type
|
||||
prefetch_ids = defaultdict(list)
|
||||
for action in screen_actions.mapped("action_ref_id"):
|
||||
prefetch_ids[action._name].append(action.id)
|
||||
for screen_action in screen_actions:
|
||||
action = screen_action.action_ref_id
|
||||
action = action.with_prefetch(prefetch_ids[action._name])
|
||||
model_name = (
|
||||
action._name in MODEL_BY_TYPE and action[MODEL_BY_TYPE[action._name]]
|
||||
)
|
||||
if not model_name or access.check(model_name, "read", False):
|
||||
visible += screen_action
|
||||
return set(visible.ids)
|
||||
|
||||
def _prepare_screen_action(self):
|
||||
return {
|
||||
"display_name": self.name or self.env._("Start"),
|
||||
"name": self.name or self.env._("Start"),
|
||||
"res_model": "quick.start.screen.action",
|
||||
"target": "current",
|
||||
"type": "ir.actions.act_window",
|
||||
"view_mode": "kanban",
|
||||
"views": [
|
||||
[
|
||||
self.env.ref(
|
||||
"web_quick_start_screen.quick_start_screen_action_kanban"
|
||||
).id,
|
||||
"kanban",
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
def action_screen_actions(self):
|
||||
"""Normally called from a server action"""
|
||||
if not self:
|
||||
self = self.env.user.quick_start_screen_id
|
||||
if not self:
|
||||
self = self.browse(self.env.context.get("default_quick_start_screen_id"))
|
||||
action = self._prepare_screen_action()
|
||||
visible_actions = set(self.action_ids.ids) & self._visible_action_ids()
|
||||
action["domain"] = [("id", "in", list(visible_actions))]
|
||||
return action
|
||||
69
web_quick_start_screen/models/quick_start_screen_action.py
Executable file
69
web_quick_start_screen/models/quick_start_screen_action.py
Executable file
@@ -0,0 +1,69 @@
|
||||
# Copyright 2024 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
from odoo.tools.safe_eval import datetime, safe_eval
|
||||
|
||||
|
||||
class DecontracStartScreenAction(models.Model):
|
||||
_name = "quick.start.screen.action"
|
||||
_description = "Actions to be launched from a quick start screen"
|
||||
_order = "sequence, id"
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
sequence = fields.Integer()
|
||||
name = fields.Char(required=True, translate=True)
|
||||
image = fields.Image("Start screen icon", max_width=128, max_height=128, store=True)
|
||||
icon_name = fields.Char(help="Just set the Font Awesome icon name. e.g.: fa-truck")
|
||||
color = fields.Integer(help="Choose the icon color")
|
||||
description = fields.Html(translate=True)
|
||||
action_ref_id = fields.Reference(
|
||||
selection=[
|
||||
("ir.actions.report", "ir.actions.report"),
|
||||
("ir.actions.act_window", "ir.actions.act_window"),
|
||||
("ir.actions.act_url", "ir.actions.act_url"),
|
||||
("ir.actions.server", "ir.actions.server"),
|
||||
("ir.actions.client", "ir.actions.client"),
|
||||
],
|
||||
required=True,
|
||||
)
|
||||
domain = fields.Char(
|
||||
help="Add extra domain if needed. You can use `ref('<xml_id>')` and it will be"
|
||||
"evaluated. You can also use `datetime` and `context_today` in the same way"
|
||||
"`ir.filters` do."
|
||||
)
|
||||
context = fields.Char(
|
||||
help="Add extra context if needed. You can use `ref('<xml_id>')` and it will be"
|
||||
"evaluated. You can also use `datetime` and `context_today` in the same way"
|
||||
"`ir.filters` do."
|
||||
)
|
||||
|
||||
def _safe_eval(self, expresion):
|
||||
return safe_eval(
|
||||
expresion,
|
||||
{
|
||||
"ref": lambda r: self.env.ref(r).id,
|
||||
"datetime": datetime,
|
||||
"context_today": datetime.datetime.now,
|
||||
},
|
||||
)
|
||||
|
||||
def _get_extra_context(self):
|
||||
self.ensure_one()
|
||||
return self._safe_eval(self.context or "{}")
|
||||
|
||||
def run_action(self):
|
||||
"""Execute the action. We can override the action context if needed"""
|
||||
self.ensure_one()
|
||||
action = self.action_ref_id._get_action_dict()
|
||||
if self.context:
|
||||
extra_context = self._get_extra_context()
|
||||
# We need to deal with the active_id and overwrite it if needed
|
||||
# MIG TODO: Check if this is affected
|
||||
active_id = extra_context.get("active_id", 0)
|
||||
action["context"] = dict(
|
||||
safe_eval(action.get("context", "{}"), {"active_id": active_id}),
|
||||
**extra_context,
|
||||
)
|
||||
if self.domain:
|
||||
action["domain"] = self._safe_eval(self.domain)
|
||||
return action
|
||||
9
web_quick_start_screen/models/res_users.py
Executable file
9
web_quick_start_screen/models/res_users.py
Executable file
@@ -0,0 +1,9 @@
|
||||
# Copyright 2024 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
quick_start_screen_id = fields.Many2one(comodel_name="quick.start.screen")
|
||||
Reference in New Issue
Block a user