Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
9311 Prikazi
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
Opusti
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
Opusti
Best Answer

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

Hope it helps, Thanks

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
dec. 16
5373
2
maj 24
7876
1
jun. 15
4164
2
jun. 15
3725
3
maj 24
7975