Skip to content

Commit

Permalink
Merge PR OCA#1855 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed May 18, 2024
2 parents 9a1e95b + 1f8b3b7 commit d0d552b
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/web_pivot_hide_total/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions web_pivot_hide_total/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is going to be generated by oca-gen-addon-readme.
Empty file.
16 changes: 16 additions & 0 deletions web_pivot_hide_total/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Web Pivot View Hide Total",
"summary": """
This addon adds a new inherited version of pivot view.
It intends to hide the last total column when required.""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"data": ["views/web_pivot_hide_total_views.xml"],
"installable": True,
}
18 changes: 18 additions & 0 deletions web_pivot_hide_total/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Activation of the view is done in xml file, using "js_class" tag.

In your xml file, declare a pivot view with js_class="web_pivot_hide_total".

For example :

.. code-block:: xml
<record id='my_new_pivot_view' model='ir.ui.view'>
<field name="model">my.model</field>
<field name="arch" type="xml">
<pivot string="My new pivot view name" js_class="web_pivot_hide_total">
<field name="My field" type="row" />
<field name="My column" type="col" />
<field name="My measure" type="measure" />
</pivot>
</field>
</record>
Empty file.
2 changes: 2 additions & 0 deletions web_pivot_hide_total/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Régis Pirard <regis.pirard@acsone.eu>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
13 changes: 13 additions & 0 deletions web_pivot_hide_total/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
In some cases, we want to use the columns of a pivot view
to compare datas, but the total sum displayed in the last column
juste makes no sens.

This module intends to hide that last total column when required.

.. image:: ../static/description/before.png
:alt: Before

\

.. image:: ../static/description/after.png
:alt: After
1 change: 1 addition & 0 deletions web_pivot_hide_total/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Allow setting default dialog size per user.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_pivot_hide_total/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
odoo.define("web.PivotModelHideTotal", function (require) {
"use strict";

const {_t} = require("web.core");

const PivotModel = require("web.PivotModel");

const PivotModelHideTotal = PivotModel.extend({
/**
* @override
*/
_getTableHeaders: function () {
var colGroupBys = this._getGroupBys().colGroupBys;
var height = colGroupBys.length + 1;
var measureCount = this.data.measures.length;
var originCount = this.data.origins.length;
var leafCounts = this._getLeafCounts(this.colGroupTree);
var headers = [];
var measureColumns = [];

// 1) generate col group rows (total row + one row for each col groupby)
var colGroupRows = new Array(height).fill(0).map(function () {
return [];
});
// Blank top left cell
colGroupRows[0].push({
height: height + 1 + (originCount > 1 ? 1 : 0),
title: "",
width: 1,
});

// Col groupby cells with group values
/**
* Recursive function that generates the header cells corresponding to
* the groups of a given tree.
*
* @param {Object} tree
* @param {Object} fields
*/
function generateTreeHeaders(tree, fields) {
var group = tree.root;
var rowIndex = group.values.length;
var row = colGroupRows[rowIndex];
var groupId = [[], group.values];
var isLeaf = !tree.directSubTrees.size;
var leafCount = leafCounts[JSON.stringify(tree.root.values)];
var cell = {
groupId: groupId,
height: isLeaf ? colGroupBys.length + 1 - rowIndex : 1,
isLeaf: isLeaf,
label:
rowIndex === 0
? undefined
: fields[colGroupBys[rowIndex - 1].split(":")[0]].string,
title: group.labels[group.labels.length - 1] || _t("Total"),
width: leafCount * measureCount * (2 * originCount - 1),
};
row.push(cell);
if (isLeaf) {
measureColumns.push(cell);
}

[...tree.directSubTrees.values()].forEach(function (subTree) {
generateTreeHeaders(subTree, fields);
});
}

generateTreeHeaders(this.colGroupTree, this.fields);

headers = headers.concat(colGroupRows);

// 2) generate measures row
var measuresRow = this._getMeasuresRow(measureColumns);
headers.push(measuresRow);

// 3) generate origins row if more than one origin
if (originCount > 1) {
headers.push(this._getOriginsRow(measuresRow));
}

return headers;
},
});

return PivotModelHideTotal;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
odoo.define("web_pivot_hide_total.PivotViewHideTotal", function (require) {
"use strict";

const PivotView = require("web.PivotView");
const PivotModelHideTotal = require("web.PivotModelHideTotal");
const viewRegistry = require("web.view_registry");

const PivotViewHideTotal = PivotView.extend({
config: _.extend({}, PivotView.prototype.config, {
Model: PivotModelHideTotal,
}),
});

viewRegistry.add("web_pivot_hide_total", PivotViewHideTotal);

return PivotViewHideTotal;
});
21 changes: 21 additions & 0 deletions web_pivot_hide_total/views/web_pivot_hide_total_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template
id="web_pivot_hide_total_assets_backend"
name="web_pivot_hide_total assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_pivot_hide_total/static/src/js/views/pivot/pivot_model_hide_total.js"
/>
<script
type="text/javascript"
src="/web_pivot_hide_total/static/src/js/views/pivot/pivot_view_hide_total.js"
/>
</xpath>
</template>
</odoo>

0 comments on commit d0d552b

Please sign in to comment.