Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

How to give Domain filter for one2many field base on the condition of another field? (Odoo 13)

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
many2oneone2manyonchangedomain_filter
2 Replies
12683 Rodiniai
Portretas
Leon

Hello,

Im trying to set Domain filter for one2many field of 'model_b.py' when showing base on the condition of another field of 'model_c.py' .

model_a.py :

name = fields.Many2one('hr.employee')

keya = fields.Many2one('model.b')

num_a = fields.Monetary()


model_b.py :

name = fields.Many2one('hr.employee')

o_2_m = fields.One2many('model.a', 'keya')
get_value_c = fields.Many2one('model.c', string='Get value of C', required= True)


model_c.py :

 _rec_name = "code_c"

code_c = fields.Char('Code', required= True)

num_c = fields.Monetary()


So, the condition is if field num_c is == num_a, then it will show all the related records which have num_a's values in o_2_m field by a popup when the user clicks on the "Add a line" link. If not, it will show nothing.


Im trying to create onchange function in model_b.py to execute like this:

@api.onchange('get_value_c')
def onchange_get_value_c(self):

    for rec in self:

        return {'domain': {'o_2_m': [('get_value_c','=', rec.get_value_c)]}}


But I don't know how to compare values of num_c and num_a for getting the results.


Please help!

Thank you!



0
Portretas
Atmesti
Leon
Autorius

Hi,

I'd tried with onchange in model_b.py like this:

@api.onchange('get_value_c')
 def onchange_get_value_c(self):
    for rec in self:
       if rec.get_value_c and rec.o_2_m:
          for line in rec.get_value_c:
             find_c = self.env["model.c"].search([('num_c', '=', line.num_c)])
             find_a = self.env["model.a"].search([('num_a', '=', line.num_a)])
             #compare value of num_c with num_a
             if find_c.num_c == find_a.num_a:
                 for abc in rec.o_2_m:
                    return {'domain': {'o_2_m': [('num_a','=', abc.find_a.id)]}}


But it still not works.

Begineer

Hi,

May i know how data is entered in one2many..??

Your onchange works only if you have data in get_value_c and o_2_m

Leon
Autorius

Hi Karthikeyan,

The data already have in model_a.py . So the one2many field of model_b.py connected with many2one field in model_a.py. Then, when click on the "Add a line" link of one2many field, it will show all the already records of model_a.py. without filtering.

This means that, first, the data must be fill in model_a.py.

After that, when the user wants to filter the records which have relate value of num_a for selecting. Then they must be fill value in num_c. Of course, the scenario related to field 'num_c' will be built properly.

If the user don't want to filtering, then they don't need to select in many2one 'get_value_c', then when click on "Add a line" link. It will show all the records without filtering.

Niyas Raphy (Walnut Software Solutions)

Domain Based on Another field: https://www.youtube.com/watch?v=IpXXYCsK2ow

Portretas
Leon
Autorius Best Answer

Finally, I'd solved my requirement.

Using onchange in model_b.py like this:

@api.onchange('get_value_c') 
def onchange_get_value_c(self):
    for rec in self:
        if rec.get_value_c:
            for line in rec.get_value_c:
                find_c = self.env["model.c"].search([('num_c', '=', line.num_c)])
                
                if find_c:
                     return {'domain': {'o_2_m': [('num_a','=', find_c.num_c)]}}

And it works fine after the user selecting many2one 'get_value_c' which have the value in field 'num_c', then when click on the "Add a line" link, it will show all records which have value in field 'num_a' equal to the value in field 'num_c'.

If the user selecting many2one 'get_value_c' but not set the value for field 'num_c' or the value is not equal to the value in field 'num_a'. Then when clicking on the "Add a line" link, it will show nothing with raise information. 

0
Portretas
Atmesti
Portretas
Begineer
Best Answer

Hi, 

    Here i think its not possible, why because,

1.You have a condition ( if field num_c is == num_a)  and based on this you need to given domain to your one2many
2.But the field num_a  itself is inside the one2many, without selecting num_a  you cannot apply your domain.
3.Try changing your logic

Thanks

0
Portretas
Atmesti
Leon
Autorius

Hi Karthikeyan, thank you for your support. Yes, I'd selected num_a for a domain. Please view my answer in above.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
How do I put One2many after Many2one defined? - transient module states reset
many2one one2many
Portretas
1
kov. 23
3203
Odoo Studio how to set a chain of multiple and related Many2one within a One2many lines
many2one one2many
Portretas
0
gruod. 22
3804
odoo onchange function on one2many field Solved
function fields many2one one2many onchange
Portretas
Portretas
Portretas
Portretas
3
spal. 22
22271
filter according to comodel's fields
many2one one2many
Portretas
0
birž. 21
3509
How to update two levels o2m fileds relation
one2many onchange
Portretas
0
rugs. 20
3720
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now