diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 5c2c59c2321..99ae65a5aab 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -103,6 +103,7 @@ You could use this simplified accounting in case you work with an (external) acc ], 'web.assets_frontend': [ 'account/static/src/js/account_portal_sidebar.js', + 'account/static/src/js/account_portal.js', ], 'web.assets_tests': [ 'account/static/tests/tours/**/*', diff --git a/addons/account/static/src/js/account_portal.js b/addons/account/static/src/js/account_portal.js new file mode 100644 index 00000000000..f4f6a9a1cc2 --- /dev/null +++ b/addons/account/static/src/js/account_portal.js @@ -0,0 +1,12 @@ +/** @odoo-module */ + +import publicWidget from 'web.public.widget'; + +publicWidget.registry.PortalHomeCounters.include({ + /** + * @override + */ + _getCountersAlwaysDisplayed() { + return this._super(...arguments).concat(['invoice_count']); + }, +}); diff --git a/addons/portal/static/src/js/portal.js b/addons/portal/static/src/js/portal.js index da8cda28308..fff2910367d 100644 --- a/addons/portal/static/src/js/portal.js +++ b/addons/portal/static/src/js/portal.js @@ -70,27 +70,51 @@ publicWidget.registry.PortalHomeCounters = publicWidget.Widget.extend({ // Private //-------------------------------------------------------------------------- + /** + * Return a list of counters name linked to a line that we want to keep + * regardless of the number of documents present + * @private + * @returns {Array} + */ + _getCountersAlwaysDisplayed() { + return []; + }, + /** * @private */ async _updateCounters(elem) { const numberRpc = 3; - const needed = this.$('[data-placeholder_count]') - .map((i, o) => $(o).data('placeholder_count')) - .toArray(); + const needed = Object.values(this.el.querySelectorAll('[data-placeholder_count]')) + .map(documentsCounterEl => documentsCounterEl.dataset['placeholder_count']); const counterByRpc = Math.ceil(needed.length / numberRpc); // max counter, last can be less + const countersAlwaysDisplayed = this._getCountersAlwaysDisplayed(); const proms = [...Array(Math.min(numberRpc, needed.length)).keys()].map(async i => { - await this._rpc({ + const documentsCountersData = await this._rpc({ route: "/my/counters", params: { counters: needed.slice(i * counterByRpc, (i + 1) * counterByRpc) }, - }).then(data => { - Object.keys(data).map(k => this.$("[data-placeholder_count='" + k + "']").text(data[k])); }); + Object.keys(documentsCountersData).forEach(counterName => { + const documentsCounterEl = this.el.querySelector(`[data-placeholder_count='${counterName}']`); + documentsCounterEl.textContent = documentsCountersData[counterName]; + // The element is hidden by default, only show it if its counter is > 0 or if it's in the list of counters always shown + if (documentsCountersData[counterName] !== 0 || countersAlwaysDisplayed.includes(counterName)) { + documentsCounterEl.parentElement.classList.remove('d-none'); + } + }); + return documentsCountersData; + }); + return Promise.all(proms).then((results) => { + const counters = results.reduce((prev, current) => Object.assign({...prev, ...current}), {}); + this.el.querySelector('.o_portal_doc_spinner').remove(); + // Display a message when there are no documents available if there are no counters > 0 and no counters always shown + if (!countersAlwaysDisplayed.length && !Object.values(counters).filter((val) => val > 0).length) { + this.el.querySelector('.o_portal_no_doc_message').classList.remove('d-none'); + } }); - return Promise.all(proms); }, }); diff --git a/addons/portal/views/portal_templates.xml b/addons/portal/views/portal_templates.xml index 3ed601ce08e..9ff33680d61 100644 --- a/addons/portal/views/portal_templates.xml +++ b/addons/portal/views/portal_templates.xml @@ -187,6 +187,8 @@

Documents

+
+

No Documents to display

@@ -194,7 +196,7 @@