3
0
Fork 0

[MIG] web_select_all_companies: Backporting from 15.0 to 14.0

14.0
Anna Janiszewska 2024-09-27 15:15:10 +02:00
parent a29b090af1
commit 33313f41da
9 changed files with 159 additions and 96 deletions

View File

@ -0,0 +1 @@
../../../../web_select_all_companies

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -17,20 +17,20 @@ Web Select All Companies
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3 :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/15.0/web_select_all_companies :target: https://github.com/OCA/web/tree/14.0/web_select_all_companies
:alt: OCA/web :alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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_select_all_companies :target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_select_all_companies
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |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 :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=14.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
This module allows you to select or deselect all the companies in a single click. This module allows you to select or deselect all the companies in a single click.
.. image:: https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png .. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png
**Table of contents** **Table of contents**
@ -43,7 +43,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -73,6 +73,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_select_all_companies>`_ project on GitHub. This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_select_all_companies>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -4,20 +4,13 @@
{ {
"name": "Web Select All Companies", "name": "Web Select All Companies",
"summary": "Allows you to select all companies in one click.", "summary": "Allows you to select all companies in one click.",
"version": "15.0.1.0.0", "version": "14.0.1.0.0",
"category": "Web", "category": "Web",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",
"author": "Camptocamp, Odoo Community Association (OCA)", "author": "Camptocamp, Odoo Community Association (OCA)",
"license": "LGPL-3", "license": "LGPL-3",
"depends": ["web"], "depends": ["web"],
"assets": { "qweb": ["static/src/xml/switch_all_company_menu.xml"],
"web.assets_qweb": [ "data": ["views/web_select_all_companies.xml"],
"web_select_all_companies/static/src/xml/switch_all_company_menu.xml",
],
"web.assets_backend": [
"web_select_all_companies/static/src/scss/switch_all_company_menu.scss",
"web_select_all_companies/static/src/js/switch_all_company_menu.esm.js",
],
},
"installable": True, "installable": True,
} }

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
@ -8,10 +9,11 @@
/* /*
:Author: David Goodger (goodger@python.org) :Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain. :Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils. Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet. customize this style sheet.
@ -274,7 +276,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ; margin-left: 2em ;
margin-right: 2em } margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */ pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee } pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 } pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@ -300,7 +302,7 @@ span.option {
span.pre { span.pre {
white-space: pre } white-space: pre }
span.problematic { span.problematic, pre.problematic {
color: red } color: red }
span.section-subtitle { span.section-subtitle {
@ -368,9 +370,9 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b2dd44d037d4c1129717952faf30f486f1ce3387df2f7a839ebed82e58bb1197 !! source digest: sha256:b2dd44d037d4c1129717952faf30f486f1ce3387df2f7a839ebed82e58bb1197
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/15.0/web_select_all_companies"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_select_all_companies"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/14.0/web_select_all_companies"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_select_all_companies"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to select or deselect all the companies in a single click.</p> <p>This module allows you to select or deselect all the companies in a single click.</p>
<img alt="https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png" src="https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png" /> <img alt="https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png" src="https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png" />
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
@ -388,7 +390,7 @@ ul.auto-toc {
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -408,11 +410,13 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2> <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_select_all_companies">OCA/web</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_select_all_companies">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -1,45 +0,0 @@
/** @odoo-module **/
/* Copyright 2023 Camptocamp - Telmo Santos
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
import {SwitchCompanyMenu} from "@web/webclient/switch_company_menu/switch_company_menu";
import {browser} from "@web/core/browser/browser";
import {patch} from "@web/core/utils/patch";
patch(SwitchCompanyMenu.prototype, "SwitchAllCompanyMenu", {
setup() {
this._super(...arguments);
this.allCompanyIds = Object.values(this.companyService.availableCompanies).map(
(x) => x.id
);
this.isAllCompaniesSelected = this.allCompanyIds.every((elem) =>
this.selectedCompanies.includes(elem)
);
},
toggleSelectAllCompanies() {
if (this.isAllCompaniesSelected) {
// Deselect all
this.state.companiesToToggle = this.allCompanyIds;
this.toggleCompany(this.currentCompany.id);
this.isAllCompaniesSelected = false;
browser.clearTimeout(this.toggleTimer);
this.toggleTimer = browser.setTimeout(() => {
this.companyService.setCompanies(
"toggle",
...this.state.companiesToToggle
);
}, this.constructor.toggleDelay);
} else {
// Select all
this.state.companiesToToggle = [this.allCompanyIds];
this.isAllCompaniesSelected = true;
browser.clearTimeout(this.toggleTimer);
this.toggleTimer = browser.setTimeout(() => {
this.companyService.setCompanies(
"loginto",
...this.state.companiesToToggle
);
}, this.constructor.toggleDelay);
}
},
});

View File

@ -0,0 +1,89 @@
/* Copyright 2023 Camptocamp - Telmo Santos
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define(
"web_select_all_companies/static/src/js/switch_all_company_menu.js",
function (require) {
"use strict";
var session = require("web.session");
var SwitchCompanyMenu = require("web.SwitchCompanyMenu");
SwitchCompanyMenu.include({
init() {
this._super.apply(this, arguments);
this.allCompanyIds = session.user_companies.allowed_companies.map(
(x) => x[0]
);
// Get allowed companies from user context and compare with all companies to check if all companies are selected or not
// and set flag accordingly
this.allowed_company_ids = session.user_context.allowed_company_ids;
this.isAllCompaniesSelected =
this.allowed_company_ids.length == this.allCompanyIds.length;
},
/**
* @private
* @param {MouseEvent|KeyEvent} ev
*/
_onToggleCompanyClick: function (ev) {
if (
ev.type == "keydown" &&
ev.which != $.ui.keyCode.ENTER &&
ev.which != $.ui.keyCode.SPACE
) {
return;
}
ev.preventDefault();
ev.stopPropagation();
var dropdownItem = $(ev.currentTarget).parent();
var companyID = dropdownItem.data("company-id");
var dropdownMenu = dropdownItem.parent();
var all_items = dropdownMenu.children();
var toggle_company_div = all_items[0].children[0];
var toggle_company_i = toggle_company_div.children[0].children[0];
if (!companyID) {
// Calculate length - 1 because one element is the 'toggle all companies' item
this.isAllCompaniesSelected =
dropdownMenu.find(".fa-check-square").length - 1 ==
this.allCompanyIds.length;
// Deselect all companies by toggling class on html elements and setting company data in session
if (this.isAllCompaniesSelected) {
all_items
.find(".fa-check-square")
.removeClass("fa-check-square")
.addClass("fa-square-o");
toggle_company_i.classList.replace(
"fa-check-square",
"fa-square-o"
);
$(ev.currentTarget).attr("aria-checked", "false");
session.setCompanies(this.allowed_company_ids[0], []);
session.user_context.allowed_company_ids = [];
} else {
// Select all companies by toggling class on html elements and setting company data in session
var allowed_company_ids = this.allowed_company_ids;
var current_company_id = allowed_company_ids[0];
_.each(this.allCompanyIds, (company_id) => {
if (!allowed_company_ids.includes(company_id)) {
allowed_company_ids.push(company_id);
}
});
all_items
.find(".fa-check-square")
.removeClass("fa-square-o")
.addClass("fa-check-square");
toggle_company_i.classList.replace(
"fa-square-o",
"fa-check-square"
);
$(ev.currentTarget).attr("aria-checked", "true");
session.setCompanies(current_company_id, allowed_company_ids);
}
} else {
return this._super.apply(this, arguments);
}
},
});
}
);

View File

@ -4,36 +4,36 @@
t-name="web_select_all_companies.SwitchAllCompanyMenu" t-name="web_select_all_companies.SwitchAllCompanyMenu"
t-inherit="web.SwitchCompanyMenu" t-inherit="web.SwitchCompanyMenu"
t-inherit-mode="extension" t-inherit-mode="extension"
owl="1"
> >
<xpath expr="//t[@t-as='company']" position="before"> <xpath expr="//t[@t-as='company']" position="before">
<DropdownItem class="p-0 bg-white"> <div class="dropdown-item d-flex py-0 px-0" data-menu="company">
<div class="d-flex"> <div
<div role="menuitemcheckbox"
role="menuitemcheckbox" tabindex="0"
tabindex="0" class="ml-auto pl-3 pr-3 border border-top-0 border-left-0 border-bottom-0 toggle_company o_py"
t-attf-class="{{isCurrent ? 'border-primary' : ''}}" >
class="border-end toggle_company" <span class="height: 2rem;">
t-on-click.stop="toggleSelectAllCompanies()" <t t-if="widget.isAllCompaniesSelected">
> <i class="fa fa-fw fa-check-square pt-2" />
<span class="btn btn-light border-0 p-2"> </t>
<i <t t-else="">
class="fa fa-fw py-2 text-primary" <i class="fa fa-fw fa-square-o pt-2" />
t-att-class="isAllCompaniesSelected ? 'fa-check-square text-primary' : 'fa-square-o'" </t>
/> </span>
</span>
</div>
<div
role="button"
tabindex="0"
class="d-flex flex-grow-1 align-items-center py-0 ps-2 ms-1 me-2 all-companies-item"
title="Select All Companies"
name="select_all_companies"
>
<span>All Companies</span>
</div>
</div> </div>
</DropdownItem> <div
class="d-flex flex-grow-1 align-items-center py-0 toggle_company pl-3 o_py"
>
<t t-if="widget.isAllCompaniesSelected">
<span class="mr-3 company_label">All Companies</span>
</t>
<t t-else="">
<span
class="mr-3 company_label text-muted"
>Select All Companies</span>
</t>
</div>
</div>
</xpath> </xpath>
</t> </t>
</templates> </templates>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template
id="assets_backend"
name="web_select_all_companies assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_select_all_companies/static/src/js/switch_all_company_menu.js"
/>
</xpath>
</template>
</odoo>