如何在自定义模块openerp中使用_defaults函数

时间:2016-02-01 07:06:07

标签: python openerp odoo-8

我编写自定义模块,但我的_defaults函数有问题。

当我安装模块时,它会抛出错误

  

缩进错误:“_defaults = {”。

的意外缩进
medical_diagnostic_hypothesis.py

from openerp.osv import fields, orm


class MedicalDiagnostic_hypothesis(orm.Model):
    _name = 'medical.diagnostic_hypothesis'
    #_inherit = ['mail.thread', 'ir.needaction_mixin']

    _columns = {
        'name': fields.char(size=256, string='Diagnostic ID', required=True),
        'partner_id': fields.many2one('res.partner', 'Partner',
                                        required=True ),
        'pathology_category_id': fields.many2one('medical.pathology.category',
                                         'Pathology',required=True ),
        'diagnostic': fields.char(size=256, string='Diagnostic'),
        'treatment_method': fields.char(size=256, string='Treatment Method'),
    }
    _defaults = {
                 }

Server trace-back image

1 个答案:

答案 0 :(得分:0)

尝试使用此代码。 (做一个适当的缩进)

medical_diagnostic_hypothesis.py

from openerp.osv import fields, orm

class MedicalDiagnostic_hypothesis(orm.Model):
    _name = 'medical.diagnostic_hypothesis'
    #_inherit = ['mail.thread', 'ir.needaction_mixin']

    _columns = {
        'name': fields.char(size=256, string='Diagnostic ID', required=True),
        'partner_id': fields.many2one('res.partner', 'Partner',
                                        required=True ),
        'pathology_category_id': fields.many2one('medical.pathology.category',
                                         'Pathology',required=True ),
        'diagnostic': fields.char(size=256, string='Diagnostic'),
        'treatment_method': fields.char(size=256, string='Treatment Method'),
    }

    _defaults = {
    }

有关indentation in python.

的更多信息