diff --git a/setup/web_field_text_limit/odoo/addons/web_field_text_limit b/setup/web_field_text_limit/odoo/addons/web_field_text_limit new file mode 120000 index 000000000000..21ce2151cde3 --- /dev/null +++ b/setup/web_field_text_limit/odoo/addons/web_field_text_limit @@ -0,0 +1 @@ +../../../../web_field_text_limit \ No newline at end of file diff --git a/setup/web_field_text_limit/setup.py b/setup/web_field_text_limit/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_field_text_limit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_field_text_limit/README.rst b/web_field_text_limit/README.rst new file mode 100644 index 000000000000..74702afdba6d --- /dev/null +++ b/web_field_text_limit/README.rst @@ -0,0 +1,107 @@ +==================== +Web Field Text Limit +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:132960eebb3b4b035d2fadac727eaca7758c0f8b88903d12f99a2d269e69bb18 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/15.0/web_field_text_limit + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_field_text_limit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the possibility to limit the displayed length of char and text fields. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +You can change the limit applied to the text from Settings > Technical > User Interface > Text Limits + +If the limit is set to 0, no limit will be applied + +Usage +===== + +To use it in QWeb views, you need to assign the text widget in t-options if the field does not use it by +default, along with text_limit and the name of the limit to be applied. + +.. code:: xml + + + +Known issues / Roadmap +====================== + +For now, the limit is only applied to QWeb views, but the intention is to apply it to all views once the corresponding +option is added. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Carlos Dauden + * Carlos Roca + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_field_text_limit/__init__.py b/web_field_text_limit/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_field_text_limit/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_field_text_limit/__manifest__.py b/web_field_text_limit/__manifest__.py new file mode 100644 index 000000000000..7a2793b994ad --- /dev/null +++ b/web_field_text_limit/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2025 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Web Field Text Limit", + "version": "15.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "development_status": "Alpha", + "license": "AGPL-3", + "category": "Web", + "summary": "Adds an option to be able to limit displayed size of a text field", + "depends": ["base"], + "data": [ + "security/ir.model.access.csv", + "data/data.xml", + "views/text_limit_views.xml", + ], +} diff --git a/web_field_text_limit/data/data.xml b/web_field_text_limit/data/data.xml new file mode 100644 index 000000000000..b4794ee5043f --- /dev/null +++ b/web_field_text_limit/data/data.xml @@ -0,0 +1,7 @@ + + + + Journal Limit + 40 + + diff --git a/web_field_text_limit/models/__init__.py b/web_field_text_limit/models/__init__.py new file mode 100644 index 000000000000..d4db993cbdda --- /dev/null +++ b/web_field_text_limit/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_qweb_field_text +from . import text_limit diff --git a/web_field_text_limit/models/ir_qweb_field_text.py b/web_field_text_limit/models/ir_qweb_field_text.py new file mode 100644 index 000000000000..f5143c4d2219 --- /dev/null +++ b/web_field_text_limit/models/ir_qweb_field_text.py @@ -0,0 +1,20 @@ +# Copyright 2025 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from markupsafe import escape + +from odoo import api, models + +from odoo.addons.base.models.ir_qweb_fields import nl2br + + +class IrQwebFieldText(models.AbstractModel): + _inherit = "ir.qweb.field.text" + + @api.model + def value_to_html(self, value, options): + res = super().value_to_html(value, options) + if value and options.get("text_limit"): + limit = self.env["text.limit"].get_limit(options["text_limit"]) + if len(value) > limit: + res = nl2br(escape(value[:limit] + "...")) + return res diff --git a/web_field_text_limit/models/text_limit.py b/web_field_text_limit/models/text_limit.py new file mode 100644 index 000000000000..8bae5eabf5b9 --- /dev/null +++ b/web_field_text_limit/models/text_limit.py @@ -0,0 +1,45 @@ +# Copyright 2025 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models, tools + + +class TextLimit(models.Model): + _name = "text.limit" + _description = "Text Limit" + + name = fields.Char("Usage", index=True, required=True) + value = fields.Integer(required=True, default=40) + + _sql_constraints = [ + ( + "name_uniq", + "unique (name)", + """Only one value can be defined for each given usage!""", + ), + ] + + @api.model + @tools.ormcache("application") + def get_limit(self, application): + self.flush(["name", "value"]) + self.env.cr.execute( + "select value from text_limit where name=%s", (application,) + ) + res = self.env.cr.fetchone() + return res[0] if res else 2 + + @api.model_create_multi + def create(self, vals_list): + res = super().create(vals_list) + self.clear_caches() + return res + + def write(self, data): + res = super().write(data) + self.clear_caches() + return res + + def unlink(self): + res = super().unlink() + self.clear_caches() + return res diff --git a/web_field_text_limit/readme/CONFIGURE.rst b/web_field_text_limit/readme/CONFIGURE.rst new file mode 100644 index 000000000000..f11ac56c0fbe --- /dev/null +++ b/web_field_text_limit/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +You can change the limit applied to the text from Settings > Technical > User Interface > Text Limits + +If the limit is set to 0, no limit will be applied diff --git a/web_field_text_limit/readme/CONTRIBUTORS.rst b/web_field_text_limit/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..c8e772ea114b --- /dev/null +++ b/web_field_text_limit/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Dauden + * Carlos Roca diff --git a/web_field_text_limit/readme/DESCRIPTION.rst b/web_field_text_limit/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..9b56fbeac4b2 --- /dev/null +++ b/web_field_text_limit/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the possibility to limit the displayed length of char and text fields. diff --git a/web_field_text_limit/readme/ROADMAP.rst b/web_field_text_limit/readme/ROADMAP.rst new file mode 100644 index 000000000000..4f9cf83d0351 --- /dev/null +++ b/web_field_text_limit/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +For now, the limit is only applied to QWeb views, but the intention is to apply it to all views once the corresponding +option is added. diff --git a/web_field_text_limit/readme/USAGE.rst b/web_field_text_limit/readme/USAGE.rst new file mode 100644 index 000000000000..859bba228247 --- /dev/null +++ b/web_field_text_limit/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use it in QWeb views, you need to assign the text widget in t-options if the field does not use it by +default, along with text_limit and the name of the limit to be applied. + +.. code:: xml + + diff --git a/web_field_text_limit/security/ir.model.access.csv b/web_field_text_limit/security/ir.model.access.csv new file mode 100644 index 000000000000..933d6ff37ebe --- /dev/null +++ b/web_field_text_limit/security/ir.model.access.csv @@ -0,0 +1,2 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_text_limit","access_text_limit","model_text_limit","base.group_system",1,1,0,0 diff --git a/web_field_text_limit/static/description/index.html b/web_field_text_limit/static/description/index.html new file mode 100644 index 000000000000..426c7052fc46 --- /dev/null +++ b/web_field_text_limit/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +Web Field Text Limit + + + +
+

Web Field Text Limit

+ + +

Alpha License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This module adds the possibility to limit the displayed length of char and text fields.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

You can change the limit applied to the text from Settings > Technical > User Interface > Text Limits

+

If the limit is set to 0, no limit will be applied

+
+
+

Usage

+

To use it in QWeb views, you need to assign the text widget in t-options if the field does not use it by +default, along with text_limit and the name of the limit to be applied.

+
+<span t-field="name" t-options="{'text_limit': 'Journal Limit'}" />
+
+
+
+

Known issues / Roadmap

+

For now, the limit is only applied to QWeb views, but the intention is to apply it to all views once the corresponding +option is added.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Carlos Dauden
    • +
    • Carlos Roca
    • +
    +
  • +
+
+
+

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/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_field_text_limit/views/text_limit_views.xml b/web_field_text_limit/views/text_limit_views.xml new file mode 100644 index 000000000000..bfadbc0ce1bc --- /dev/null +++ b/web_field_text_limit/views/text_limit_views.xml @@ -0,0 +1,39 @@ + + + + Text Limit Form + text.limit + +
+ + + + + + +
+
+
+ + Text Limit List + text.limit + + + + + + + + + Text Limits + text.limit + + +