diff --git a/.copier-answers.yml b/.copier-answers.yml index 653dedb99..9ab731486 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,9 +1,14 @@ # Do NOT update manually; changes here will be overwritten by Copier -_commit: v1.6.1 +_commit: v1.11.0 _src_path: gh:oca/oca-addons-repo-template ci: GitHub dependency_installation_mode: PIP generate_requirements_txt: true +github_check_license: true +github_enable_codecov: true +github_enable_makepot: true +github_enable_stale_action: true +github_enforce_dev_status_compatibility: true include_wkhtmltopdf: false odoo_version: 14.0 org_name: Odoo Community Association (OCA) @@ -11,10 +16,11 @@ org_slug: OCA rebel_module_groups: - web_widget_model_viewer repo_description: "This project aims to deal with modules related to the webclient\ - \ of Odoo. You'll find modules that:\n\n - Add facilities to the UI\n - Add widgets\n\ - \ - Ease the import/export features\n - Generally add clientside functionality" + \ of Odoo. You'll find modules that:\n\n - Add facilities to the UI\n - Add widgets\n\ + \ - Ease the import/export features\n - Generally add clientside functionality" repo_name: Web addons for Odoo repo_slug: web repo_website: https://github.com/OCA/web travis_apt_packages: [] travis_apt_sources: [] + diff --git a/.gitignore b/.gitignore index 818770fb1..9c283fd41 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ build/ develop-eggs/ dist/ eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5bedc50c4..e01273ce8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -119,19 +119,15 @@ repos: - id: flake8 name: flake8 additional_dependencies: ["flake8-bugbear==20.1.4"] - - repo: https://github.com/PyCQA/pylint - rev: v2.11.1 + - repo: https://github.com/OCA/pylint-odoo + rev: 7.0.2 hooks: - - id: pylint + - id: pylint_odoo name: pylint with optional checks args: - --rcfile=.pylintrc - --exit-zero verbose: true - additional_dependencies: &pylint_deps - - pylint-odoo==5.0.5 - - id: pylint - name: pylint with mandatory checks + - id: pylint_odoo args: - --rcfile=.pylintrc-mandatory - additional_dependencies: *pylint_deps diff --git a/.pylintrc b/.pylintrc index e33958833..d1f72970b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,5 @@ + + [MASTER] load-plugins=pylint_odoo score=n diff --git a/.pylintrc-mandatory b/.pylintrc-mandatory index 08bca3cef..3bf8ceefb 100644 --- a/.pylintrc-mandatory +++ b/.pylintrc-mandatory @@ -1,3 +1,4 @@ + [MASTER] load-plugins=pylint_odoo score=n diff --git a/web_access_rule_buttons/models/models.py b/web_access_rule_buttons/models/models.py index ed43cb817..b6b4c08c0 100644 --- a/web_access_rule_buttons/models/models.py +++ b/web_access_rule_buttons/models/models.py @@ -22,19 +22,16 @@ class Base(models.AbstractModel): operations = ["read", "create", "write", "unlink"] result = {} for operation in operations: - try: - self.check_access_rule(operation) - except exceptions.AccessError: - result[operation] = False - if ( - self.is_transient() - or self.ids - and self.env.user.has_group("base.user_admin") - ): + if self.is_transient() or not self.ids: # If we call check_access_rule() without id, it will try to # run a SELECT without ID which will crash, so we just blindly # allow the operations result[operation] = True - else: + continue + try: + self.check_access_rule(operation) + except exceptions.AccessError: result[operation] = False + else: + result[operation] = True return result diff --git a/web_access_rule_buttons/tests/test_access_rule_buttons.py b/web_access_rule_buttons/tests/test_access_rule_buttons.py index 0708507d1..582a31155 100644 --- a/web_access_rule_buttons/tests/test_access_rule_buttons.py +++ b/web_access_rule_buttons/tests/test_access_rule_buttons.py @@ -1,25 +1,38 @@ # Copyright 2019 Onestein BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase +from odoo.tests import common, new_test_user, users -class TestAccessRuleButtons(TransactionCase): +class TestAccessRuleButtons(common.TransactionCase): def setUp(self): - super(TestAccessRuleButtons, self).setUp() - - self.curr_obj = self.env["res.currency"] + super().setUp() self.curr_record = self.env.ref("base.USD") + new_test_user(self.env, login="test-user", groups="base.group_system") + self.env.ref("base.user_admin").write( + { + "groups_id": [(4, self.env.ref("base.group_system").id)], + } + ) + @users("admin", "test-user") def test_check_access_rule_1(self): - res = self.curr_obj.check_access_rule_all(["write"]) - self.assertFalse(res["write"]) - - def test_check_access_rule_2(self): - res = self.curr_record.check_access_rule_all(["write"]) + res = self.env["res.currency"].check_access_rule_all(["write"]) self.assertTrue(res["write"]) + @users("admin", "test-user") + def test_check_access_rule_2(self): + res = ( + self.env["res.currency"] + .browse(self.curr_record.id) + .check_access_rule_all(["write"]) + ) + self.assertTrue(res["write"]) + + @users("admin", "test-user") def test_check_access_rule_3(self): - res = self.curr_record.check_access_rule_all() + res = ( + self.env["res.currency"].browse(self.curr_record.id).check_access_rule_all() + ) self.assertTrue(res["read"]) self.assertTrue(res["create"]) self.assertTrue(res["write"]) diff --git a/web_domain_field/README.rst b/web_domain_field/README.rst index a14831b6f..c360a77c2 100644 --- a/web_domain_field/README.rst +++ b/web_domain_field/README.rst @@ -1,11 +1,42 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ================ Web Domain Field ================ +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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/14.0/web_domain_field + :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_domain_field + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When you define a view you can specify on the relational fields a domain +attribute. This attribute is evaluated as filter to apply when displaying +existing records for selection. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + When you define a view you can specify on the relational fields a domain attribute. This attribute is evaluated as filter to apply when displaying existing records for selection. @@ -51,7 +82,6 @@ The field used as domain must provide the domain as a JSON encoded string. store=False, ) - @api.multi @api.depends('name') def _compute_product_id_domain(self): for rec in self: @@ -59,49 +89,44 @@ The field used as domain must provide the domain as a JSON encoded string. [('type', '=', 'product'), ('name', 'like', rec.name)] ) - -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/10.0 - - - 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. +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 ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* ACSONE SA/NV Contributors ------------- +~~~~~~~~~~~~ * Laurent Mignon * Denis Roussel +* Raf Ven -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +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_domain_field/readme/CONTRIBUTORS.rst b/web_domain_field/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..1294ec29e --- /dev/null +++ b/web_domain_field/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Laurent Mignon +* Denis Roussel +* Raf Ven diff --git a/web_domain_field/readme/DESCRIPTION.rst b/web_domain_field/readme/DESCRIPTION.rst new file mode 100644 index 000000000..5aa1b96f3 --- /dev/null +++ b/web_domain_field/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +When you define a view you can specify on the relational fields a domain +attribute. This attribute is evaluated as filter to apply when displaying +existing records for selection. diff --git a/web_domain_field/readme/USAGE.rst b/web_domain_field/readme/USAGE.rst new file mode 100644 index 000000000..b9c04da19 --- /dev/null +++ b/web_domain_field/readme/USAGE.rst @@ -0,0 +1,51 @@ +When you define a view you can specify on the relational fields a domain +attribute. This attribute is evaluated as filter to apply when displaying +existing records for selection. + +.. code-block:: xml + + + +The value provided for the domain attribute must be a string representing a +valid Odoo domain. This string is evaluated on the client side in a +restricted context where we can reference as right operand the values of +fields present into the form and a limited set of functions. + +In this context it's hard to build complex domain and we are facing to some +limitations as: + + * The syntax to include in your domain a criteria involving values from a + x2many field is complex. + * The right side of domain in case of x2many can involve huge amount of ids + (performance problem). + * Domains computed by an onchange on an other field are not recomputed when + you modify the form and don't modify the field triggering the onchange. + * It's not possible to extend an existing domain. You must completely redefine + the domain in your specialized addon + * etc... + +In order to mitigate these limitations this new addon allows you to use the +value of a field as domain of an other field in the xml definition of your +view. + +.. code-block:: xml + + + + +The field used as domain must provide the domain as a JSON encoded string. + +.. code-block:: python + + product_id_domain = fields.Char( + compute="_compute_product_id_domain", + readonly=True, + store=False, + ) + + @api.depends('name') + def _compute_product_id_domain(self): + for rec in self: + rec.product_id_domain = json.dumps( + [('type', '=', 'product'), ('name', 'like', rec.name)] + ) diff --git a/web_domain_field/static/description/index.html b/web_domain_field/static/description/index.html new file mode 100644 index 000000000..d602ae0e2 --- /dev/null +++ b/web_domain_field/static/description/index.html @@ -0,0 +1,474 @@ + + + + + + +Web Domain Field + + + +
+

