diff --git a/board_eval_context/README.rst b/board_eval_context/README.rst new file mode 100644 index 000000000..81d23d3bc --- /dev/null +++ b/board_eval_context/README.rst @@ -0,0 +1,80 @@ +================== +Board Eval Context +================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/15.0/board_eval_context + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-15-0/server-ux-15-0-board_eval_context + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/250/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds some useful keys in the evaluation context of board.board +records, which can be useful when creating generic boards for all the users of +an instance. + +At the moment it allows using the following values in the domains of a board.board record: + +* datetime: the datetime.datetime class +* date: the datetime.date class +* timedelta: the datetime.timedelta class +* timezone: the datetime.timezone class +* tzinfo: the datetime.tzinfo class +* relativedelta: the dateutil.relativedelta.relativedelta class +* uid: the ID of the current user + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/board_eval_context/__init__.py b/board_eval_context/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/board_eval_context/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/board_eval_context/__manifest__.py b/board_eval_context/__manifest__.py new file mode 100644 index 000000000..4b7834117 --- /dev/null +++ b/board_eval_context/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Board Eval Context", + "summary": "Add some keys to board.board eval context", + "version": "15.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainer": "gurneyalex", + "depends": [ + "board", + ], + "category": "Extra Tools", + "website": "https://github.com/OCA/reporting-engine", + "installable": True, + "auto_install": False, + "license": "AGPL-3", + "application": False, + "development_status": "Alpha", + "maintainers": ["gurneyalex"], +} diff --git a/board_eval_context/models/__init__.py b/board_eval_context/models/__init__.py new file mode 100644 index 000000000..21c6aa151 --- /dev/null +++ b/board_eval_context/models/__init__.py @@ -0,0 +1 @@ +from . import board_board diff --git a/board_eval_context/models/board_board.py b/board_eval_context/models/board_board.py new file mode 100644 index 000000000..8261b89ab --- /dev/null +++ b/board_eval_context/models/board_board.py @@ -0,0 +1,48 @@ +# Copyright 2021-2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import datetime + +from dateutil.relativedelta import relativedelta + +from odoo import api, models +from odoo.tools.safe_eval import safe_eval + + +class Board(models.AbstractModel): + _inherit = "board.board" + + def _get_eval_context(self): + """Prepare the context used when evaluating python code + :returns: dict -- evaluation context given to safe_eval + """ + return { + "datetime": datetime.datetime, + "date": datetime.date, + "timedelta": datetime.timedelta, + "timezone": datetime.timezone, + "tzinfo": datetime.tzinfo, + "relativedelta": relativedelta, + "uid": self.env.uid, + } + + @api.model + def _arch_preprocessing(self, arch): + # keeping it inside the method as in the + # original code, for perf reason at startup + from lxml import etree + + arch = super()._arch_preprocessing(arch) + eval_context = self._get_eval_context() + + def fix_domain(node): + for child in node.iterchildren(): + if child.tag == "action" and child.get("domain"): + domain = safe_eval(child.get("domain"), eval_context) + child.set("domain", str(domain)) + else: + fix_domain(child) + return node + + archnode = etree.fromstring(arch) + archnode = fix_domain(archnode) + return etree.tostring(archnode, pretty_print=True, encoding="unicode") diff --git a/board_eval_context/readme/DESCRIPTION.rst b/board_eval_context/readme/DESCRIPTION.rst new file mode 100644 index 000000000..702a02a6b --- /dev/null +++ b/board_eval_context/readme/DESCRIPTION.rst @@ -0,0 +1,13 @@ +This module adds some useful keys in the evaluation context of board.board +records, which can be useful when creating generic boards for all the users of +an instance. + +At the moment it allows using the following values in the domains of a board.board record: + +* datetime: the datetime.datetime class +* date: the datetime.date class +* timedelta: the datetime.timedelta class +* timezone: the datetime.timezone class +* tzinfo: the datetime.tzinfo class +* relativedelta: the dateutil.relativedelta.relativedelta class +* uid: the ID of the current user diff --git a/board_eval_context/static/description/index.html b/board_eval_context/static/description/index.html new file mode 100644 index 000000000..5a0fb5d06 --- /dev/null +++ b/board_eval_context/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Board Eval Context + + + +
+

Board Eval Context

+ + +

Beta License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runbot

+

This module adds some useful keys in the evaluation context of board.board +records, which can be useful when creating generic boards for all the users of +an instance.

+

At the moment it allows using the following values in the domains of a board.board record:

+
    +
  • datetime: the datetime.datetime class
  • +
  • date: the datetime.date class
  • +
  • timedelta: the datetime.timedelta class
  • +
  • timezone: the datetime.timezone class
  • +
  • tzinfo: the datetime.tzinfo class
  • +
  • relativedelta: the dateutil.relativedelta.relativedelta class
  • +
  • uid: the ID of the current user
  • +
+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/setup/board_eval_context/odoo/addons/board_eval_context b/setup/board_eval_context/odoo/addons/board_eval_context new file mode 120000 index 000000000..100441886 --- /dev/null +++ b/setup/board_eval_context/odoo/addons/board_eval_context @@ -0,0 +1 @@ +../../../../board_eval_context \ No newline at end of file diff --git a/setup/board_eval_context/setup.py b/setup/board_eval_context/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/board_eval_context/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)