Skip to content

[16.0][IMP] tracking_manager: allow tracking readonly fields - #2813

Merged
OCA-git-bot merged 1 commit into
OCA:16.0from
c4a8-odoo:16.0-imp-tracking_manager
Apr 9, 2024
Merged

OCA-git-bot merged 1 commit into
OCA:16.0from
c4a8-odoo:16.0-imp-tracking_manager

Conversation

@CRogos

@CRogos CRogos commented Jan 19, 2024

Copy link
Copy Markdown
Contributor

@AnizR, @Kev-Roche, @sebastienbeau

What is the reason for the limitation that read_only fields cannot be tracked?
When there have a look at the Odoo native tracking, there are also read_only fields with tracking enabled:
image

In our case we what to track changes on an enterprise table account.asset, where most of the fields are read_only and can only be changed by a separate wizard. But through this wizard, user changes are possible and therefore tracking might be necessary.

Are there any doubt to remove the read_only filter?

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @Kev-Roche, @sebastienbeau,
some modules you are maintaining are being modified, check this out!

@CRogos
CRogos marked this pull request as ready for review January 19, 2024 12:47
)
trackable = fields.Boolean(
compute="_compute_trackable",
store=True,

@AnizR AnizR Jan 26, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did you remove store=True?

I think that you may need to add something in the depends of your compute if the field isn't (re-)computed correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The trackable attribute is already computed, but with this PR we change the implementation how it is computed.
Changing the implementation does not change the stored value automatically.
I agree another options would be an migration update script to recalculate all values.

In think this is the only place where trackable is used. I am not sure if this syntax requires a stored field. But this could also be replaced by an lambda. Beside not changing it, I do not see the benefit of storing this simple value.

def update_custom_tracking(self):
for record in self:
fields = record.field_id.filtered("trackable").filtered_domain(
literal_eval(record.automatic_custom_tracking_domain)
)
fields.write({"custom_tracking": True})
untrack_fields = record.field_id - fields
untrack_fields.write({"custom_tracking": False})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that a migration script might be needed like you suggested but I am not 100% sure about that..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe there is a 3rd opinion over the weekend. I am personally not so a big fan of store=True on computed values. But indeed, changing it has also its risks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ll prefer to keep it stored because in some cases, we want to save a custom choice of fields tracked, and this independently to its kind (read only, related, ...).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think "trackable" is only used as a filter when showing all trackable fields in the list. If this value is False, the field is not in the list and you cannot activating the track. There is also no possibility to change this value in the UI.
image

I do not see why this field needs to be persistent, but I agree changing it could also have unwanted side effects. But I did not have time yet to write the necessary upgrade script, to recalculate all values with the update. Without an update of the stored values, removing the readonly filter has no effect.

@CRogos
CRogos force-pushed the 16.0-imp-tracking_manager branch from 3e073a9 to 26ec789 Compare January 26, 2024 15:39

@Kev-Roche Kev-Roche left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I m not sure about this.
In a way, the behavior of readonly field is known and not changed by users. In order to avoid some noise with too many tracked fields by default, I will prefer to not include the readonly fields as tracked.
IMHO, maybe just set as tracked the relevant fields to follow, as you mention in your specific case, will be enough.

)
trackable = fields.Boolean(
compute="_compute_trackable",
store=True,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ll prefer to keep it stored because in some cases, we want to save a custom choice of fields tracked, and this independently to its kind (read only, related, ...).

@CRogos

CRogos commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

I m not sure about this. In a way, the behavior of readonly field is known and not changed by users. In order to avoid some noise with too many tracked fields by default, I will prefer to not include the readonly fields as tracked. IMHO, maybe just set as tracked the relevant fields to follow, as you mention in your specific case, will be enough.

I only give the user the option to track fields, and do not activate the tracking. (trackable vs. tracking_custom field)
Do you still have concerns?

@Kev-Roche

Kev-Roche commented Feb 6, 2024

Copy link
Copy Markdown
Contributor

I m not sure about this. In a way, the behavior of readonly field is known and not changed by users. In order to avoid some noise with too many tracked fields by default, I will prefer to not include the readonly fields as tracked. IMHO, maybe just set as tracked the relevant fields to follow, as you mention in your specific case, will be enough.

I only give the user the option to track fields, and do not activate the tracking. (trackable vs. tracking_custom field) Do you still have concerns?

But if you set tracking on a new model or just update it with update_custom_tracking button, it will add all the readonly fields as tracked and we don't want too many automatic and unwanted tracked fields. Maybe just trackable as readonly=False and store will be enough to deal with specific cases, or making optional the readonly fields as trackable ?

@CRogos

CRogos commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

I've tested it on res.partner and there are 74 fields tracked instead of 59. Yes these are 15 fields more.
How about initializing the default domain this way to prevent readonly fields from automatic configuration?
image

@CRogos
CRogos force-pushed the 16.0-imp-tracking_manager branch 3 times, most recently from ed1777f to d80df38 Compare February 6, 2024 18:33
@CRogos

CRogos commented Feb 6, 2024

Copy link
Copy Markdown
Contributor Author

I've now re-added the store flag and added an upgrade script to recompute the existing value.

@Kev-Roche Kev-Roche left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as you said "to prevent readonly fields from automatic configuration", my main point is to keep the configuration and reading of tracking fields simple.
From my opinion, the tracking of readonly fields is marginal and can not be the main rule of this module.

cc @sebastienbeau

Comment thread tracking_manager/models/ir_model.py Outdated
Comment thread tracking_manager/models/ir_model.py
@CRogos
CRogos force-pushed the 16.0-imp-tracking_manager branch from d80df38 to 51e6f36 Compare February 6, 2024 19:50
@CRogos

CRogos commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

@Kev-Roche I think everything is done now. Could you update your review to approved?

@CRogos
CRogos requested a review from Kev-Roche February 19, 2024 17:40
@CRogos

CRogos commented Feb 19, 2024

Copy link
Copy Markdown
Contributor Author

I think everything is final now. Could you review again?

@CRogos

CRogos commented Mar 1, 2024

Copy link
Copy Markdown
Contributor Author

@Kev-Roche @AnizR @legalsylvain could update your reviews?

@CRogos

CRogos commented Mar 18, 2024

Copy link
Copy Markdown
Contributor Author

@Kev-Roche

From my opinion, the tracking of readonly fields is marginal and can not be the main rule of this module.

Unfortunately the account_asset module of odoo enterprise is one, were the fields are readonly and the user changes the fields via a wizard. So technically they are readonly, but actually they are not and they are very important to track.

If you really see a risk, I could also add a global setting that needs to be enabled first before allowing to track readonly attributes. But "Keep the configuration simple" could also mean not to add this global setting ;-) .

