This question has been flagged

I used defaults attribute and made state field value as 'draft' and once I saved the form its going to To Approve state

Help me out to resolve this 

Thanks in Advance

Avatar
Discard
Author Best Answer

Hi Found solution that is happening because of the work flow defined for the Leave Request

Workflow starting from the Confirm stage so that was happen now I changed workflow to start at the to Submit state now working fine.

Thanks.

Avatar
Discard
Best Answer

Just override the create method of your model, like:

from openerp import api, models 
class leave(models.Model)
_inherit = "module.model_leave"

    @api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
vals['state'] = 'approve'
return super(leave, self).create(vals)


Avatar
Discard
Author

In Create method state value coming as 'draft' only but once saved the form its going to confirm state

The create method get executed when the record is about to be saved, so you will get displayed the record in the form as draft using your defaults and when the user clic save the state field will became approve in the create method.

Author

Due to workflows defined for the object create state value is not effecting