Skip to Content
Menú
This question has been flagged
1 Respondre
1646 Vistes

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
Descartar
Autor 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
Descartar
Related Posts Respostes Vistes Activitat
2
d’abr. 25
3804
5
de març 25
19267
1
de juny 24
1936
1
de maig 24
1972
1
de març 24
2969