Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7879 Lượt xem

hi all,
i want to make one2many list contain another many2one field with domain in the same form 

the problem is "Uncaught Error: NameError: name 'model_id' is not defined"

and i noticed the the model_id stored in a record and the rest in other record 

i don't understand what is happening 

thanks 

 <form >
<br/>
<sheet>
<group col="4">
<field name="name" placeholder="Enter the report name..."/>
<field name="model_id"/>
</group>
<group>
<field name="record_ids">
<tree editable="bottom">
<field name="model_object_field"/>
<field name="user_field"/>
<field name="sequence"/>
<field name="operation"/>
</tree>
</field>
</group>
</sheet>
</form>
and .py
model_id = fields.Many2one('ir.model', 'Apply to',on_change="onchange_sub_model_object_value_field('model_id')",delegate=True)
model_object_field=fields.Many2one('ir.model.fields', string="choose Field",
domain="[('model_id','=',model_id),('ttype','!=','one2many'),('ttype','!=','many2many')]")
field_operation = fields.Selection([('plus', '+'), ('mi', '-'), ('div', '/'), ('mul', '*')],)
record_ids=fields.One2many('xsl.report.file', 'model_id')
user_field=fields.Char()
sequence=fields.Char()
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

thanks 
it worked for me after passing  context value 

<field name="cash_forecast_ids" context="{'current_id' : model_id}">
    <tree editable="bottom">
        <field name="name"/>
        <field name="user" />
        <field name="id" domain="[('id','=',parent.model_id)]" required="1" />
Ảnh đại diện
Huỷ bỏ

If you're satisfied with the answer. Please upvote it. You help others

Câu trả lời hay nhất

In the model declaration you used the domain ('model_id','=',model_id) for the field model_id.

However, domain works only in case, the used criteria is placed on a related xml view.

In your case, there should be 'model_id' inside a tree tag. You may make it invisible, but is should exists (model_id on a parent form surely is not taken into account). E.g.:

                  <tree editable="bottom">

                      <field name="model" invisible="1"/>

                     <field name="model_object_field"/>

                      <field name="user_field"/>

                      <field name="sequence"/>

                      <field name="operation"/>

                  </tree>

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
3373
1
thg 8 19
2486
1
thg 9 17
5436
1
thg 3 15
5198
0
thg 4 23
5306