扫码阅读
手机扫码阅读

在Odoo13实现from视图按钮的一些定制化开发

293 2024-02-28

我们非常重视原创文章,为尊重知识产权并避免潜在的版权问题,我们在此提供文章的摘要供您初步了解。如果您想要查阅更为详尽的内容,访问作者的公众号页面获取完整文章。

查看原文:在Odoo13实现from视图按钮的一些定制化开发
文章来源:
神州数码云基地
扫码关注公众号

Odoo Form View Button Customization Summary

In Odoo, all buttons within a form view trigger a save operation that includes validation by default. However, there are scenarios where the desired button functionality does not require a save operation. To address this, Odoo's button event handling has been customized to allow for more conventional operations.

1. Preventing Default Save Operation on Button Click

The saveAndExecuteAction method has been overridden to prevent the default Odoo save operation when a button is clicked. This involves modifications to the form_controller.js by including custom code. In the XML view, custom attributes are added to the buttons to enable this functionality.

2. Implementing a Cancel Button

A cancel button functionality has been implemented to close the form view without saving changes. This is achieved by detecting the 'm-cancel' custom attribute and invoking the _discardChanges method. Custom attributes must also be added to the relevant buttons in the XML view.

3. Toggling Between Read-Only and Edit Mode

Odoo's form view has both edit and read-only modes within the same page, with the default behavior being that the page becomes read-only after saving. To manually switch between these states, a custom attribute 'm-toggle-mode' is used to toggle the view's mode. The view type is set accordingly and the button's action handler must return this event.

4. Displaying or Hiding Buttons Based on the Form View Mode

This feature works in conjunction with the view mode toggle, allowing for the hiding or showing of buttons or fields depending on whether the form is in edit or read-only mode. The _updateButtons method is updated to toggle visibility using custom CSS classes 'm-form-view-hidden' and 'm-form-edit-hidden'. These classes must be added to the corresponding elements in the XML view.

5. Implementing Save Without Validation

There are cases where data needs to be saved without validation, such as when saving a draft that may not meet mandatory field requirements. To bypass Odoo's validation and save directly, the canBeSaved method is modified to skip validation when the 'm-no-valid' custom attribute is present. This attribute must be added to the relevant buttons in the XML view.

想要了解更多内容?

查看原文:在Odoo13实现from视图按钮的一些定制化开发
文章来源:
神州数码云基地
扫码关注公众号