跳至内容
菜单
此问题已终结
3 回复
5166 查看

i want to be able to add default image in wizard form .

形象
丢弃
最佳答案

You can use default_get method. For eg.

@api.model
def default_get(self, fields):
rec = super(Your_Class_Name, self).default_get(fields)
context = dict(self._context or {})
active_model = context.get('active_model')
active_ids = context.get('active_ids', [])
形象
丢弃
最佳答案

Use 'default_get' method to assign a default image.
Check these links for reference.

(docs)

https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.default_get


(example)

https://github.com/odoo/odoo/blob/8.0/addons/account/account.py#L3085

形象
丢弃
最佳答案

Hi,
For Odoo 10.
from odoo.modules.module import get_module_resource

product_image = fields.Binary(

        string='Global Product Image',

        default=lambda s: s._default_product_image(),

        help='Use as the global image for all product default images. '

             'Limited to 1024x1024.',

    )


    @api.model

    def _default_product_image(self):

        image_path = get_module_resource(

            'module_name', 'static/src/img', 'glob_prod_img.png'

        )

        with open(image_path, 'rb') as handler:

            image_data = handler.read()

        return tools.image_resize_image_big(

            image_data.encode('base64')

        )

形象
丢弃
相关帖文 回复 查看 活动
1
3月 15
6747
3
2月 24
12553
2
8月 22
8819
2
4月 19
9561
0
3月 25
1149