Coder Social home page Coder Social logo

button_no_save's Introduction

button_no_save

Trigger the onchange function when clicking an odoo button instead of saving the document and go to read-only mode

When we are creating or editing a document in odoo and then click a button, odoo will save that document and go to the read-only mode. If the document is opened in a modal, the modal will be closed. In some scenarios, this behavior feels not right.

With this module, you can configure your button to prevent that behavior. This module will trigger the onchange function instead of the save function, so you can review your document and make some editing before saving it. And the biggest advantage is, with this module you can prevent odoo to close the modal when you click a button.

How it works ?

First, you must provide a Char field with any name. This field will be used to trigger the onchange function

trigger_field = fields.Char()

Then provide one or two methods. The first method must be decorated with @api.onchange. This method will be called by odoo when you click your desired button in edit mode. This method is mandatory.

@api.onchange('trigger_field')
def onchange_trigger_field(self):
    print('This method will be called in edit mode')

The second method is optional. This method will be called by odoo when you click your desired button in read-only mode.

def recompute_total(self):
    print('This method will be called in readonly mode')

Then in your form/view write the triggered field, please set it to invisible.

<field name="trigger_field" invisible="1" />

The next step is to write your object type button and set your second method as name if you want odoo to call the different method when you click your desired button

<button name="recompute_total" string="Compute Result" type="object" />

But if you want odoo to call the same method both in edit and read-only mode please write your onchange method as your button name

<button name="onchange_trigger_field" string="Compute Result" type="object" />

The final step is to add this module special attribute to your button. It is the triggeronchange with the value of your Char trigger field

<button name="onchange_trigger_field" string="Compute Result" type="object" triggeronchange="trigger_field" />

Trigger onchange function when click an odoo button

No closing modal when click an odoo button

Please download the demo module here

This module is tested in odoo v14. If you found any bug please report it to me.

button_no_save's People

Contributors

znry27 avatar

Stargazers

Lars Trey avatar biu~biu~biu avatar Myrrkel avatar  avatar

Watchers

Lars Trey avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.