在点击之前是什么使得改变功能?

时间:2015-07-21 11:45:04

标签: odoo-8

请使用on_change和get_inputs。

这是我的代码:

PYTHON:

 def get_inputs(self, cr, uid,ids, convention_id, company_id, context=None):
 ret = []
 if convention_id == False:
 My_error_Msg = 'Please, select your CONVENTION'
 raise osv.except_osv(_("Error!"), _(My_error_Msg))
 return False
 else:
    obj = self.pool.get('seetek.convention.categorie.line')
    obj_ids = obj.search(cr, uid, [('convention_id', '=', convention_id)])
    res = obj.read(cr, uid, obj_ids, ['nom','nature','id'], context)
    for r in res :
        inputs = {  
                  'company_convention_categorie_id': r['id'],
                  'company_id': company_id,
                  'nom': r['nom'],
                  'nature': r['nature'],
                  'actif': True,
                   }
      ret.append(inputs)
 return ret
 def on_change_convention_id(self, cr, uid, ids, convention_id, company_id, context=None):
 res = {'value':{line_ids': self.get_inputs(cr, uid, ids, convention_id, company_id, context=context),
 }
 }
 return res

XML:

  <field name="convention_ids" on_change="on_change_convention_id(convention_ids,company_ids)" attrs="{'invisible': [('company_ids','=',False)]}"/>

我的问题是,在我点击convention_ids字段之前,get_inputs函数并给我所有值?

拜托,谁可以帮忙?!

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。 事实上,get_inputs函数是完美的,没有问题。 导致问题的问题出在on_change上。 我把它改成了下面的代码,它运作得很好:

  def on_change_conventions_id(self, cr, uid, ids, convention_id, company_id, context=None):
    if company_id == False:
    My_error_Msg =  'Please, select your COMPANY'
    raise osv.except_osv(_("Error!"), _(My_error_Msg))
else:
    print company_id
    print convention_id
        res = {'value':{'seetek_line_ids': self.get_inputs(cr, uid, ids, convention_id, company_id, context=context),
                  }
            }
        return res

非常感谢&amp;问候:)