Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
1647 Widoki

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.


Awatar
Odrzuć
Autor Najlepsza odpowiedź

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)]}">


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
kwi 25
3832
5
mar 25
19278
1
cze 24
1940
1
maj 24
1983
1
mar 24
2973