Skip to content
Snippets Groups Projects
Commit e8c56976 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: Initial version

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #5842 failed
include:
- project: xcg/ci-templates
file: /odoo/11.0/gitlab-ci.yaml
This diff is collapsed.
Changelog
=========
1.0
---
Initial version.
==================
Base Clean Context
==================
Provide a get_clean_context method on objects.
\ No newline at end of file
from .hooks import post_load # noqa: F401
##############################################################################
#
# Base Clean Context, for Odoo
# Copyright (C) 2020 XCG Consulting <https://xcg-consulting.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Base Clean Context",
"license": "AGPL-3",
"summary": "Provide clean context method on models",
"version": "11.0.1.0",
"category": "Technical",
"author": "XCG Consulting",
"website": "https://xcg-consulting.fr/",
"depends": ["base"],
"installable": True,
"post_load": "post_load",
}
hooks.py 0 → 100644
##############################################################################
#
# Base Clean Context, for Odoo
# Copyright (C) 2020 XCG Consulting <https://xcg-consulting.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from typing import Dict
from odoo import api
from odoo.models import BaseModel
def patch_base_model():
"""Add methods to the base model so they are available with a simple
self.get_clean_context()"""
@api.multi
def get_clean_context(self) -> Dict[str]:
"""Remove cruft from the Odoo context.
Useful when returning view display actions.
"""
return {
key: value
for key, value in self.env.context.items()
if (
not key.startswith("default_")
and not key.startswith("search_default_")
and key not in ("form_view_ref", "group_by", "tree_view_ref")
)
}
BaseModel.get_clean_context = get_clean_context
def post_load():
patch_base_model()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment