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 pass records from list to many2many field?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
listmany2manypython3arrayodoo12.0
12 Odpowiedzi
20049 Widoki
Awatar
Mohamed Fouad (personal)


 need to get the range between 2 years on a many2many field each year must be a record on the model

i added 2 fields to get the 2 years and and method to get the range between them

class yearrange(models.Model):
_name = 'yearrange'
_rec_name = 'name'

name = fields.Char()

 class autopart(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('start', 'end')
def years(self):
    record = [int(x) for x in range(int(self.start), int(self.end))]
    for rec in self:
        rec.rang=record

start = fields.Char(string="", required=False, )
end = fields.Char(string="", required=False, )
rang = fields.Many2many(comodel_name="yearrange", string="",compute=years )

i get records at the many2many field but all of them are = False 

0
Awatar
Odrzuć
Sehrish

In this article I will show you how to create a many2many field in odoo. I will also show you guys how to filter many2many field using domain. You can also learn how to set default value on many2many field.

Reference: https://learnopenerp.blogspot.com/2018/12/add-domain-on-many2many-field-in-odoo.html

Mohamed Fouad (personal)
Autor

i solve it by this code

class yearrange(models.Model):

_name = 'yearrange'

_rec_name = 'name'

name = fields.Char()

product_id = fields.Many2one(comodel_name="product.template")

@api.multi

@api.onchange('start', 'end')

def years(self):

print('innnnn')

for rec in self:

if rec.start and rec.end:

record = [int(x) for x in range(int(rec.start), int(rec.end) + 1)]

list = []

for item in record:

print(item)

range_id = self.env['yearrange'].create({

'name': str(item)

})

list.append(range_id.id)

rec.rang = [(4, x, None) for x in list]

start = fields.Char(string="", required=False, )

end = fields.Char(string="", required=False, )

rang = fields.One2many(comodel_name="yearrange", inverse_name="product_id", store=True, string="range")

Awatar
Mohamed Fouad (personal)
Autor Najlepsza odpowiedź


i solve it by this code

class yearrange(models.Model):
_name = 'yearrange'
_rec_name = 'name'

name = fields.Char()
product_id = fields.Many2one(comodel_name="product.template")


class autopart(models.Model):
_inherit = 'product.template'

@api.multi
@api.onchange('start', 'end')
def years(self):
print('innnnn')
for rec in self:
if rec.start and rec.end:
record = [int(x) for x in range(int(rec.start)+1, int(rec.end)+1)]
list = []
for item in record:
print(item)
range_id = self.env['yearrange'].create({
'name': str(item)
})
list.append(range_id.id)
rec.rang = [(4, x, None) for x in list]

start = fields.Char(string="", required=False, )
end = fields.Char(string="", required=False, )
rang = fields.One2many(comodel_name="yearrange", inverse_name="product_id", store=True)



1
Awatar
Odrzuć
Awatar
Mital Vaghani
Najlepsza odpowiedź

Hello,

​rang is a Many2many field with model yearrange and it's functional field, so in computed method of that field you need to give ids  of yearrange model and you are assigning direct years.
So you can write as following :

@api.multi
@api.depends('start', 'end')
def years(self):
    record = [str(x) for x in range(int(self.start), int(self.end))]
    for rec in self:
        yearranges = self.env['yearrange'].search([('name','in',record)])
        rec.rang=yearranges

0
Awatar
Odrzuć
Mohamed Fouad (personal)
Autor

Thanks dear for your help i appreciate that too much but it's still not working for me

the field range doesn't updated and i added print (rec.rang) its print yearrange()

not any record

Awatar
Manish Bohra
Najlepsza odpowiedź


Hello,
In your case your  Many2many field range are used as functional filed(Compute field) So in this case you want to update your id in respective field.

So you following changes in your code maybe it's works for you

@api.multi
@api.depends('start', 'end')
def years(self):
    record = [str(x) for x in range(int(self.start), int(self.end))]
    for rec in self:
        yearranges = self.env['yearrange'].search([('name','in',record)]).ids
        OR
      yearranges = self.env['yearrange].search([('name','in',record)])
     rec.rang=yearranges
​
Thanks 

0
Awatar
Odrzuć
Mohamed Fouad (personal)
Autor

Thanks dear for your help i appreciate that too much but it's still not working for me

the field range doesn't updated and i added print (rec.rang) its print yearrange()

not any record

Manish Bohra

can you share the value of record?

Mohamed Fouad (personal)
Autor

first solution rec and yearranges isn't used

if i added rec to rec.yearranges and print it display empty list []

second solution i get error

File "/odoo/odoo-server/odoo/osv/expression.py", line 318, in distribute_not

elif token in DOMAIN_OPERATORS_NEGATION:

TypeError: unhashable type: 'list'

Manish Bohra

ok, but what is the output of the record variable?

Mohamed Fouad (personal)
Autor

it print list of range like >>>>>> ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019']

Manish Bohra

What is value in name ..? Similar like year ..?

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ę
Powiązane posty Odpowiedzi Widoki Czynność
[Odoo12] Check current model in python Rozwiązane
python3 odoo12.0
Awatar
Awatar
Awatar
2
lut 20
13344
How to replace previous references in One2Many Field
python3 odoo12.0
Awatar
Awatar
1
lip 19
5312
TypeError: unhashable type: 'list'
list many2many
Awatar
Awatar
Awatar
Awatar
4
mar 15
34116
Can't add items to Many2many in Odoo 12 EE
enterprise many2many odoo12.0
Awatar
Awatar
Awatar
Awatar
4
lut 19
8376
unhashable type: 'list' -many2many
list many2many unhashable
Awatar
1
gru 17
7030
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