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 set this specific domain in XML?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
domainxmlmany2oneodoo8.0
3 Replies
39852 Rodiniai
Portretas
Juan Formoso Vasco

I have the next table in Odoo, named relationship, which comes from the relation between the table girl and the table boy:

girl_id
boy_id
relationship_type
1
2
friends
1
3
siblings
2
7
lovers

So:

  • In the table girl there's a field relationships which is a one2many pointing to the table relationship.

  • In the table boy there's a field relationships which is a one2many pointing to the table relationship.

  • In the table relationship there are two fields, girl_id and boy_id, both pointing to the tables girl and boy respectively.

Scenario:

In the forms of girl and boy there's the field relationships. When I add a new relationship for a girl or a boy, a form is opened to fill in the fields of the table relationship (girl_id, boy_id and relationship_type). Imagine I'm in the form of a girl, I click on add a new relationship and the form is opened. I implemented this in order not to see the girl_id (it's invisible but it contains the ID of the current girl). So I can see only two fields (boy_id and relationship_type).

What I want:

Keeping on with the example, if I open the dropdown of boy_id, I'll see all boys, even the ones who are already related to this girl, and that's what I don't want. For example, if I'm adding a relationship to the girl with id 1, I must not see boys with ids 2 and 3, if the girl is the one with id 2, I must not see the boy with id 7.

My code:

<field name="girl_id" invisible="1"/>
<field name="boy_id" domain="[('id', 'not in', girl_id.relationships.boy_id)]"/> <!-- Obviously this does not work -->
<field name="relationship_type"/>

Can anyone help me, please? Thank you!

4
Portretas
Atmesti
Temur

1) wrong domain, it should not work... 2) why do not use many2many relations between girl and boy? many2many relation seems more convenient to use in your scenario and all this packet of technical problems will disappear with it

Juan Formoso Vasco
Autorius

Because it's my understanding that it's not possible to store more fields than the IDs in a many2many relationship, is it?

Portretas
Temur
Best Answer

you can use relation many2many...

use in girl's model:

relationships = fields.Many2many(comodel_name="boy.model.name", relation='relation_table_name', column1='boy_id', column2='girl_id', string="relationships of this girl")


use in boy's model:

relationships = fields.Many2many(comodel_name="girl.model.name", relation='relation_table_name', column1='girl_id', column2='boy_id', string="relationships of this boy")


note that in both cases relation table is the same ( relation='relation_table_name' )

but column1 and column2 are inversed (in case of girl column1='boy_id' and column2='girl_id' but in case of boy column1='girl_id' and column2='boy_id'


UPDATE:

 apart of this two models, you can add new model and force it to have same table name as the relation table (using _table field):

_table = "relation_table_name"

and add the two fields representing ids:

boy_id = fields.Many2one(comodel_name="boy.model.name", string="Boy's ID")

girl_id = fields.Many2one(comodel_name="girl.model.name", string="Girl's ID")

also additional fields you like, as:

relationship_type = fields.Selection(....         (or fields.Char(... or something else...)

... 

you can find useful the last model.


OR


you can try to correct your domain as follows:

<field name="boy_id" domain="[('id', 'not in', the_computed_one2many_field )]"/>

add "the_computed_one2many_field" computed field and add it as invisible to the view.

the 'compute' function of "the_computed_one2many_field" must return list of ids...


probably the_computed_one2many_field may be also related field to girl_id.relationships.boy_id (not computed one)

0
Portretas
Atmesti
Juan Formoso Vasco
Autorius

Thank you for your help @Temur, but I think that way a boy will have the same relationship with every girl and the other way around. Let's imagine that I create the relationship_type on the table boy: when I create a boy, I will have to set the relationship type of that boy? And that boy will always have that relationship type!

Temur

yes, I see. I updated the answer. it's more complicated then I thought.

Juan Formoso Vasco
Autorius

Thank you @Temur, I thought the last suggestion (after the OR) was the best and would work, but I get the RuntimeError: maximum recursion depth exceeded while calling a Python object, because there's a model with a one2many pointing to other model which also has a one2many pointing to the first one.

Temur

you tried to add computed field or related field?

Temur

lets say we're adding the computed field to girls model, then

@api.depends('girl_id')
def _compute_boys(self):
   #... implement the function

girls_relations = fields.One2many(comodel_name="boys.model.name", compute='_compute_boys')
for @api.depends I just guess, adapt it to your model. then use in xml:
<field name="boy_id" domain="[('id', 'not in', girls_relations )]"/>
and you'll need same for boy's relations...
Temur

probably @api.depends('relationships') and not girl_id ? I don't know your model structure

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
[SOLVED] Is posible change a domain_force in security.xml through a function in Python? (odoo 8) Solved
security domain xml odoo8.0
Portretas
Portretas
2
kov. 15
10914
Domain with inherited field Solved
domain many2one
Portretas
1
spal. 22
4517
How to get the current user in XML
domain xml
Portretas
Portretas
Portretas
2
lapkr. 25
9967
Many2one field: 'id' instead of 'name' Solved
many2one odoo8.0
Portretas
Portretas
1
vas. 21
5599
Showing many2one fields in other modules Solved
xml many2one
Portretas
Portretas
Portretas
2
vas. 18
13067
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