Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

How to get the value(Char) of the first line in one2many field?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
13 Odpowiedzi
9701 Widoki
Awatar
Boby

I want to get the value(Char) of the first line in one2many field into my main form.

Any advice?


0
Awatar
Odrzuć
Awatar
Prakash
Najlepsza odpowiedź

You can access one2many fields values using one2many filed name and dot notation. 

Example, In sale order main

rec =[ line.comment for line self.order_line]

The above rec variable get all lines comment data list.

To get first line.

rec =[ line.comment for line self.order_line]

line1 = rec[0]

To get particular line based on condition

rec =[ line.comment for line self.order_line if comment != False]

The above rec return list of sale order line id, based on above condition.

Edit based on your object,

@api.depends('certificate_of_competency_ids')
def _get_licence(self):
    first_line = self.env['hr.certificate.competency'].search([('id', 'in',     self.certificate_of_competency_ids.ids)], order='sequence, id', limit=1)
    if first_line and first_line.certificate_name_competency:
    self.licence = first_line.certificate_name_competency.name

class certificate_competency(models.Model):
    _name = 'hr.certificate.competency'
    _description = 'Certificate Competency'
    _order = 'coc_emp_id, sequence, id'
2
Awatar
Odrzuć
Boby
Autor

how to make the condition when the data o2m field are empty? i dont know but i cant use this (if comment != False)

Boby
Autor

Hi, Praksesh

I've tried the code.. But there is an error:

first_line = self.certificate_of_competency_ids.filtered(lambda line: min(line.sequence))

TypeError: 'int' object is not iterable

Boby
Autor

Cool.. i can use that,

Thankyou very much Prakash.

Awatar
Ray Carnes (ray)
Najlepsza odpowiedź

You can do this directly within Odoo (without writing custom code) by making a related field.


Check out how we do this for the Next Activity Summary field on a Lead/Opportunity:






activity_ids is a one2many field.

2
Awatar
Odrzuć
Boby
Autor

can it show only one name of the first line in one2many field?

i mean, i make a field sequence widget="handle" so i can move it.. And if i move every data to the top of the line.. it show that data in my main form.

but i dont know if i make a related field i think all the data in o2m field will be showed and it will error?

Awatar
Odoo Mates
Najlepsza odpowiedź

Hi,

You can get the value of the first line like this,

self.field_name[0] this will return you the id of the first line and if you need to access a particular field from it, self.field_name[0].name .


Thanks

1
Awatar
Odrzuć
Boby
Autor

i tried the code.. but its error when there is no line in the o2m data.. how to make the condition when the data is empty?

Odoo Mates

self.field_name[0].name if self.field_name else ''

Boby
Autor

Thankyou Odoo Mates, it solve the empty data problem. But i have another problem, i add <field name="sequence" widget="handle"/> in my o2m field so i can drag and drop the lines. but not every data in the first line that showed up on my main form.

sometimes when i move another data to the first lines, data in the second lines showed up on my main form

Prakash

Using order line sequence field you find first order line. Order lines min(line.sequence) find and get value.

Boby
Autor

Hi Prakash.

I'm sorry but i don't understand what do you mean. Can you help me with it

Here is my code:

class employee(models.Model):

_inherit = 'hr.employee'

licence = fields.Char(string="Licence", compute="_get_licence")

certificate_of_competency_ids = fields.One2many('hr.certificate.competency', 'coc_emp_id', String="Certificate of Competency")

(Now i'm using below function)

@api.depends('certificate_of_competency_ids')

def _get_licence(self):

self.licence = self.certificate_of_competency_ids[0].certificate_name_competency.name if self.certificate_of_competency_ids else ''

class certificate_competency(models.Model):

_name = 'hr.certificate.competency'

_description = 'Certificate Competency'

coc_emp_id = fields.Many2one('hr.employee', string="Employee Name")

sequence = fields.Integer(string='Sequence', default=10)

certificate_name_competency = fields.Many2one('hr.certificate.competency.name', string="Certificate Name")

Prakash

updated the code, check it let me know if any issue.

Prakash

Updated answer, please check

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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