Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
9291 Представления
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?


Аватар
Отменить
Лучший ответ


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,


Аватар
Отменить
Лучший ответ

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

Hope it helps, Thanks

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
дек. 16
5362
2
мая 24
7868
1
июн. 15
4149
2
июн. 15
3710
3
мая 24
7945