Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1690 Lượt xem

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.


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 25
5046
5
thg 3 25
19582
1
thg 6 24
2063
1
thg 5 24
2121
1
thg 3 24
3083