Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing-
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

how to create a foreign key and update the column once saved

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
many2onerelationshipproduct.product
2 Antworten
3863 Ansichten
Avatar
random_mai

I have this scenario: I have a new field in product.product and it's a Many2one field. The many2one field has a product_id column. Here's the sample code:


class MyMany2one():

​_name = "my.manytoone"


​name = fields.Char()

​product_id = fields.Many2one(

​ ​comodel_name = "product.product"

​)



class ProductProduct():

​_inherit = "product.product"


​# in the product view, this will be a selection

​mymany2one = fields.Many2one(

​ ​comodel_name = "my.manytoone"

​)


My issue is it does not populate the product_id in the many2one class after saving

0
Avatar
Verwerfen
Avatar
shubham shiroya
Beste Antwort

you can try this way:

class MyMany2one(models.Model):
_name = "my.manytoone"
name = fields.Char()
product_id = fields.Many2one(
comodel_name="product.product",
inverse_name="mymany2one",
)


class ProductProduct(models.Model):
_inherit = "product.product"

# In the product view, this will be a selection
mymany2one = fields.Many2one(
comodel_name="my.manytoone",
inverse_name="product_id",
)

By adding the inverse_name parameter to the product_id field in the my.manytoone class and the mymany2one field in the product.product class, you establish a two-way relationship between the two fields. This ensures that the product_id field in the my.manytoone class gets populated when a value is selected in the mymany2one field of product.product.

After making these modifications, update the module containing this code and restart the Odoo server. Then, when you create or edit a product.product record, select a value in the mymany2one field, and the corresponding product_id field in the my.manytoone class should populate correctly.

0
Avatar
Verwerfen
Avatar
Niyas Raphy (Walnut Software Solutions)
Beste Antwort

Hi,

Am not sure about your design, if you need  product_id as Many2one inside your model, you have to write code for updating the product_id field inside your custom model.

Inherit the write method of product.product model, and if the mymany2one field has a value, update the product id into it.

But what if the same record is selected inside multiple products ?

Lets say, you have a record My Record 1 in your table and 2 products in products table P1 and P2, which value you will store inside the My Record 1 if for both P1 and P2, if user choose My Record 1 ?


If its possible to change it one2many field inside your model, you can achieve this without any extra coding. Remove many2one from your model and define a one2many field as follows:


product_ids = fields.One2many('product.product', 'mymany2one', string="Test")

Thanks

0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
Display another field in many2one instead of name Gelöst
many2one relationship search
Avatar
Avatar
Avatar
3
Feb. 25
37194
Show related objects of the same model. Gelöst
many2one one2many relationship
Avatar
Avatar
2
Aug. 15
5884
Can i eliminate the option to create and edit?
many2one creation relationship
Avatar
Avatar
Avatar
2
März 15
5023
Change display field in popup from related Module
many2one relationship popup Studio
Avatar
Avatar
1
Juli 23
3197
how to delete one2many if many2one is deleted Gelöst
many2one one2many relationship unlink
Avatar
Avatar
1
Mai 23
3739
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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