How to set default values with methods in Odoo?

后端 未结 2 851
时光说笑
时光说笑 2020-12-30 09:03

How to compute the value for default value in object fields in Odoo 8 models.py

We can\'t use the _default attribute anymore in Odoo 8.

相关标签:
2条回答
  • 2020-12-30 09:50

    A simpler version for the @ChesuCR answer:

    def _get_default_name(self):
        return "test"
    
    name = fields.Char(
        string='Name',
        default=_get_default_name,
    )
    
    0 讨论(0)
  • 2020-12-30 10:00

    You can use a lambda function like this:

    name = fields.Char(
        string='Name',
        default=lambda self: self._get_default_name(),
    )
    
    @api.model
    def _get_default_name(self):
        return "test"
    
    0 讨论(0)
提交回复
热议问题