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

Displaying data from another model in a form

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
2 Replies
6959 Rodiniai
Portretas
Linton Rooms

I dont know what is the most recommended way to display data from a model (A) in the form of a model (B) [Odoo 11].


So far I've used One2many relations, but in this case I cant (or I dont know how to do it).

I have three models:

class School(models.Model):
_name = 'abby.school'
...

class Agreement(models.Model):
_name = 'abby.agreement'
...
agreement_school = fields.Many2one(comodel_name='abby.school', string='School')
...

class Student(models.Model):
_name = 'abby.student'
...
school = fields.Many2one(comodel_name='abby.school', string='School')
...


Graphically: Agreement > School < Student


I want to display a list of Students in the Agreements form.

 
Could I use an One2many relation? Or a SELECT in any place? (I'm a beginner in Odoo)

Thank you in advance!!

0
Portretas
Atmesti
Linton Rooms
Autorius

--- I want to display all the students (could be one or eleven or zero) who belongs to a school with an agreement ---

Portretas
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

If each student will always have one agreement, then you can use One2many field

class Student(models.Model):
_name = 'abby.student'

agreement_id = fields.Many2one('abby.aggrement', 'Agreement')

class Agreement(models.Model):
_name = 'abby.agreement'

student_ids = fields.One2Many('abby.student', 'agreement_id', string="Students")
If the student can have multiple agreements, then you should use the Many2many field:

class Agreement(models.Model):
_name = 'abby.agreement'

student_ids = fields.Many2many('abby.student', string="Students")

Update:

Since you want to display all the students belonging to the school, you should use the auto-compute Many2many field:


class Agreement(...):

student_ids = fields.Many2many('abby.student', compute='_compute_students')

@api.depends('agreement_school')
def _compute_students(self):
        stud_obj = self.env['abby.student']
for agreement in self:
# Search students belongs to the school of the agreement
stud_ids = stud_obj.search([('school', '=', agreement.agreement_school.id)]).ids
agreement.student_ids = [(6, 0, stud_ids)]




1
Portretas
Atmesti
Linton Rooms
Autorius

Thanks for answering, Sudhir.

I think that solution does not work because there isnt direct relationship between Student and Agreemet. They both point to School:

Agreement > School < Student

Sudhir Arya (ERP Harbor Consulting Services)

Still, with the m2m field, you can select your students in the agreement. Do you want to auto-select all the students belongs to the school of the agreement?

Linton Rooms
Autorius

Thanks, Sudhir.

### Still, with the m2m field, you can select your students in the agreement.
### Do you want to auto-select all the students belongs to the school of the agreement?

Yes, I want to display (only display, not add or delete) the students who belong to a school with an agreement.

Using this:
student_ids = fields.Many2many('abby.student', string="Students") (In Agreement)

How can I specify the model School?

Thanks a lot

Sudhir Arya (ERP Harbor Consulting Services)

Please check my updated answer.

Linton Rooms
Autorius

Thank you a lot, Sudhir, for beeing so patient.
It's working... almost!
No errors, but list is empty.
So, I've write these "prints":
class Agreement(...):

student_ids = fields.Many2many(compute='_compute_students')

@api.depends('agreement_school')
def _compute_students(self):

stud_obj = self.env['abby.student']
print ("FooAAA ---")
for agreement in self:
print ("FooBBB agreement:")
print (agreement)
# Search students belongs to the school of the agreement
stud_ids = stud_obj.search([('school', '=', agreement.agreement_school.id)])
print ("FooCCC stud_ids")
print (stud_ids)
print ("FooEEE stud_ids[0]")
print (stud_ids[0])
agreement.student_ids = [(6, 0, stud_ids)]

When I go to an agreement, I get:
FooAAA ---
FooBBB agreement:
abby.agreement(10,)
FooCCC stud_ids
abby.student(1369, 905)
FooEEE stud_ids[0]
abby.student(1369,)

The list in trace "FooCCC" is OK. These are the correct ids to display... but they are not loaded in the list... any idea?

Thanks again!!

Sudhir Arya (ERP Harbor Consulting Services)

Please update bellow code:
agreement.student_ids = [(6, 0, stud_ids)]

Replace (stud_ids.ids):
agreement.student_ids = [(6, 0, stud_ids.ids)]

Linton Rooms
Autorius

Hi again, and thanks for keep helping!!

Adding "ids", I get this error:
psycopg2.ProgrammingError: relation "_unknown" does not exist
LINE 1: SELECT "_unknown"."id" as "id" FROM "_unknown" WHERE "_unkno...

Looking for that, I have found two posible causes/solutions. The first one recommends to restart both odoo and postgresql. I did it, but the error continues.
In the second comment, they talk about define relationships between models, but in my case, both models are defined in the same module.

Do you know what the problem could be?
Thanks in advance again!

Sudhir Arya (ERP Harbor Consulting Services)

Sorry, I missed to pass on the object name in the m2m field:

student_ids = fields.Many2many('abby.student', compute='_compute_students')

Linton Rooms
Autorius

It is working.
Sudhir, thank you very very much for your time and sharing your knowledge.

Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

To get the data from modelA to modelB we can use Many2one relation here.For example you need to get the list of students list in agreement form,

ie,

class Agreement(models.Model):
_name = 'abby.agreement'
student_list_id = fields.Many2one('abby.student', string="Student list")

Regards

0
Portretas
Atmesti
Linton Rooms
Autorius

Thanks for your answer.

But, if I use a Many2one, I will have a list for choose a student...

I want to display all the students (could be one or eleven or zero) who belongs to a school with an agreement.

Regards

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

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

Registracija
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