@pedrobaeza do you have an opinion on this?

@Kev-Roche

Copy link
Copy Markdown
Contributor

@Kev-Roche

From my opinion, the tracking of readonly fields is marginal and can not be the main rule of this module.

Unfortunately the account_asset module of odoo enterprise is one, were the fields are readonly and the user changes the fields via a wizard. So technically they are readonly, but actually they are not and they are very important to track.

If you really see a risk, I could also add a global setting that needs to be enabled first before allowing to track readonly attributes. But "Keep the configuration simple" could also mean not to add this global setting ;-) .

@pedrobaeza do you have an opinion on this?

I m good with the current way

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza

Copy link
Copy Markdown
Member

I think it's usual that some fields are readonly, but unlocked on certain conditions (like state and having force_save="1" parameter) or modified by code, so they should be tracked as well.

@CRogos

CRogos commented Mar 28, 2024

Copy link
Copy Markdown
Contributor Author

@sebastienbeau could you merge?

@Kev-Roche

Copy link
Copy Markdown
Contributor

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-2813-by-Kev-Roche-bump-minor, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Mar 29, 2024
Signed-off-by Kev-Roche
@OCA-git-bot

Copy link
Copy Markdown
Contributor

@Kev-Roche your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-2813-by-Kev-Roche-bump-minor.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@CRogos

CRogos commented Apr 2, 2024

Copy link
Copy Markdown
Contributor Author

@Kev-Roche do you have an idea what's the issue with the merge? Error does not look related to this change? Shall I rebase or could you give it another try?

@Kev-Roche

Copy link
Copy Markdown
Contributor

@CRogos I have no Idea, don't see any related reason... can you rebase please, then I ll try again.

@CRogos
CRogos force-pushed the 16.0-imp-tracking_manager branch from 51e6f36 to 66be890 Compare April 3, 2024 07:43
@CRogos

CRogos commented Apr 3, 2024

Copy link
Copy Markdown
Contributor Author

This themes to be the problem: #2578

@CRogos
CRogos force-pushed the 16.0-imp-tracking_manager branch from 66be890 to 2beff64 Compare April 9, 2024 17:03
@CRogos

CRogos commented Apr 9, 2024

Copy link
Copy Markdown
Contributor Author

@Kev-Roche the problem with the repo has been solved. Could you retry the merge?

@Kev-Roche

Copy link
Copy Markdown
Contributor

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 16.0-ocabot-merge-pr-2813-by-Kev-Roche-bump-minor, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit df96c1a into OCA:16.0 Apr 9, 2024
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at ed9c1bb. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants