I wanna change the value of status
once I click save. status
is a selection field [('ok', 'Ok'),('tobe', 'Not Ok')]
status = fields.Selection(
readonly=False,
default='tobe',
related= 'name.status'
)
@api.model
def create(self, values):
self.status= 'ok'
line = super(MyClass, self).create(values)
return line
Status is a related field so after creating change the status of you many2one field.
@api.model
def create(self, values):
rec = super(YouClassName, self).create(values)
# here change the status.
rec.name.status = 'ok'
return rec
The error is in your selection field declaration. It should be like this:
status = fields.Selection([('ok', "OK"),('not ok', "Not OK"),],default='tobe')
@api.multi
def write(self, vals):
vals['status'] = 'ok'
ret = super(Your-Class-Name-here, self).write(vals)
By default, readonly on every field is false, so no need specifying it inside the selection field.
Please, notify me if this solve your challenge. Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With