From d5c11bed9d44a6ca12285b19d99704cec37c0454 Mon Sep 17 00:00:00 2001 From: Sergei Ruzki Date: Mon, 15 Feb 2021 14:46:56 +0100 Subject: [PATCH] web_boolean_button ported from Odoo 12.0 CE --- web_boolean_button/README.rst | 99 ++++ web_boolean_button/__init__.py | 0 web_boolean_button/__manifest__.py | 15 + web_boolean_button/readme/CONTRIBUTORS.rst | 3 + web_boolean_button/readme/DESCRIPTION.rst | 1 + web_boolean_button/readme/ROADMAP.rst | 1 + web_boolean_button/readme/USAGE.rst | 13 + .../static/description/index.html | 443 ++++++++++++++++++ .../static/src/js/basic_fields.js | 80 ++++ web_boolean_button/static/tests/form_tests.js | 312 ++++++++++++ web_boolean_button/views/templates.xml | 23 + 11 files changed, 990 insertions(+) create mode 100644 web_boolean_button/README.rst create mode 100644 web_boolean_button/__init__.py create mode 100644 web_boolean_button/__manifest__.py create mode 100644 web_boolean_button/readme/CONTRIBUTORS.rst create mode 100644 web_boolean_button/readme/DESCRIPTION.rst create mode 100644 web_boolean_button/readme/ROADMAP.rst create mode 100644 web_boolean_button/readme/USAGE.rst create mode 100644 web_boolean_button/static/description/index.html create mode 100644 web_boolean_button/static/src/js/basic_fields.js create mode 100644 web_boolean_button/static/tests/form_tests.js create mode 100644 web_boolean_button/views/templates.xml diff --git a/web_boolean_button/README.rst b/web_boolean_button/README.rst new file mode 100644 index 000000000..9b4c34ba1 --- /dev/null +++ b/web_boolean_button/README.rst @@ -0,0 +1,99 @@ +===================== +Boolean Button Widget +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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/13.0/web_boolean_button + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_boolean_button + :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/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds 'boolean_button' widget to 13.0 as it was in 12.0 + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to form and attach widget boolean_button to your boolean field (i.e. in button-box div) with terminology if needed. + +.. code-block:: xml + + + + +Known issues / Roadmap +====================== + +Ported from 12.0 to 13.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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Bigdata BY +* Odoo SA + +Contributors +~~~~~~~~~~~~ + +* `Odoo S.A. `_ +* `Odoo Community Association (OCA) `_ +* Sergei Ruzki (Bigdata.BY) + +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_boolean_button/__init__.py b/web_boolean_button/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_boolean_button/__manifest__.py b/web_boolean_button/__manifest__.py new file mode 100644 index 000000000..777c4c87e --- /dev/null +++ b/web_boolean_button/__manifest__.py @@ -0,0 +1,15 @@ +{ + "name": "Boolean Button Widget", + "version": "13.0.1.0.0", + "category": "Web", + "summary": "Boolean Button Widget for Forms with legend", + "license": "LGPL-3", + "author": "Bigdata BY, Odoo SA, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["web"], + "data": ["views/templates.xml"], + "qweb": [], + "installable": True, + "application": False, + "auto_install": False, +} diff --git a/web_boolean_button/readme/CONTRIBUTORS.rst b/web_boolean_button/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..8cf51003b --- /dev/null +++ b/web_boolean_button/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Odoo S.A. `_ +* `Odoo Community Association (OCA) `_ +* Sergei Ruzki (Bigdata.BY) diff --git a/web_boolean_button/readme/DESCRIPTION.rst b/web_boolean_button/readme/DESCRIPTION.rst new file mode 100644 index 000000000..70dbddd78 --- /dev/null +++ b/web_boolean_button/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds 'boolean_button' widget to 13.0 as it was in 12.0 diff --git a/web_boolean_button/readme/ROADMAP.rst b/web_boolean_button/readme/ROADMAP.rst new file mode 100644 index 000000000..7e5512065 --- /dev/null +++ b/web_boolean_button/readme/ROADMAP.rst @@ -0,0 +1 @@ +Ported from 12.0 to 13.0 diff --git a/web_boolean_button/readme/USAGE.rst b/web_boolean_button/readme/USAGE.rst new file mode 100644 index 000000000..e1ed4727c --- /dev/null +++ b/web_boolean_button/readme/USAGE.rst @@ -0,0 +1,13 @@ +Go to form and attach widget boolean_button to your boolean field (i.e. in button-box div) with terminology if needed. + +.. code-block:: xml + + diff --git a/web_boolean_button/static/description/index.html b/web_boolean_button/static/description/index.html new file mode 100644 index 000000000..947265ce8 --- /dev/null +++ b/web_boolean_button/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Boolean Button Widget + + + +
+

Boolean Button Widget

+ + +

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

+

This module adds ‘boolean_button’ widget to 13.0 as it was in 12.0

+

Table of contents

+ +
+

Usage

+

Go to form and attach widget boolean_button to your boolean field (i.e. in button-box div) with terminology if needed.

+
+<button name="toggle_start" type="object" class="oe_stat_button" icon="fa-archive">
+    <field name="help_button" widget="boolean_button"
+        options="{'terminology': {
+                'string_true': 'ACTIVE',
+                'hover_true': 'PAUSE',
+                'string_false': 'HELP',
+                'hover_false': 'FINISH'
+            }}"/>
+</button>
+
+
+
+

