Hi everyone,
I have a field of type image in Odoo 12, declared as:
image = fields.Binary("Image", attachment=True,)
On the form view I added the code for the user to choose an image.
What I need to do is, on both create and write methods, check if there is an image attached to the field and if not, set a default image to that field.
What I have tried (for write method as an example):
@api.model
def write(self, vals, context=None
if not vals.get(self.image, False):
get_image = "/mymodule/static/img/noimage.jpg"
vals['image'] = get_image
return super(mymodule_model, self).write(vals)
Using this code i get the error: AttributeError: 'list' object has no attribute 'get'
also tried..
@api.model
def write(self, vals, contect=None):
if (self.image == False):
get_imae = "/mymodule/static/img/noimage.jpg"
vals['image'] = get_image
return super(mymodule_model, self).write(vals)
...and does not work either!
How can I test if the image field is empty and if so, have Odoo to save a default image to the database.
Thank you in advance
Regards