Web Domain Field

+ + +

Production/Stable License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

When you define a view you can specify on the relational fields a domain +attribute. This attribute is evaluated as filter to apply when displaying +existing records for selection.

+

Table of contents

+ +
+

Usage

+

When you define a view you can specify on the relational fields a domain +attribute. This attribute is evaluated as filter to apply when displaying +existing records for selection.

+
+<field name="product_id" domain="[('type','=','product')]"/>
+
+

The value provided for the domain attribute must be a string representing a +valid Odoo domain. This string is evaluated on the client side in a +restricted context where we can reference as right operand the values of +fields present into the form and a limited set of functions.

+

In this context it’s hard to build complex domain and we are facing to some +limitations as:

+
+
    +
  • The syntax to include in your domain a criteria involving values from a +x2many field is complex.
  • +
  • The right side of domain in case of x2many can involve huge amount of ids +(performance problem).
  • +
  • Domains computed by an onchange on an other field are not recomputed when +you modify the form and don’t modify the field triggering the onchange.
  • +
  • It’s not possible to extend an existing domain. You must completely redefine +the domain in your specialized addon
  • +
  • etc…
  • +
+
+

In order to mitigate these limitations this new addon allows you to use the +value of a field as domain of an other field in the xml definition of your +view.

+
+<field name="product_id_domain" invisible="1"/>
+<field name="product_id" domain="product_id_domain"/>
+
+

The field used as domain must provide the domain as a JSON encoded string.

+
+product_id_domain = fields.Char(
+    compute="_compute_product_id_domain",
+    readonly=True,
+    store=False,
+)
+
+@api.depends('name')
+def _compute_product_id_domain(self):
+    for rec in self:
+        rec.product_id_domain = json.dumps(
+            [('type', '=', 'product'), ('name', 'like', rec.name)]
+        )
+
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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.

+
+
+
+ +