Known issues / Roadmap

+

Ported from 12.0 to 13.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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Bigdata BY
  • +
  • Odoo SA
  • +
+
+ +
+

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_boolean_button/static/src/js/basic_fields.js b/web_boolean_button/static/src/js/basic_fields.js new file mode 100644 index 000000000..c5c2c93d2 --- /dev/null +++ b/web_boolean_button/static/src/js/basic_fields.js @@ -0,0 +1,80 @@ +odoo.define("web.boolean_button_widget", function(require) { + "use strict"; + + var AbstractField = require("web.AbstractField"); + var registry = require("web.field_registry"); + var translation = require("web.translation"); + var _t = translation._t; + + var FieldBooleanButton = AbstractField.extend({ + className: "o_stat_info", + supportedFieldTypes: ["boolean"], + + // -------------------------------------------------------------------------- + // Public + // -------------------------------------------------------------------------- + + /** + * A boolean field is always set since false is a valid value. + * + * @override + */ + isSet: function() { + return true; + }, + + // -------------------------------------------------------------------------- + // Private + // -------------------------------------------------------------------------- + + /** + * This widget is supposed to be used inside a stat button and, as such, is + * rendered the same way in edit and readonly mode. + * + * @override + * @private + */ + + _render: function() { + this.$el.empty(); + var text = null, + hover = null; + switch (this.nodeOptions.terminology) { + case "active": + text = this.value ? _t("Active") : _t("Inactive"); + hover = this.value ? _t("Deactivate") : _t("Activate"); + break; + case "archive": + text = this.value ? _t("Active") : _t("Archived"); + hover = this.value ? _t("Archive") : _t("Restore"); + break; + case "close": + text = this.value ? _t("Active") : _t("Closed"); + hover = this.value ? _t("Close") : _t("Open"); + break; + default: + var opt_terms = this.nodeOptions.terminology || {}; + if (typeof opt_terms === "string") { + opt_terms = {}; // Unsupported terminology + } + text = this.value + ? _t(opt_terms.string_true) || _t("On") + : _t(opt_terms.string_false) || _t("Off"); + hover = this.value + ? _t(opt_terms.hover_true) || _t("Switch Off") + : _t(opt_terms.hover_false) || _t("Switch On"); + } + var valColor = this.value ? "text-success" : "text-danger"; + var hoverColor = this.value ? "text-danger" : "text-success"; + var $val = $("") + .addClass("o_stat_text o_not_hover " + valColor) + .text(text); + var $hover = $("") + .addClass("o_stat_text o_hover " + hoverColor) + .text(hover); + this.$el.append($val).append($hover); + }, + }); + + registry.add("boolean_button", FieldBooleanButton); +}); diff --git a/web_boolean_button/static/tests/form_tests.js b/web_boolean_button/static/tests/form_tests.js new file mode 100644 index 000000000..9e5dd1b07 --- /dev/null +++ b/web_boolean_button/static/tests/form_tests.js @@ -0,0 +1,312 @@ +odoo.define("web_boolean_button.form_tests", function(require) { + "use strict"; + + /* global QUnit*/ + + var FormView = require("web.FormView"); + var testUtils = require("web.test_utils"); + var createView = testUtils.createView; + + QUnit.module("web_boolean_button", {}, function() { + QUnit.module("web_boolean_button", {}, function() { + QUnit.module( + "basic_fields", + { + beforeEach: function() { + this.data = { + partner: { + fields: { + date: { + string: "A date", + type: "date", + searchable: true, + }, + datetime: { + string: "A datetime", + type: "datetime", + searchable: true, + }, + display_name: { + string: "Displayed name", + type: "char", + searchable: true, + }, + foo: { + string: "Foo", + type: "char", + default: "My little Foo Value", + searchable: true, + trim: true, + }, + bar: { + string: "Bar", + type: "boolean", + default: true, + searchable: true, + }, + txt: { + string: "txt", + type: "text", + default: + "My little txt Value\nHo-ho-hoooo Merry Christmas", + }, + int_field: { + string: "int_field", + type: "integer", + sortable: true, + searchable: true, + }, + qux: { + string: "Qux", + type: "float", + digits: [16, 1], + searchable: true, + }, + p: { + string: "one2many field", + type: "one2many", + relation: "partner", + searchable: true, + }, + trululu: { + string: "Trululu", + type: "many2one", + relation: "partner", + searchable: true, + }, + timmy: { + string: "pokemon", + type: "many2many", + relation: "partner_type", + searchable: true, + }, + product_id: { + string: "Product", + type: "many2one", + relation: "product", + searchable: true, + }, + sequence: { + type: "integer", + string: "Sequence", + searchable: true, + }, + currency_id: { + string: "Currency", + type: "many2one", + relation: "currency", + searchable: true, + }, + selection: { + string: "Selection", + type: "selection", + searchable: true, + selection: [ + ["normal", "Normal"], + ["blocked", "Blocked"], + ["done", "Done"], + ], + }, + document: {string: "Binary", type: "binary"}, + hex_color: { + string: "hexadecimal color", + type: "char", + }, + }, + records: [ + { + id: 1, + date: "2017-02-03", + datetime: "2017-02-08 10:00:00", + display_name: "first record", + bar: true, + foo: "yop", + int_field: 10, + qux: 0.44444, + p: [], + timmy: [], + trululu: 4, + selection: "blocked", + document: "coucou==\n", + hex_color: "#ff0000", + }, + { + id: 2, + display_name: "second record", + bar: true, + foo: "blip", + int_field: 0, + qux: 0, + p: [], + timmy: [], + trululu: 1, + sequence: 4, + currency_id: 2, + selection: "normal", + }, + { + id: 4, + display_name: "aaa", + foo: "abc", + sequence: 9, + int_field: false, + qux: false, + selection: "done", + }, + { + id: 3, + bar: true, + foo: "gnap", + int_field: 80, + qux: -3.89859, + m2o: 1, + m2m: [], + }, + { + id: 5, + bar: false, + foo: "blop", + int_field: -4, + qux: 9.1, + m2o: 1, + m2m: [1], + currency_id: 1, + }, + ], + onchanges: {}, + }, + product: { + fields: { + name: { + string: "Product Name", + type: "char", + searchable: true, + }, + }, + records: [ + { + id: 37, + display_name: "xphone", + }, + { + id: 41, + display_name: "xpad", + }, + ], + }, + partner_type: { + fields: { + name: { + string: "Partner Type", + type: "char", + searchable: true, + }, + color: { + string: "Color index", + type: "integer", + searchable: true, + }, + }, + records: [ + {id: 12, display_name: "gold", color: 2}, + {id: 14, display_name: "silver", color: 5}, + ], + }, + currency: { + fields: { + symbol: { + string: "Currency Sumbol", + type: "char", + searchable: true, + }, + position: { + string: "Currency Position", + type: "char", + searchable: true, + }, + }, + records: [ + { + id: 1, + display_name: "$", + symbol: "$", + position: "before", + }, + { + id: 2, + display_name: "€", + symbol: "€", + position: "after", + }, + ], + }, + "ir.translation": { + fields: { + lang_code: {type: "char"}, + value: {type: "char"}, + res_id: {type: "integer"}, + }, + records: [ + { + id: 99, + res_id: 37, + value: "", + lang_code: "en_US", + }, + ], + }, + }; + }, + }, + function() { + QUnit.module("FieldBooleanButtonView"); + + QUnit.test("boolean button tests", async function(assert) { + assert.expect(2); + + var terminology = { + string_true: "Production Environment", + hover_true: "Switch to test environment", + string_false: "Test Environment", + hover_false: "Switch to production environment", + }; + + var form = await createView({ + View: FormView, + model: "partner", + data: this.data, + arch: + "
" + + '
' + + '" + + "
" + + "
", + res_id: 2, + }); + + assert.strictEqual( + form.$( + ".o_stat_text.o_not_hover:contains(Production Environment)" + ).length, + 1, + "button should contain correct string" + ); + assert.strictEqual( + form.$( + ".o_stat_text.o_hover:contains(Switch to test environment)" + ).length, + 1, + "button should display correct string when hovering" + ); + + form.destroy(); + }); + } + ); + }); + }); +}); diff --git a/web_boolean_button/views/templates.xml b/web_boolean_button/views/templates.xml new file mode 100644 index 000000000..c4d16bf4e --- /dev/null +++ b/web_boolean_button/views/templates.xml @@ -0,0 +1,23 @@ + + +