diff --git a/setup/web_field_reference_domain/odoo/addons/web_field_reference_domain b/setup/web_field_reference_domain/odoo/addons/web_field_reference_domain new file mode 120000 index 000000000000..272379ba3f3d --- /dev/null +++ b/setup/web_field_reference_domain/odoo/addons/web_field_reference_domain @@ -0,0 +1 @@ +../../../../web_field_reference_domain \ No newline at end of file diff --git a/setup/web_field_reference_domain/setup.py b/setup/web_field_reference_domain/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_field_reference_domain/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_field_reference_domain/README.rst b/web_field_reference_domain/README.rst new file mode 100644 index 000000000000..7b4b0db1ea08 --- /dev/null +++ b/web_field_reference_domain/README.rst @@ -0,0 +1,93 @@ +========================== +Web Field Reference Domain +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e1fc658206388842a964783e100c6442d011687ad0a692bdb83c8b5c0301e357 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/14.0/web_field_reference_domain + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_field_reference_domain + :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=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add support to define domains in reference fields + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Use the attribute ```domain_map``` to declare the field domains: + +.. code-block:: html + + + +Known issues / Roadmap +====================== + +* Add tests. +* Extends the reference field in python to allow the 'domain_map' attribute. + +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 +~~~~~~~ + +* Grupo Isonor + +Contributors +~~~~~~~~~~~~ + +* `Grupo Isonor `_: + + * Alexandre D. Díaz + +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_reference_domain/__init__.py b/web_field_reference_domain/__init__.py new file mode 100644 index 000000000000..6a294e4d7c48 --- /dev/null +++ b/web_field_reference_domain/__init__.py @@ -0,0 +1 @@ +# Copyright 2024 Alexandre D. Díaz - Grupo Isonor diff --git a/web_field_reference_domain/__manifest__.py b/web_field_reference_domain/__manifest__.py new file mode 100644 index 000000000000..ad439c286b9b --- /dev/null +++ b/web_field_reference_domain/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Alexandre D. Díaz - Grupo Isonor + +{ + "name": "Web Field Reference Domain", + "summary": "Add support to define domains on reference fields", + "version": "14.0.1.0.0", + "category": "Web", + "website": "https://github.com/OCA/web", + "author": "Grupo Isonor, Odoo Community Association (OCA)", + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": ["web"], + "data": ["templates/assets.xml"], + "demo": [], +} diff --git a/web_field_reference_domain/readme/CONTRIBUTORS.rst b/web_field_reference_domain/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..e39a0acfe5f0 --- /dev/null +++ b/web_field_reference_domain/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Grupo Isonor `_: + + * Alexandre D. Díaz diff --git a/web_field_reference_domain/readme/DESCRIPTION.rst b/web_field_reference_domain/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3d34690ea7c4 --- /dev/null +++ b/web_field_reference_domain/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add support to define domains in reference fields diff --git a/web_field_reference_domain/readme/ROADMAP.rst b/web_field_reference_domain/readme/ROADMAP.rst new file mode 100644 index 000000000000..2a1f6edbe913 --- /dev/null +++ b/web_field_reference_domain/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Add tests. +* Extends the reference field in python to allow the 'domain_map' attribute. diff --git a/web_field_reference_domain/readme/USAGE.rst b/web_field_reference_domain/readme/USAGE.rst new file mode 100644 index 000000000000..cd355f312ac2 --- /dev/null +++ b/web_field_reference_domain/readme/USAGE.rst @@ -0,0 +1,5 @@ +Use the attribute ```domain_map``` to declare the field domains: + +.. code-block:: html + + diff --git a/web_field_reference_domain/static/description/index.html b/web_field_reference_domain/static/description/index.html new file mode 100644 index 000000000000..cb0dcf7e2bb8 --- /dev/null +++ b/web_field_reference_domain/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Web Field Reference Domain + + + +
+

Web Field Reference Domain

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Add support to define domains in reference fields

+

Table of contents

+ +
+

Usage

+

Use the attribute `domain_map` to declare the field domains:

+
+<field name="reference_field" domain_map="{'model_a': [domain], 'model_n': [domain_n]}" />
+
+
+
+

Known issues / Roadmap

+
    +
  • Add tests.
  • +
  • Extends the reference field in python to allow the ‘domain_map’ attribute.
  • +
+
+
+

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

+
    +
  • Grupo Isonor
  • +
+
+
+

Contributors

+ +
+
+

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_reference_domain/static/src/js/basic_model.js b/web_field_reference_domain/static/src/js/basic_model.js new file mode 100644 index 000000000000..5054491d11bb --- /dev/null +++ b/web_field_reference_domain/static/src/js/basic_model.js @@ -0,0 +1,23 @@ +// Copyright 2024 Alexandre D. Díaz - Grupo Isonor +odoo.define("web_field_reference_domain.BasicModel", function (require) { + "use strict"; + + var BasicModel = require("web.BasicModel"); + + BasicModel.include({ + /** + * This is donde in this way to avoid do extra searchs. + * FIXME: If someday Odoo changes the implementation of the + * '_search' method in the 'Many2One', see if you can avoid + * doing this. + * + * @override + */ + _getDomain: function (element, options) { + if (options.referenceDomain) { + return options.referenceDomain; + } + return this._super(...arguments); + }, + }); +}); diff --git a/web_field_reference_domain/static/src/js/relational_fields.js b/web_field_reference_domain/static/src/js/relational_fields.js new file mode 100644 index 000000000000..29cfb2391744 --- /dev/null +++ b/web_field_reference_domain/static/src/js/relational_fields.js @@ -0,0 +1,55 @@ +/* global py */ +// Copyright 2024 Alexandre D. Díaz - Grupo Isonor +odoo.define("web_field_reference_domain.relational_fields", function (require) { + "use strict"; + + const relational_fields = require("web.relational_fields"); + + relational_fields.FieldMany2One.include({ + /** + * @override + */ + init: function () { + this._super(...arguments); + this.isReferenceField = this.field.type === "reference"; + }, + + /** + * Gets the domain for the selected model + * + * @returns {Array} + */ + _getReferenceDomain: function () { + if (Object.hasOwn(this.attrs, "domain_map")) { + const state = (this.getParent() && this.getParent().state) || {}; + const domain_map = py.eval(this.attrs.domain_map, state.evalContext); + if (Object.hasOwn(domain_map, this.field.relation)) { + return domain_map[this.field.relation]; + } + } + return []; + }, + + /** + * @override + */ + _search: async function () { + // See why this is necessary in the 'basic_model.js' file + if (this.isReferenceField) { + this.recordParams.referenceDomain = this._getReferenceDomain(); + } + return this._super(...arguments); + }, + + /** + * @override + */ + _getSearchCreatePopupOptions: function () { + const res = this._super(...arguments); + if (this.isReferenceField) { + res.domain = this._getReferenceDomain(); + } + return res; + }, + }); +}); diff --git a/web_field_reference_domain/templates/assets.xml b/web_field_reference_domain/templates/assets.xml new file mode 100644 index 000000000000..fe0b63bc661c --- /dev/null +++ b/web_field_reference_domain/templates/assets.xml @@ -0,0 +1,21 @@ + + + +