Browse Source

[ADD] web_group_by_percentage

[ADD] web_group_by_percentage

[ADD] web_group_by_percentage

[FIX] Readme screenshot paths
pull/1210/head
tarteo 5 years ago
parent
commit
1a4099a8dc
  1. 84
      web_group_by_percentage/README.rst
  2. 0
      web_group_by_percentage/__init__.py
  3. 17
      web_group_by_percentage/__manifest__.py
  4. 1
      web_group_by_percentage/readme/CONTRIBUTORS.rst
  5. 4
      web_group_by_percentage/readme/DESCRIPTION.rst
  6. 4
      web_group_by_percentage/readme/USAGE.rst
  7. BIN
      web_group_by_percentage/static/description/screenshot.png
  8. 94
      web_group_by_percentage/static/src/js/backend.js
  9. 3
      web_group_by_percentage/static/src/scss/backend.scss
  10. 14
      web_group_by_percentage/templates/assets.xml

84
web_group_by_percentage/README.rst

@ -0,0 +1,84 @@
====================================
Show percentage (of total) in groups
====================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/12.0/web_group_by_percentage
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_group_by_percentage
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module shows the percentage of the total sum in group by rows.
.. image:: ../static/description/screenshot.png
:alt: Printscreen of percentages in group rows
**Table of contents**
.. contents::
:local:
Usage
=====
To use this module, you need to:
#. Go to any list view;
#. group by one or more fields.
Bug Tracker
===========
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.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_group_by_percentage%0Aversion:%2012.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.
Credits
=======
Authors
~~~~~~~
* Onestein
Contributors
~~~~~~~~~~~~
* Dennis Sluijk <d.sluijk@onestein.nl>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/12.0/web_group_by_percentage>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

0
web_group_by_percentage/__init__.py

17
web_group_by_percentage/__manifest__.py

@ -0,0 +1,17 @@
{
'name': 'Show percentage (of total) in groups',
'summary': 'Show the percentage of the total sum in group by rows',
'author': 'Onestein, Odoo Community Association (OCA)',
'development_status': 'Beta',
'website': 'https://github.com/OCA/web',
'category': 'Web',
'license': 'AGPL-3',
'version': '12.0.1.0.0',
'depends': [
'web',
],
'data': [
'templates/assets.xml'
],
'installable': True,
}

1
web_group_by_percentage/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Dennis Sluijk <d.sluijk@onestein.nl>

4
web_group_by_percentage/readme/DESCRIPTION.rst

@ -0,0 +1,4 @@
This module shows the percentage of the total sum in group by rows.
.. image:: ../static/description/screenshot.png
:alt: Printscreen of percentages in group rows

4
web_group_by_percentage/readme/USAGE.rst

@ -0,0 +1,4 @@
To use this module, you need to:
#. Go to any list view;
#. group by one or more fields.

BIN
web_group_by_percentage/static/description/screenshot.png

After

Width: 173  |  Height: 167  |  Size: 6.4 KiB

94
web_group_by_percentage/static/src/js/backend.js

@ -0,0 +1,94 @@
/* Copyright 2019 Onestein
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
odoo.define('web_group_by_percentage', function (require) {
"use strict";
var ListRenderer = require('web.ListRenderer'),
BasicModel = require('web.BasicModel');
ListRenderer.include({
/**
* Render the percentage to the group row.
*
* @override
*/
_renderGroupRow: function (group) {
var self = this;
var res = this._super.apply(this, arguments);
_.each(group.aggregatePercentages, function (percentage, field) {
var cellIndex = _.findIndex(self.columns, function (column) {
if (field === column.attrs.name) {
return true;
}
});
var $cell = $(res.find('td').get(cellIndex - 1));
var $b = $('<span>')
.addClass('web_group_by_percentage')
.html(_.str.sprintf('%s%% ', percentage.toFixed(2)))
.data('percentage', percentage);
$cell.prepend($b);
});
return res;
},
});
BasicModel.include({
/**
* Adds aggregatePercentages to the result.
*
* @override
*/
get: function () {
var result = this._super.apply(this, arguments),
dp = result && this.localData[result.id];
if (dp) {
if (dp.aggregatePercentages) {
result.aggregatePercentages = $.extend({}, dp.aggregatePercentages);
}
}
return result;
},
/**
* Calculate percentages.
*
* @override
*/
_readGroup: function () {
var self = this,
res = this._super.apply(this, arguments);
res.done(function (list) {
// Calculate totals
var sums = {};
_.each(list.data, function (groupId) {
var group = self.get(groupId);
_.each(group.aggregateValues, function (value, field) {
if (!(field in sums)) {
sums[field] = 0;
}
sums[field] += value;
});
});
// Calculate percentages
_.each(list.data, function (groupId) {
var group = self.get(groupId),
aggregatePercentages = {};
_.each(_.keys(sums), function (field) {
var percentage = 0;
if (sums[field]) {
percentage = (group.aggregateValues[field] / sums[field]) * 100;
}
aggregatePercentages[field] = percentage;
});
var dp = self.localData[groupId];
dp.aggregatePercentages = aggregatePercentages;
});
return list;
});
return res;
},
});
});

3
web_group_by_percentage/static/src/scss/backend.scss

@ -0,0 +1,3 @@
.web_group_by_percentage {
font-weight: bold;
}

14
web_group_by_percentage/templates/assets.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Onestein
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr=".">
<script src="/web_group_by_percentage/static/src/js/backend.js"></script>
</xpath>
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/web_group_by_percentage/static/src/scss/backend.scss"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save