forked from Smile-SA/odoo_addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Improve aggregate sum on views list with the sum of roundings
- Loading branch information
1 parent
cc7e31b
commit 1e1a8b8
Showing
3 changed files
with
71 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
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,57 @@ | ||
odoo.define('smile_decimal_precision.ListRenderer', function (require) { | ||
"use strict"; | ||
|
||
var ListRenderer = require('web.ListRenderer'); | ||
var field_utils = require('web.field_utils'); | ||
|
||
ListRenderer.include({ | ||
|
||
_computeColumnAggregates: function (data, column) { | ||
var attrs = column.attrs; | ||
var field = this.state.fields[attrs.name]; | ||
if (!field) { | ||
return; | ||
} | ||
var type = field.type; | ||
if (type !== 'integer' && type !== 'float' && type !== 'monetary') { | ||
return; | ||
} | ||
var func = (attrs.sum && 'sum') || (attrs.avg && 'avg') || | ||
(attrs.max && 'max') || (attrs.min && 'min'); | ||
if (func) { | ||
var count = 0; | ||
var aggregateValue = (func === 'max') ? -Infinity : (func === 'min') ? Infinity : 0; | ||
_.each(data, function (d) { | ||
count += 1; | ||
var value = (d.type === 'record') ? d.data[attrs.name] : d.aggregateValues[attrs.name]; | ||
// Added by Smile | ||
var formatFunc = field_utils.format[column.attrs.widget]; | ||
if (!formatFunc) { | ||
formatFunc = field_utils.format[field.type]; | ||
} | ||
value = field_utils.parse.float( | ||
formatFunc(value, d.fields[attrs.name], {noSymbol: true})); | ||
// End by Smile | ||
if (func === 'avg') { | ||
aggregateValue += value; | ||
} else if (func === 'sum') { | ||
aggregateValue += value; | ||
} else if (func === 'max') { | ||
aggregateValue = Math.max(aggregateValue, value); | ||
} else if (func === 'min') { | ||
aggregateValue = Math.min(aggregateValue, value); | ||
} | ||
}); | ||
if (func === 'avg') { | ||
aggregateValue = count ? aggregateValue / count : aggregateValue; | ||
} | ||
column.aggregate = { | ||
help: attrs[func], | ||
value: aggregateValue, | ||
}; | ||
} | ||
}, | ||
|
||
}); | ||
|
||
}); |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<odoo> | ||
<data> | ||
|
||
<template id="assets_backend" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" src="/smile_decimal_precision/static/src/js/list_renderer.js"></script> | ||
</xpath> | ||
</template> | ||
|
||
</data> | ||
</odoo> |