diff --git a/web_responsive_company/README.rst b/web_responsive_company/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/web_responsive_company/__init__.py b/web_responsive_company/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/web_responsive_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_responsive_company/__manifest__.py b/web_responsive_company/__manifest__.py new file mode 100644 index 000000000..3b40d36d6 --- /dev/null +++ b/web_responsive_company/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Web Responsive - Company Menu", + "summary": "Improve the diplay of the list of the companies", + "version": "12.0.1.0.0", + "category": "Web", + "website": "https://github.com/OCA/web", + "author": "GRAP,Odoo Community Association (OCA)", + "license": "LGPL-3", + "installable": True, + "depends": ["web_responsive"], + "data": [ + "views/assets.xml", + ], + "qweb": [ + "static/src/xml/web_responsive_company.xml", + ], + "demo": [ + "demo/res_groups.xml", + "demo/res_company.xml", + ], +} diff --git a/web_responsive_company/demo/res_company.xml b/web_responsive_company/demo/res_company.xml new file mode 100644 index 000000000..987cc24ec --- /dev/null +++ b/web_responsive_company/demo/res_company.xml @@ -0,0 +1,46 @@ + + + + + + + Tecnativa + + + + + + GRAP + + + + + + Camp To Camp + + + + + + Acsone + + + + + + Akretion + + + + + + Coop It Easy + + + + + diff --git a/web_responsive_company/demo/res_groups.xml b/web_responsive_company/demo/res_groups.xml new file mode 100644 index 000000000..b6b41fde4 --- /dev/null +++ b/web_responsive_company/demo/res_groups.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/web_responsive_company/i18n/fr.po b/web_responsive_company/i18n/fr.po new file mode 100644 index 000000000..85d5673ff --- /dev/null +++ b/web_responsive_company/i18n/fr.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_responsive_company +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-06-18 07:40+0000\n" +"PO-Revision-Date: 2021-06-18 07:40+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_responsive_company +#. openerp-web +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:77 +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:80 +#, python-format +msgid "Alt" +msgstr "Alt" + +#. module: web_responsive_company +#. openerp-web +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:75 +#, python-format +msgid "Change company" +msgstr "Changer de société" + +#. module: web_responsive_company +#. openerp-web +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:80 +#, python-format +msgid "Control" +msgstr "Contrôle" + +#. module: web_responsive_company +#: model:ir.model,name:web_responsive_company.model_ir_http +msgid "HTTP Routing" +msgstr "Routage HTTP" + +#. module: web_responsive_company +#. openerp-web +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:30 +#, python-format +msgid "Search company..." +msgstr "Rechercher une société ..." + +#. module: web_responsive_company +#. openerp-web +#: code:addons/web_responsive_company/static/src/xml/web_responsive_company.xml:77 +#, python-format +msgid "Shift" +msgstr "" + diff --git a/web_responsive_company/models/__init__.py b/web_responsive_company/models/__init__.py new file mode 100644 index 000000000..9a5eb7187 --- /dev/null +++ b/web_responsive_company/models/__init__.py @@ -0,0 +1 @@ +from . import ir_http diff --git a/web_responsive_company/models/ir_http.py b/web_responsive_company/models/ir_http.py new file mode 100644 index 000000000..2a7f740a3 --- /dev/null +++ b/web_responsive_company/models/ir_http.py @@ -0,0 +1,29 @@ +# Copyright (C) 2021-Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models +from odoo.http import request + + +class IrHttp(models.AbstractModel): + _inherit = 'ir.http' + + def session_info(self): + res = super().session_info() + user = request.env.user + companies = [] + for company in user.company_ids: + # Lazy dependency to res_company_code module + # if installed, return code and complete name + # to allow to display code separately, and + # search by code and name. (complete_name) + companies.append({ + 'id': company.id, + 'code': 'code' in company._fields and company.code or '', + 'name': company.name, + 'complete_name': 'complete_name' in company._fields + and company.complete_name or company.name, + }) + res["complete_companies"] = companies + return res diff --git a/web_responsive_company/readme/CONTRIBUTORS.rst b/web_responsive_company/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..dc70097ea --- /dev/null +++ b/web_responsive_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Sylvain LE GAL (https://www.twitter.com/legalsylvain) + +Part of the code comes from ``web_responsive`` module, and has been adapted. diff --git a/web_responsive_company/readme/DESCRIPTION.rst b/web_responsive_company/readme/DESCRIPTION.rst new file mode 100644 index 000000000..43c61362e --- /dev/null +++ b/web_responsive_company/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module extends the ``web_responsive`` module to have a better display of the companies menu. + +It is usefull only if you have an Odoo Instance, with a lot of companies. diff --git a/web_responsive_company/readme/INSTALL.rst b/web_responsive_company/readme/INSTALL.rst new file mode 100644 index 000000000..b3a8460c8 --- /dev/null +++ b/web_responsive_company/readme/INSTALL.rst @@ -0,0 +1,5 @@ +if the OCA module ``res_company_code`` (OCA module present in the +multi-company repository) is installed, the search will be done +also on the company codes. + +Ref : https://github.com/OCA/multi-company/tree/12.0/res_company_code diff --git a/web_responsive_company/readme/ROADMAP.rst b/web_responsive_company/readme/ROADMAP.rst new file mode 100644 index 000000000..1f60556d5 --- /dev/null +++ b/web_responsive_company/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +In V13+, the current company of the user is a many2many fields. +So the UI of this module should be highly refactored, introducing checkboxes +to work in more recent version. diff --git a/web_responsive_company/readme/USAGE.rst b/web_responsive_company/readme/USAGE.rst new file mode 100644 index 000000000..d5fd98b3b --- /dev/null +++ b/web_responsive_company/readme/USAGE.rst @@ -0,0 +1,13 @@ +* click on the current company name + +* The list of the companies are now displayed with the logo and the code (if defined), and there are ordered by complete name. (code and name) + +.. figure:: ../static/description/company_menu.png + +* It is also possible to search by complete name, in the same way as for the menus. + +.. figure:: ../static/description/company_menu_search.png + +**Note** : A new access key is available on 'Y' to switch company. + +.. figure:: ../static/description/shortcut.png diff --git a/web_responsive_company/static/description/company_menu.png b/web_responsive_company/static/description/company_menu.png new file mode 100644 index 000000000..4b3c1422d Binary files /dev/null and b/web_responsive_company/static/description/company_menu.png differ diff --git a/web_responsive_company/static/img/res_company-acsone.png b/web_responsive_company/static/img/res_company-acsone.png new file mode 100644 index 000000000..8a8bef5ec Binary files /dev/null and b/web_responsive_company/static/img/res_company-acsone.png differ diff --git a/web_responsive_company/static/img/res_company-akretion.png b/web_responsive_company/static/img/res_company-akretion.png new file mode 100644 index 000000000..12b824c03 Binary files /dev/null and b/web_responsive_company/static/img/res_company-akretion.png differ diff --git a/web_responsive_company/static/img/res_company-camp_to_camp.svg b/web_responsive_company/static/img/res_company-camp_to_camp.svg new file mode 100644 index 000000000..8861e8a75 --- /dev/null +++ b/web_responsive_company/static/img/res_company-camp_to_camp.svg @@ -0,0 +1,61 @@ + +image/svg+xml + + \ No newline at end of file diff --git a/web_responsive_company/static/img/res_company-coop_it_easy.png b/web_responsive_company/static/img/res_company-coop_it_easy.png new file mode 100644 index 000000000..20cd3ce6c Binary files /dev/null and b/web_responsive_company/static/img/res_company-coop_it_easy.png differ diff --git a/web_responsive_company/static/img/res_company-grap.png b/web_responsive_company/static/img/res_company-grap.png new file mode 100644 index 000000000..48e33305c Binary files /dev/null and b/web_responsive_company/static/img/res_company-grap.png differ diff --git a/web_responsive_company/static/img/res_company-tecnativa.svg b/web_responsive_company/static/img/res_company-tecnativa.svg new file mode 100644 index 000000000..f42a30d0a --- /dev/null +++ b/web_responsive_company/static/img/res_company-tecnativa.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web_responsive_company/static/src/js/web_responsive_company.js b/web_responsive_company/static/src/js/web_responsive_company.js new file mode 100644 index 000000000..440df664f --- /dev/null +++ b/web_responsive_company/static/src/js/web_responsive_company.js @@ -0,0 +1,213 @@ +/* + Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) + Copyright Tecnativa - Jairo Llopis + Copyright Tecnativa - Alexandre Díaz + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + Part of the code comes from web_responsive module. (same repository) +*/ + +odoo.define('web_responsive_company', function (require) { + 'use strict'; + + var SwitchCompanyMenu = require("web.SwitchCompanyMenu"); + var session = require('web.session'); + var config = require("web.config"); + var core = require("web.core"); + + + function findNames (memo, company) { + memo[company.complete_name] = company; + return memo; + } + + + SwitchCompanyMenu.include({ + events: _.extend({ + "keydown .search-input input": "_searchResultsNavigate", + "input .search-input input": "_searchCompaniesSchedule", + "click .o-menu-search-result": "_searchResultChosen", + "shown.bs.dropdown": "_searchFocus", + "hidden.bs.dropdown": "_searchReset", + "hide.bs.dropdown": "_hideCompaniesMenu", + }, SwitchCompanyMenu.prototype.events), + + + /** + * Load complete companies. + * + * @override + */ + init: function () { + this._super.apply(this, arguments); + this._companies = session.complete_companies; + this._searchableCompanies = _.reduce( + this._companies, + findNames, + {} + ); + this._search_def = $.Deferred(); + }, + + /** + * @override + */ + start: function () { + this._super.apply(this, arguments); + // rerender element to remove html that is hard inserted in the odoo Core function + // and so read the name of the company + this.renderElement(); + if (!this.isMobile) { + this.$('.oe_topbar_name').text(session.user_companies.current_company[1]); + } + this.$search_container = this.$(".search-container"); + this.$search_input = this.$(".search-input input"); + this.$search_results = this.$(".search-results"); + }, + + /** + * Autofocus on search field on big screens. + */ + _searchFocus: function () { + if (!config.device.isMobile) { + this.$search_input.focus(); + } + }, + + /** + * Reset search input and results + */ + _searchReset: function () { + this.$search_container.removeClass("has-results"); + this.$search_results.empty(); + this.$search_input.val(""); + }, + + /** + * Navigate among search results + * + * @param {jQuery.Event} event + */ + _searchResultsNavigate: function (event) { + // Find current results and active element (1st by default) + var all = this.$search_results.find(".o-menu-search-result"), + pre_focused = all.filter(".active") || $(all[0]), + offset = all.index(pre_focused), + key = event.key; + // Keyboard navigation only supports search results + if (!all.length) { + return; + } + // Transform tab presses in arrow presses + if (key === "Tab") { + event.preventDefault(); + key = event.shiftKey ? "ArrowUp" : "ArrowDown"; + } + switch (key) { + // Pressing enter is the same as clicking on the active element + case "Enter": + pre_focused.click(); + break; + // Navigate up or down + case "ArrowUp": + offset--; + break; + case "ArrowDown": + offset++; + break; + default: + // Other keys are useless in this event + return; + } + // Allow looping on results + if (offset < 0) { + offset = all.length + offset; + } else if (offset >= all.length) { + offset -= all.length; + } + // Switch active element + var new_focused = $(all[offset]); + pre_focused.removeClass("active"); + new_focused.addClass("active"); + this.$search_results.scrollTo(new_focused, { + offset: { + top: this.$search_results.height() * -0.5, + }, + }); + }, + + /* + * Control if AppDrawer can be closed + */ + _hideCompaniesMenu: function () { + return !this.$('input').is(':focus'); + }, + + _companyInfo: function (key) { + var company = this._searchableCompanies[key]; + return company; + }, + + /** + * Schedule a search on current menu items. + */ + _searchCompaniesSchedule: function () { + this._search_def.reject(); + this._search_def = $.Deferred(); + setTimeout(this._search_def.resolve.bind(this._search_def), 50); + this._search_def.done(this._searchCompanies.bind(this)); + }, + + /** + * Search among available menu items, and render that search. + */ + _searchCompanies: function () { + var query = this.$search_input.val(); + if (query === "") { + this.$search_container.removeClass("has-results"); + this.$search_results.empty(); + return; + } + var results = fuzzy.filter( + query, + _.keys(this._searchableCompanies), + { + pre: "", + post: "", + } + ); + this.$search_container.toggleClass( + "has-results", + Boolean(results.length) + ); + this.$search_results.html( + core.qweb.render( + "web_responsive_company.CompanySearchResults", + { + results: results, + widget: this, + } + ) + ); + }, + + /** + * Use chooses a search result, so we navigate to that menu + * + * @param {jQuery.Event} event + */ + _searchResultChosen: function (event) { + this._onClick(event); + }, + + getCompanies: function () { + return this._companies; + }, + + isCurrentCompany: function(company) { + return session.company_id === company.id; + }, + + }); + +}); diff --git a/web_responsive_company/static/src/scss/web_responsive_company.scss b/web_responsive_company/static/src/scss/web_responsive_company.scss new file mode 100644 index 000000000..ad428311b --- /dev/null +++ b/web_responsive_company/static/src/scss/web_responsive_company.scss @@ -0,0 +1,81 @@ +/* + Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) + Copyright Tecnativa - Jairo Llopis + Copyright Tecnativa - Alexandre Díaz + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + Part of the code comes from web_responsive module. (same repository) +*/ + +.o_switch_company_menu { + + .dropdown-menu.show { + @include full-screen-dropdown(); + + // Display apps in a grid + align-content: flex-start; + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: flex-start; + + @include media-breakpoint-up(lg) { + padding: { + left: 20vw; + right: 20vw; + } + } + + .o-company { + align-items: center; + display: flex; + flex-direction: column; + justify-content: flex-start; + border-radius: 5px; + padding: 5px; + + /*// Size depends on screen*/ + width: 33.33333333%; + @include media-breakpoint-up(sm) { + width: 25%; + } + + @include media-breakpoint-up(md) { + width: 16.6666666%; + } + + .o-company-logo-container { + height: 100px; + width: 100px; + text-align: center; + line-height:100px; + background-color:white; + border-radius: 3px; + } + + .o-company-logo-img { + max-width: 95px; + } + + } + + // Hide companies icons when searching + .has-results ~ .o-company { + display: none; + } + + .o-company-selected-yes { + background-color:#DDD; + } + + .o-company-selected-no { + cursor: pointer; + + &:hover { + background-color:#EEE; + } + } + + } + +} diff --git a/web_responsive_company/static/src/xml/web_responsive_company.xml b/web_responsive_company/static/src/xml/web_responsive_company.xml new file mode 100644 index 000000000..9b86f0e5f --- /dev/null +++ b/web_responsive_company/static/src/xml/web_responsive_company.xml @@ -0,0 +1,86 @@ + + + diff --git a/web_responsive_company/views/assets.xml b/web_responsive_company/views/assets.xml new file mode 100644 index 000000000..3d27655a8 --- /dev/null +++ b/web_responsive_company/views/assets.xml @@ -0,0 +1,16 @@ + + + + + +