diff options
| author | Aaron Bohy <aab@odoo.com> | 2019-03-13 15:42:52 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-04-02 11:55:57 +0000 |
| commit | 2be28d4d033b5930e5a16ff02407315a116e9043 (patch) | |
| tree | 0561dbbf8c127d0aea94c6766c6815fe1d1f2d83 /addons/web/models/models.py | |
| parent | 5895d23cbd26beb3bc3c83cc760b3cdbb64b0e85 (diff) | |
[IMP] web,board: enable pagination in grouped lists
With this rev., when there are a lot of groups in a grouped list
view, groups are displayed under several pages, whereas they were
all displayed in the same page before.
This is especially interesting with the new 'expand' attribute, to
ensure that we don't read records for a large number of groups.
By default, the groups limit is set to 80 (like records), and to 10
is the 'expand' attribute is set to true. This limit can be
overriden with the 'groups_limit' attribute.
Part of task 1915702
Diffstat (limited to 'addons/web/models/models.py')
| -rw-r--r-- | addons/web/models/models.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/web/models/models.py b/addons/web/models/models.py index 12e6a422507..271f8b831da 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -18,6 +18,40 @@ class Base(models.AbstractModel): _inherit = 'base' @api.model + def web_read_group(self, domain, fields, groupby, limit=None, offset=0, orderby=False, + lazy=True): + """ + Returns the result of a read_group and the total number of groups matching the search + domain. + + :param domain: search domain + :param fields: list of fields to read (see ``fields``` param of ``read_group``) + :param groupby: list of fields to group on (see ``groupby``` param of ``read_group``) + :param limit: see ``limit`` param of ``read_group`` + :param offset: see ``offset`` param of ``read_group`` + :param orderby: see ``orderby`` param of ``read_group`` + :param lazy: see ``lazy`` param of ``read_group`` + :return: { + 'groups': array of read groups + 'length': total number of groups + } + """ + groups = self.read_group(domain, fields, groupby, offset=offset, limit=limit, + orderby=orderby, lazy=lazy) + + if not groups: + length = 0 + elif limit and len(groups) == limit: + all_groups = self.read_group(domain, ['display_name'], groupby, lazy=True) + length = len(all_groups) + else: + length = len(groups) + offset + return { + 'groups': groups, + 'length': length + } + + @api.model def read_progress_bar(self, domain, group_by, progress_bar): """ Gets the data needed for all the kanban column progressbars. |
