Skip to content

Commit

Permalink
[FIX] web: Correctly aggregate values in exported parent groups
Browse files Browse the repository at this point in the history
[FIX] web: Correctly aggregate values in exported parent groups
--------------------
When exporting a grouped list view with some nested groups, the aggregate value
of parent groups are not correct. It always sums aggregated values of children
whether the group operator is 'sum' or not (could be 'max', 'avg', ...).

This behavior is wrong and can even lead to a crash if the aggregated field is a
date field (e.g. with group_operator='max'). (Try two sum two dates...)

To avoid the crash a quick fix was merged 85cf47f just before OXP. This fix
limited the support of aggregates to only int and float fields.
This commit remove this limitation.

This commit correctly implements the aggregation for parent group for all
field types and all group_operator.

This commit also improves the export feature tests.

[FIX] base export: Manage False in groupby title
--------------------
Before this commit, when we export a list with a groupby on
boolean, the groupby title 'False' is replaced by 'Undefined'
in xls document.

After this commit, with an export and groupby on a boolean, we
will have correct title: True and False.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

closes odoo#38373

Signed-off-by: Yannick Tivisse (yti) <[email protected]>
  • Loading branch information
robodoo authored Oct 16, 2019
2 parents 93d17be + 6225ce6 commit dc03d50
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 196 deletions.
1 change: 1 addition & 0 deletions addons/test_xlsx_export/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions addons/test_xlsx_export/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'test xlsx export',
'version': '0.1',
'category': 'Tests',
'description': """A module to test xlsx export.""",
'depends': ['web', 'test_mail'],
'data': ['ir.model.access.csv'],
'installable': True,
'auto_install': False,
}
3 changes: 3 additions & 0 deletions addons/test_xlsx_export/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_export_group_operator,access_export_group_operator,model_export_group_operator,,1,1,1,1
access_export_group_operator_one2many,access_export_group_operator_one2many,model_export_group_operator_one2many,,1,1,1,1
34 changes: 34 additions & 0 deletions addons/test_xlsx_export/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models

class NewModel(models.Model):
_name = 'export.integer'
_description = 'Export: Integer'

value = fields.Integer(default=4)

def name_get(self):
return [(record.id, "%s:%s" % (self._name, record.value)) for record in self]

class GroupOperator(models.Model):
_name = 'export.group_operator'
_description = 'Export Group Operator'

int_sum = fields.Integer(group_operator='sum')
int_max = fields.Integer(group_operator='max')
float_min = fields.Float(group_operator='min')
float_avg = fields.Float(group_operator='avg')
date_max = fields.Date(group_operator='max')
bool_and = fields.Boolean(group_operator='bool_and')
bool_or = fields.Boolean(group_operator='bool_or')
many2one = fields.Many2one('export.integer')
one2many = fields.One2many('export.group_operator.one2many', 'parent_id')

class GroupOperatorO2M(models.Model):
_name = 'export.group_operator.one2many'
_description = 'Export Group Operator One2Many'

parent_id = fields.Many2one('export.group_operator')
value = fields.Integer()
4 changes: 4 additions & 0 deletions addons/test_xlsx_export/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_export

Loading

0 comments on commit dc03d50

Please sign in to comment.