How to change status of a form while clicking Save

Changing Status by Clicking Save In Odoo

 

Step1: First you want to create one status bar in your form

In py file you need to add a new class  and add the field

eg:

from odoo import models,fields,api

class SmartButton(models.Model):
    _name='smart.button'

    state = fields.Selection([
        ('draft', 'Draft'),
        ('approved', 'Approved'),
        ('done', 'Done'),
        ('cancel', 'Cancelled'),
], string='Status', index=True, readonly=True, default='draft')

Step 2: Now you have to create corresponding xml for status
eg:
<record id="enzapps_contract_smart_button" model="ir.ui.view">
  <field name="name">estimate.enzapps.form</field>
  <field name="model">smart.button</field>
  <field name="arch" type="xml">
      <field name="state" widget="statusbar" style="align-right"/>
    </field>
    </record>
</odoo>
then the xml file you can add the manifest and python file you can mension  in models init 
file,new class you can mension security file Now run the module 
the output will be:

In this the status wil be draft state,

Step 3:Then you have to add the code  changing the state
eg:
@api.model
def create(self,vals):
    vals['state'] = 'approved'
    return super(SmartButton,self).create(vals)

@api.model
def write(self,vals):
    vals['state'] = 'approved'
    return super(SmartButton,self).write(vals)


After this you can restart your pycharm and upgrade the module after clicking save button
the output will be like this


To know more about us



		

Leave a Reply

Your email address will not be published.