This question has been flagged
2 Replies
6698 Views

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()
Avatar
Discard
Author Best Answer

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" />
Avatar
Discard

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

Best Answer

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>

Avatar
Discard