“account_invoice.py的python代码,我想知道如何在OpenERP中初始化默认的one2many字段”
class account_invoice(osv.osv):
def _tax_line_default(self, cr ,uid, context=None):
obj= self.pool.get('account.invoice.tax')
ids= obj.search(self, cr, uid)
obj.write(cr, uid, ids[0], {'name' : 'droit de timbre','amount':0.400})
res =obj.browse(cr, uid, ids[0])
return res.name_get(cr, uid, ids[0], context)
_ columns = {
'tax_line': fields.one2many('account.invoice.tax', 'invoice_id', 'Tax Lines', readonly=True, states={'draft':[('readonly',False)]})
}
_defaults = {
'tax_line':_tax_line_default,
}
http://nsa33.casimages.com/img/2013/05/17/130517043059690422.png
http://nsa33.casimages.com/img/2013/05/17/130517053356530066.png
答案 0 :(得分:0)
您需要从函数中返回ID列表,例如return [res.id]
您必须从搜索方法中删除self
。这就是你错误的原因。
ids = obj.search(cr, uid, [])
根据您的代码,这是我的建议。