问题
"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