-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14.0][ADD] New addon web_pivot_hide_total
- Loading branch information
1 parent
3aab677
commit 1f8b3b7
Showing
16 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../web_pivot_hide_total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions
86
web_pivot_hide_total/static/src/js/views/pivot/pivot_model_hide_total.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
17 changes: 17 additions & 0 deletions
17
web_pivot_hide_total/static/src/js/views/pivot/pivot_view_hide_total.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |