Skip to Content
Menu
This question has been flagged
1 Reply
1160 Views

When I edit settings without saving, I nicely see "Unsaved Changes" on the top. 

For a custom addon now I have the requirement to hide an action, when there are unsaved changes and show a message.


Does Odoo provide helper classes for this, for example "o_settings_dirty_only" in a similar matter it has the o_read_only and o_edit_only classes in other forms?


It seems, the "Unsaved Changes" on the top with the o_dirty_warning feature do not add any class up the hierarchy, that I could use, but maybe I missed something.


Avatar
Discard
Author Best Answer

For everybody who has a similar problem, here a possible solution, or rather workaround, that works for related fields. Note, that most fields in settings view are related fields, that relate, for example, to the company or website records. 

You can add a computed boolean field on the settings model, that compares if the field is the same as on the related model. In my case, this looked similar to this:

related_field = fields.Many2one("stock.warehouse", related="website_id.other_warehouse_id")

@api.onchange("related_field")
def _compute_can_execute_action_depending_on_related_field(self):
for record in self:
if not record.related_field or (
record.related_field
!= record.website_id.related_field
):
record.related_field = False
else:
record.related_field = True

can_execute_action_depending_on_related_field = fields.Boolean(
compute=_compute_can_execute_action_depending_on_related_field,
)

Then, you can use it in your settings view:

field name="can_execute_action_depending_on_related_field" invisible="1"/>
div attrs="{'invisible': [('can_execute_action_depending_on_related_field', '=', False)]}">


Avatar
Discard
Related Posts Replies Views Activity
4
Dec 24
14795
1
Jun 24
626
1
May 24
323
1
Nov 23
685
1
Mar 24
1376