how to initialize a default one2many fields in OpenERP

六眼飞鱼酱① 提交于 2019-12-08 08:26:22

问题


"python code for account_invoice.py and i want to know how to initialize a default one2many fields in OpenERP "

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

回答1:


You need to return list of IDs from your function like this return [res.id]

You have to remove self from search method. That is the reason of your error.

ids = obj.search(cr, uid, [])

This is my suggestion as per your code.



来源:https://stackoverflow.com/questions/16622376/how-to-initialize-a-default-one2many-fields-in-openerp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!