Skip to Content
Menu
This question has been flagged
2 Replies
8245 Views
class a(models.Mocel):
    _name='a'
    master = field.Char()
    slave = field.One2many('b','a_id')

class b(models.Model):
    _name='b'
    a_id=field.Many2one('a')
    c_id=field.Many2one('c')

class c(models.Model):
    _name='c'
    code=field.Char()

and the view for model "a"

<field name="master"/>
<field name="slave">
    <tree editable="bottom">
        <field name="c_id"/>
    </tree>
</field>

I need to filter "c" so that a.master=c.code so I tryed:

@api.onchange('master')
def onchange_master(self):
    return {'domain': {'slave.c_id': [('code','=',self.master)]}}

and

@api.onchange('master')
def onchange_master(self):
    return {'domain': {'slave': [('code','=',self.master)]}}

and

@api.onchange('master')
def onchange_master(self):
    return {'domain': {'c_id': [('code','=',self.master)]}}

but it just doesn't set the domain for c_id field. Is there any way to achieve this, or it is just not possible?


Avatar
Discard
Best Answer


Dear  Praful chavdam

We can achive your requirment,
just try the bellow codes.

 .py

# -*- encoding: utf-8 -*-
from odoo import api, fields, models, _

class A(models.Model):     
_name = 'a'

    name = fields.Char()
    slave = fields.One2many('b', 'a_id')


class B(models.Model):     
_name = 'b'
_rec_name = 'a_id' 
a_id = fields.Many2one('a')
a_rel = fields.Char(related='a_id.name', readonly=1)
c_id = fields.Many2one('c') 
@api.onchange('a_rel')  def onchange_master(self): return {'domain': {'c_id': [('name', '=', self.a_rel)]}}
class C(models.Model):
    _name = 'c' 
name = fields.Char()​
.XML
        
 <group>

        field name="name"/>
field name="slave">
<tree editable="bottom">
<field name="c_id"/>
<field name="a_rel"/>
<field name="a_id"/>
</tree>
</field>
</group>   
Regards,

Nikhilkrishnan,


Avatar
Discard
Best Answer

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

Avatar
Discard
Related Posts Replies Views Activity
0
Dec 16
4736
2
May 24
7069
1
Jun 15
3582
2
Jun 15
2965
3
May 24
7095