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 keep multiple Many2many fields on the same model

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
modelsmany2manymultiple_values
4 Odpowiedzi
21725 Widoki
Awatar
arthur

Hello, I am trying to create a model that have multiple Many2many fields that relates to the "product.product" model. Basically, the model will have four list, each one containing different products.

My model is the following:

class SubscriptionBasket(models.Model):
    _name="subscription.basket"
    name = fields.Char("Nome", required=True)
    legumes = fields.Many2many(
        'product.product',
        string='Legumes',
    )
    frutas = fields.Many2many(
        'product.product',
        string='Frutas',
    )
    verduras = fields.Many2many(
        'product.product',
        string='Verduras',
    )
    temperos = fields.Many2many(
        'product.product',
        string='Temperos',
    )


The problem however is that when I choose a product to one of the fields and then save, all fields get this product as well.

As an example, I overwrote the create function to get logs:

@api.model
def create(self, vals):
    _logger.info("Vals received on creation: %s", vals)
    res = super(SubscriptionBasket, self).create(vals)
    _logger.info("Field temperos on creation response: %s", res.temperos)
    return res


Then, when creating a record, informing a product just to the fields "legumes", I get the following log for the vals I received:

    Vals received on creation: {'name': 'Cesta', 'temperos': [[6, False, []]], 'frutas': [[6, False, []]], 'date_start': '2019-02-05',     'verduras': [[6, False, []]], 'legumes': [[6, False, [6952]]], 'date_end': '2019-02-08'}

And the following log for the field "temperos", which I would expect to be empty, on the creation response:

    Field temperos on creation response: product.product(6952,)

What am I missing here?

2
Awatar
Odrzuć
Sehrish

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

Awatar
Jignesh Mehta
Najlepsza odpowiedź

Hello Arthur,

Try to define like below:

class SubscriptionBasket(models.Model):
    _name="subscription.basket"

    name = fields.Char("Nome", required=True)
    legumes = fields.Many2many('product.product', 'product_legumes', 'product_id', 'legumes_id', string='Legumes')
    frutas = fields.Many2many('product.product', 'product_frutas', 'product_id', 'frutas_id', string='Frutas')
    verduras = fields.Many2many('product.product', 'product_verduras', 'product_id', 'verduras_id', string='Verduras')
    temperos = fields.Many2many('product.product', 'product_temperos', 'product_id', 'temperos_id',string='Temperos')


Hope it will works for you.

Thanks,

10
Awatar
Odrzuć
arthur
Autor

Thank you! 'product_legumes', 'product_id', 'legumes_id' are the name for relation, column1 and column2, respectively, right? How do I know these names?

Awatar
Muhammad Awais
Najlepsza odpowiedź

You can look in the Base Model as well.

the description


class Many2many(_RelationalMulti):
""" Many2many field; the value of such a field is the recordset.


:param comodel_name: name of the target model (string)

The attribute ``comodel_name`` is mandatory except in the case of related
fields or field extensions.


The attribute ``comodel_name`` is mandatory except in the case of related
fields or field extensions.
:param relation: optional name of the table that stores the relation in
the database (string)


the database (string)
:param column1: optional name of the column referring to "these" records
in the table ``relation`` (string)


in the table ``relation`` (string)
:param column2: optional name of the column referring to "those" records
in the table ``relation`` (string)

The attributes ``relation``, ``column1`` and ``column2`` are optional. If not
given, names are automatically generated from model names, provided
``model_name`` and ``comodel_name`` are different!


in the table ``relation`` (string)
The attributes ``relation``, ``column1`` and ``column2`` are optional. If not
given, names are automatically generated from model names, provided
``model_name`` and ``comodel_name`` are different!
:param domain: an optional domain to set on candidate values on the
client side (domain or string)


client side (domain or string)
:param context: an optional context to use on the client side when
handling that field (dictionary)


handling that field (dictionary)
:param limit: optional limit to use upon read (integer)


0
Awatar
Odrzuć
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ść
How can we access child model filed in parents model
models many2many v15 childclass
Awatar
1
lip 22
2741
I can't save the field relation to my new model Rozwiązane
modules models many2many odoo8
Awatar
Awatar
Awatar
3
lut 17
4492
How to get the tax_id from a sale order? (Customize Quotation template) Rozwiązane
models quotation many2many model
Awatar
Awatar
1
mar 15
6870
How can I use two models in an API (foreign key - relations)?
models
Awatar
0
gru 24
2148
Import Data From Another Model Rozwiązane
models
Awatar
Awatar
1
mar 24
3264
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