콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
27949 화면

class name(osv.osv):
        _name='name.model'
        _columns={'name':fields.char('Name',size=32),
                  'so':fields.integer('So luong'),
                  'cost':fields.integer('Cost'),
                  }
name()

class second_model(osv.osv_memory):
        _name='second.model'
        _columns={
                  'name1':fields.many2one('name.model','Name1'),
                  'name2':fields.many2one('name.model','Name2'),
                  'select_cost':fields.integer('Select Cost')         
                  }
        def onchange_cost(self,cr,uid,ids,name1,context=None):
            value={}
            if name1:
                record_id=self.pool.get('name.model').search(cr,uid,[('name','=',name1)],context=context)
                record=self.pool.get('name.model').browse(cr,uid,record_id[0],context=context)
                value['select_cost']=record.cost
            else:
                value['select_cost']=0    
            return {'value':value}
second_model()

<record id="model2_form" model="ir.ui.view">
        <field name="name">teb</field>
        <field name="model">second.model</field> 
        <field name="type">form</field>
        <field name="arch" type="xml">
                <form>
                    <group col="2">
                         <field name="name1" on_change="onchange_cost(name1)"/>
                        <field name="name2"/>
                        <field name="select_cost"/>
                    </group>
                </form> 
         </field>
    </record>

When name1 is selected , this error appear 

File "C:\openerp-8.0rc1\openerp\addons\Baitap05\core.py", line 30, in onchange_cost record=self.pool.get('name.model').browse(cr,uid,record_id[0],context=context) IndexError: list index out of range

 I'm new in odoo ,please help me .Thanks

아바타
취소
베스트 답변

The search you do on name.model is coming up with no results. You should check if record_id contains any records before perfoming a browse on it.

아바타
취소
작성자

Thanks for replay .I added some code : if record_id: record=self.pool.get('tt_kho').browse(cr,uid,record_id[0],context=context) value['ten']=record.ten else: value['ten']='haha' It looks like it can't get record_id and value['ten'] always = 'haha' ,please help me solve this .Thanks

베스트 답변

i had the same error in a report i was creating and i fixed it by adding 

<t t-call="web.html_container">  before this 

 <t t-call="web.internal_layout">

don't forget to add the </t> among the last </t> s.

아바타
취소
베스트 답변

Hi this is Gulshan Negi

Well, Accessing an index that is too high: This can happen if you have a list of length n and you try to access the element at index n or higher. To fix this, ensure that the index you are trying to access is within the range of the list (ie, between 0 and n-1).

Hope it can help you.

Thanks

아바타
취소