Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] web_timeline - for relational group fields use default order in related model, fix for default_group_by attribute no relational #2929

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

IJOL
Copy link

@IJOL IJOL commented Sep 5, 2024

No description provided.

@OCA-git-bot
Copy link
Contributor

Hi @tarteo,
some modules you are maintaining are being modified, check this out!

@legalsylvain legalsylvain changed the title [18.0][IMP] if the group field is relational try to use sequence field in related model if it exists [16.0][IMP] if the group field is relational try to use sequence field in related model if it exists Sep 5, 2024
@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch 3 times, most recently from 0c3272a to 360e8af Compare September 5, 2024 15:47
@pedrobaeza pedrobaeza added this to the 16.0 milestone Sep 5, 2024
@IJOL IJOL changed the title [16.0][IMP] if the group field is relational try to use sequence field in related model if it exists [16.0][IMP] web_timeline - if the group field is relational try to use sequence field in related model if it exists Sep 5, 2024
@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch from 157eca7 to bda41fc Compare September 5, 2024 16:19
@carlos-lopez-tecnativa
Copy link
Contributor

@IJOL, could you please give me an example or use case to test this PR? Thanks.

TT50999

@IJOL
Copy link
Author

IJOL commented Sep 27, 2024

@IJOL, could you please give me an example or use case to test this PR? Thanks.

TT50999

if your timeline default_group_by field is a many2* field and the related model has a sequence field it used to order the groups in the timeline left area, in the example in https://github.com/OCA/project/blob/16.0/project_timeline/views/project_project_view.xml if you change default_group_by to project_id which i think you can in that context, with my change the sequence field in the project model should be used as order for the groups in the timeline, thus giving the same order in the timeline that projects has

@pedrobaeza
Copy link
Member

The order should be defined by the model itself with their _order clause, being the sequence or whatever, but it shouldn't be hardcoded. The module should rely on the existing order.

@IJOL
Copy link
Author

IJOL commented Sep 27, 2024

this is exactly what the sequence field does in other contexts like list , trees or whatever, if the group is a model wiith no seuqence, or a plain field it does nothing

@pedrobaeza
Copy link
Member

That's only if the widget="handle" is present AFAIK, but it's not the same context here, as we can't drag and drop for changing such sequence. I insist that we must rely on the model order.

@IJOL
Copy link
Author

IJOL commented Sep 27, 2024

The problem is that Js part reworks the groups, because your are no reading from a projects query that should be ordered you are doingthe groups by the extension it self, and gives up any order i think in the context i use it, and in the example given you order the group as it is stored in the tasks, so no order in projects at all

@IJOL
Copy link
Author

IJOL commented Sep 27, 2024

Just confused the example i use it in project.task context model and i try to group by project_id..

@pedrobaeza
Copy link
Member

When grouping by project, you should query Odoo to return the ordered recordset including all the existing projects.

@IJOL
Copy link
Author

IJOL commented Sep 27, 2024

When grouping by project, you should query Odoo to return the ordered recordset including all the existing projects.

Ok, get your point it should be easy to implement that way too, not actually able to remember why i ended in this solution, not so sure i have now the time to do it.. i will push something if i can

@pedrobaeza
Copy link
Member

Great, let us know. @carlos-lopez-tecnativa FYI

@tarteo
Copy link
Member

tarteo commented Oct 1, 2024

@IJOL are you saying when grouping records, the groups are not ordered by the corresponding model's order?

this is exactly what the sequence field does in other contexts like list , trees or whatever, if the group is a model wiith no seuqence, or a plain field it does nothing

Can you send me a link to where Odoo does this in the tree view etc. Does it there look at hard-coded sequence or _order? Thanks in advance

@IJOL
Copy link
Author

IJOL commented Oct 1, 2024 via email

@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch 2 times, most recently from 328f853 to eb862c9 Compare October 16, 2024 15:07
@IJOL IJOL changed the title [16.0][IMP] web_timeline - if the group field is relational try to use sequence field in related model if it exists [16.0][IMP] web_timeline - for relational group fields use default order in related model, fix for default_group_by attribute no relational Oct 16, 2024
@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch from eb862c9 to 2114bfa Compare October 16, 2024 16:13
@IJOL
Copy link
Author

IJOL commented Oct 17, 2024

As suggested the group's order is obtained from the related model if the default_group_by is relational ( Many2one or Many2many ), i added a fix for other issues i'm having when the group field if is not relational, need reviewers though..

@carlos-lopez-tecnativa @tarteo @pedrobaeza

@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch 2 times, most recently from 832c06a to 1592ce8 Compare October 17, 2024 09:19
@pedrobaeza
Copy link
Member

ping @carlos-lopez-tecnativa

Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally tested, and it works. Just a minor technical change needed for performance reasons.

Comment on lines 387 to 394
const fields = await this._rpc({
model: this.modelName,
method: "fields_get",
args: [[grouped_field]],
context: this.getSession().user_context,
});
const fieldType = fields[grouped_field].type;
const relation = fields[grouped_field].relation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this RPC call can be avoided if you use this.fields, which already contains metadata for fields (such as type, relation, etc.).
image

Suggested change
const fields = await this._rpc({
model: this.modelName,
method: "fields_get",
args: [[grouped_field]],
context: this.getSession().user_context,
});
const fieldType = fields[grouped_field].type;
const relation = fields[grouped_field].relation;
const fieldType = this.fields[grouped_field].type;
const relation = this.fields[grouped_field].relation;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, good catch!!

@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch from 1592ce8 to 44a7b0a Compare November 7, 2024 10:45
Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@carlos-lopez-tecnativa
Copy link
Contributor

ping @pedrobaeza

views: [[false, "form"]],
});
}
console.warn(`Field ${groupField} is not a relational field.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

@@ -2,7 +2,7 @@
Web timeline
============

..
..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem to be done by the IDE stripping out leading spaces. They should be removed.

@@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also shouldn't change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know how that change was done, but it seems legit to me, maybe is the precommit thing..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, because you have a different libraries than the bot, but it will be undone again by the bot. I was trying to avoid noise.

…th a relational field in addition fixes grouping when the field is not relational,

and default_group_by can use a non relational field
@IJOL IJOL force-pushed the 16.0-web_timeline-groups-sequence branch from 44a7b0a to 916e166 Compare November 11, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants