From 35d00388fbe6f0caa29f77023fcb71ecbd38521d Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Thu, 26 Nov 2020 16:34:59 +0100 Subject: [PATCH] [ADD] web_domain_field_example: Test and demo web_domain_field --- web_domain_field_example/README.rst | 83 ++++ web_domain_field_example/__init__.py | 2 + web_domain_field_example/__manifest__.py | 18 + .../demo/product_demonstration.xml | 28 ++ web_domain_field_example/models/__init__.py | 3 + .../models/product_demonstration.py | 25 + .../models/product_selection_example.py | 46 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + web_domain_field_example/readme/USAGE.rst | 6 + .../security/ir.model.access.csv | 3 + .../static/description/index.html | 428 ++++++++++++++++++ web_domain_field_example/views/menu.xml | 18 + .../views/product_selection_example.xml | 29 ++ 14 files changed, 691 insertions(+) create mode 100644 web_domain_field_example/README.rst create mode 100644 web_domain_field_example/__init__.py create mode 100644 web_domain_field_example/__manifest__.py create mode 100644 web_domain_field_example/demo/product_demonstration.xml create mode 100644 web_domain_field_example/models/__init__.py create mode 100644 web_domain_field_example/models/product_demonstration.py create mode 100644 web_domain_field_example/models/product_selection_example.py create mode 100644 web_domain_field_example/readme/CONTRIBUTORS.rst create mode 100644 web_domain_field_example/readme/DESCRIPTION.rst create mode 100644 web_domain_field_example/readme/USAGE.rst create mode 100644 web_domain_field_example/security/ir.model.access.csv create mode 100644 web_domain_field_example/static/description/index.html create mode 100644 web_domain_field_example/views/menu.xml create mode 100644 web_domain_field_example/views/product_selection_example.xml diff --git a/web_domain_field_example/README.rst b/web_domain_field_example/README.rst new file mode 100644 index 000000000..bc162462d --- /dev/null +++ b/web_domain_field_example/README.rst @@ -0,0 +1,83 @@ +======================== +Web Domain Field Example +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_domain_field_example + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_domain_field_example + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is intendend to demonstrate and test the web_domain_field module. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +You can go to the menu +Configuration==>Technical==>User Interface==>product Selection Example +to see dynamic adaption of a domain in practice. + +In practice the domain fields would be invisible. For test/demo purposes the +field product_id_domain in this module is visible in the form view. + +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 +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Ronald Portier + +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_domain_field_example/__init__.py b/web_domain_field_example/__init__.py new file mode 100644 index 000000000..3275ac2ad --- /dev/null +++ b/web_domain_field_example/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/web_domain_field_example/__manifest__.py b/web_domain_field_example/__manifest__.py new file mode 100644 index 000000000..c2f358693 --- /dev/null +++ b/web_domain_field_example/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2020 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Web Domain Field Example", + "summary": "Show and test web_domain_field module", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "Therp BV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["web_domain_field", "product"], + "data": [ + "views/product_selection_example.xml", + "views/menu.xml", + "security/ir.model.access.csv", + ], + "demo": ["demo/product_demonstration.xml"], +} diff --git a/web_domain_field_example/demo/product_demonstration.xml b/web_domain_field_example/demo/product_demonstration.xml new file mode 100644 index 000000000..e9feb4fc9 --- /dev/null +++ b/web_domain_field_example/demo/product_demonstration.xml @@ -0,0 +1,28 @@ + + + + + Entertainment for employees + ENT001 + + + + + Education for employees + EDU0001 + + + + + Do back-up for customers + BCK0001 + + + + + Do programming for customers + PRG0001 + + + + diff --git a/web_domain_field_example/models/__init__.py b/web_domain_field_example/models/__init__.py new file mode 100644 index 000000000..e64d38624 --- /dev/null +++ b/web_domain_field_example/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import product_demonstration +from . import product_selection_example diff --git a/web_domain_field_example/models/product_demonstration.py b/web_domain_field_example/models/product_demonstration.py new file mode 100644 index 000000000..75331f880 --- /dev/null +++ b/web_domain_field_example/models/product_demonstration.py @@ -0,0 +1,25 @@ +# Copyright 2020 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +"""Demonstration products. + +We do nut use the normal product.template and product.product models because some +odoo modules had the abhorrent idea of adding required fields to product.template, +like sale_line_warn in the sale module. In order to make this module not dependant +on modules that make the terrible mistake of adding required fields to models +defined in another module, we have our own demo product model. +""" + +from odoo import fields, models + + +class ProductDemonstration(models.Model): + """Demonstration product. Just for the sake of this module.""" + _name = "product.demonstration" + _description = "Products to demonstrate workings of web_domain_field module." + + name = fields.Char(required=True) + default_code = fields.Char(required=True) + categ_id = fields.Many2one( + comodel_name="product.category", + required=True + ) diff --git a/web_domain_field_example/models/product_selection_example.py b/web_domain_field_example/models/product_selection_example.py new file mode 100644 index 000000000..af942b44f --- /dev/null +++ b/web_domain_field_example/models/product_selection_example.py @@ -0,0 +1,46 @@ +# Copyright 2020 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +"""Demonstratie web_domain_field, making product domain dependent on category.""" +import json + +from odoo import api, fields, models + + +class ProductSelectionExample(models.Model): + """Demonstratie web_domain_field, making product domain dependent on category.""" + _name = "product.selection.example" + _description = "Show web_domain_field in action" + + @api.multi + @api.depends("product_category_id") + def _compute_product_id_domain(self): + for this in self: + domain = ( + [("categ_id", "=", this.product_category_id.id)] + if this.product_category_id + else [] + ) + this.product_id_domain = json.dumps(domain) + + product_category_id = fields.Many2one( + comodel_name="product.category", + required=True + ) + product_id = fields.Many2one(comodel_name="product.demonstration") + product_id_domain = fields.Char( + compute="_compute_product_id_domain", + readonly=True, + store=False, + ) + + @api.onchange("product_category_id") + def _onchange_product_category_id(self): + """Clear product_id if not in accordance with category.""" + for this in self: + if ( + this.product_category_id + and this.product_id + and this.product_category_id != this.product_id.categ_id + ): + no_product = self.env["product.demonstration"].browse([]) + this.product_id = no_product diff --git a/web_domain_field_example/readme/CONTRIBUTORS.rst b/web_domain_field_example/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..4e07c28e1 --- /dev/null +++ b/web_domain_field_example/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Ronald Portier diff --git a/web_domain_field_example/readme/DESCRIPTION.rst b/web_domain_field_example/readme/DESCRIPTION.rst new file mode 100644 index 000000000..6674ff111 --- /dev/null +++ b/web_domain_field_example/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module is intendend to demonstrate and test the web_domain_field module. diff --git a/web_domain_field_example/readme/USAGE.rst b/web_domain_field_example/readme/USAGE.rst new file mode 100644 index 000000000..f8b696df4 --- /dev/null +++ b/web_domain_field_example/readme/USAGE.rst @@ -0,0 +1,6 @@ +You can go to the menu +Configuration==>Technical==>User Interface==>product Selection Example +to see dynamic adaption of a domain in practice. + +In practice the domain fields would be invisible. For test/demo purposes the +field product_id_domain in this module is visible in the form view. diff --git a/web_domain_field_example/security/ir.model.access.csv b/web_domain_field_example/security/ir.model.access.csv new file mode 100644 index 000000000..77c32fc1e --- /dev/null +++ b/web_domain_field_example/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_product_selection_example_system,access.product_selection_example.system,model_product_selection_example,base.group_system,1,1,1,1 +access_product_demonstration_system,access.product_demonstration.system,model_product_demonstration,base.group_system,1,1,1,1 diff --git a/web_domain_field_example/static/description/index.html b/web_domain_field_example/static/description/index.html new file mode 100644 index 000000000..16a7bd218 --- /dev/null +++ b/web_domain_field_example/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +Web Domain Field Example + + + +
+

Web Domain Field Example

+ + +

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

+

This module is intendend to demonstrate and test the web_domain_field module.

+

Table of contents

+ +
+

Usage

+

You can go to the menu +Configuration==>Technical==>User Interface==>product Selection Example +to see dynamic adaption of a domain in practice.

+

In practice the domain fields would be invisible. For test/demo purposes the +field product_id_domain in this module is visible in the form view.

+
+
+

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

+
    +
  • Therp BV
  • +
+
+
+

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_domain_field_example/views/menu.xml b/web_domain_field_example/views/menu.xml new file mode 100644 index 000000000..aca850369 --- /dev/null +++ b/web_domain_field_example/views/menu.xml @@ -0,0 +1,18 @@ + + + + + Product Selection Example + tree,form + product.selection.example + + + + + diff --git a/web_domain_field_example/views/product_selection_example.xml b/web_domain_field_example/views/product_selection_example.xml new file mode 100644 index 000000000..0a81becde --- /dev/null +++ b/web_domain_field_example/views/product_selection_example.xml @@ -0,0 +1,29 @@ + + + + + product.selection.example.tree + product.selection.example + + + + + + + + + + product.selection.example.form + product.selection.example + +
+ + + + + + +
+
+ +