odoo-10 - Odoo 10,显示默认图像
问题描述
如何以表单显示默认图像(保存在 /my_module/static/img/car1.png 中)?
我有一个像这样的二进制字段:
car_image =field.Binary(string="car1",default=??)
在xml中,我给了这样的:
请帮忙
解决方案
你可以_get_default_image
参考res.partner.py
@api.model
def _get_default_image(self, partner_type, is_company, parent_id):
if getattr(threading.currentThread(), 'testing', False) or self._context.get('install_mode'):
return False
colorize, img_path, image = False, False, False
if partner_type in ['other'] and parent_id:
parent_image = self.browse(parent_id).image
image = parent_image and base64.b64decode(parent_image) or None
if not image and partner_type == 'invoice':
img_path = get_module_resource('base', 'static/src/img', 'money.png')
elif not image and partner_type == 'delivery':
img_path = get_module_resource('base', 'static/src/img', 'truck.png')
elif not image and is_company:
img_path = get_module_resource('base', 'static/src/img', 'company_image.png')
elif not image:
img_path = get_module_resource('base', 'static/src/img', 'avatar.png')
colorize = True
if img_path:
with open(img_path, 'rb') as f:
image = f.read()
if image and colorize:
image = tools.image_colorize(image)
return tools.image_resize_image_big(base64.b64encode(image))
创建函数
@api.model
def create(self, vals):
if vals.get('website'):
vals['website'] = self._clean_website(vals['website'])
if vals.get('parent_id'):
vals['company_name'] = False
# compute default image in create, because computing gravatar in the onchange
# cannot be easily performed if default images are in the way
if not vals.get('image'):
vals['image'] = self._get_default_image(vals.get('type'), vals.get('is_company'), vals.get('parent_id'))
tools.image_resize_images(vals)
partner = super(Partner, self).create(vals)
partner._fields_sync(vals)
partner._handle_first_contact_creation()
return partner
希望这会帮助你。
推荐阅读
- android - 如何在按下后退的情况下从活动中结束应用程序而不返回到上一个活动
- woocommerce - WooCommerce:分页未出现在商店页面上
- node.js - Azure 通信服务 Web/JS 调用 SDK - 是否可以接收到 PSTN 的来电并获取音频流?
- python - 应用具有多个匹配条件的 numpy 掩码
- tsql - 将 nvarchar 转换为日期时间/日期后的计算
- autolayout - 两个 UITableViewCell 具有相同的约束,但在 Interface Builder 中显示不同
- php - 使用带有 mysqli 准备语句的哈希密码时插入语句失败
- kubernetes-helm - 当您不知道名称时,检查 values.yaml 属性中是否有任何条目?
- r - 不同结构的分离柱
- flutter - 颤振数据表