Odoo Help

0

1
3 Answers
1
Avatar

Pawan Kumar Sharma

--Pawan Kumar Sharma--
SunArc Technologies
8478
| 6 2 7
Bikaner, India
--Pawan Kumar Sharma--


Pawan Kumar Sharma
6/15/18, 1:07 AM

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', [])
1
Taher Giyori
7/18/16, 9:16 AM

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

0
Ubaid ur Rehman
6/12/18, 6:05 AM

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')

        )

Ask a Question
Writer
Tags
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now