Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7461 Lượt xem

I want to set default product image, if we create a product but we dont upload image, there's no Camera with cross image? but another image, yesterday i was look a module for set it, but it's for Odoo 10 only, i installed but cant.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất
import base64
from odoo import models, fields
from odoo import modules


def get_default_img():
with open(modules.get_module_resource('my_module', 'static/img', 'my_image.png'),
 'rb') as f:
return base64.b64encode(f.read())



class MyModel(models.Model):
_name = 'my.model'

field_binary = fields.Binary(default=get_default_img())

This is the answer, thread will be closed, thanks


src : https://www.iwesabe.com/blog/how-to-set-default-image-for-binary-field-odoo

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

For odoo18 if you want to do it for the website image you should check the product/static/src/img/product_thumbnails.png . Here is the place where comes the default image for website for example. If you want to change it and set another default image you just inherit the method where it is used and replace it with your own static image. Just did it worked. Good luck!

for help you can email me info@nimexsolutions.com

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 4 20
4369
1
thg 3 16
2002
2
thg 9 21
8229
1
thg 5 18
12551
2
thg 6 24
7472