In my module I have a binary field and I show that field using the image widget, but when that field has no value, it shows a blank space in the user interface. I would like to know how to set a default image to that field, so when the user has not set a value for the image field the interface would show a default image instead. I am working with odoo 12
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
3
Replies
11107
Views
Hi,
You can try this method,
add a default image in this location "static/src/img"
image = fields.Binary("Photo", default='_get_default_image')
define _get_default_image():
def _get_default_image(self):
image_path = modules.get_module_resource('your_module_name', 'static/src/img', 'default.png')
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
Regards
Dear Ernesto,
This may help you.
https://www.iwesabe.com/blog/how-to-set-default-image-for-binary-field-odoo
Regards
Global Creative Concepts Tech Co Ltd.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
See:- https://learnopenerp.blogspot.com/2016/06/using-binary-fields-in-odoo.html