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

Custom code: Key columns are of incompatible types: character varying and integer

Abonnieren

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

Diese Frage wurde gekennzeichnet
typeforeignkeymismatch
2 Antworten
2540 Ansichten
Avatar
Nicolás

Hi everyone!

I have this error:


psycopg2.errors.DatatypeMismatch: foreign key constraint "project_project_laboratorio_fkey" cannot be implemented
DETAIL:  Key columns "laboratorio" and "id" are of incompatible types: character varying and integer.


I have created a model "areas" (Table in database) to use it in a many2one field in a "project.project" inherited custom module I made. I loaded registers in my "areas" module in the python file.


  @api.model

  def init(self):

        default_data = [

            {'area_ejecutante': 'lie', 'laboratorio': 'lide'},

            {'area_ejecutante': 'ima', 'laboratorio': 'pintura'},

            {'area_ejecutante': 'lie', 'laboratorio': 'laie'},

            {'area_ejecutante': 'ima', 'laboratorio': 'mecanica'},

        ]

        for data in default_data:

        # Ensure no duplicates

            if not self.search([('area_ejecutante', '=', data['area_ejecutante']),

                                ('laboratorio', '=', data['laboratorio'])]):

                self.create(data)



Now I commented all the code and unlinked the "areas" model in the __init__.py . 

And I have this error.


Any idea how can I fix it?

Thanks in advance, Nicolás

0
Avatar
Verwerfen
Dương Nguyễn

Many2one use _rec_name property and you need to have _compute_display_name method
P/s: can you mark my answer as best one please, thank in advance

Avatar
Dương Nguyễn
Beste Antwort

No one create model record in the init method, i think you should use data.xml file or use post_init_hook please

0
Avatar
Verwerfen
Avatar
Nicolás
Autor Beste Antwort

Hi Dương!

Thanks for your answer.


I think what you mentioned could be the problem. Do you have any doc or vid on how to create model records using data.xml?


I have reset the code to my last working commit but I still have this issue because the foreign key remains created. I'll proceed by deleting the foreign key directly through the database,

0
Avatar
Verwerfen
Dương Nguyễn

How do you define your model and have you try new database ?

Nicolás
Autor

Hi Dương,
I defined my module like this:

from odoo import api, models, fields

class AreasEjecutantesModel(models.Model):
_name = 'areas.ejecutantes.model'
_description = 'Modelo para gestionar las áreas ejecutantes y sus laboratorios'

# area_ejecutante1 = fields.Char(string='Area ejecutante1')
area_ejecutante1 = fields.Selection([
('lab1', 'lab_name'),
('lab2', 'lab_name'),
('lab3', 'lab_name'),
('lab4', 'lab_name')
], string="Area Ejecutante", default='lab1')
# laboratorio1 = fields.Char(string='Laboratorio1')
laboratorio1 = fields.Selection([
('sublab1','sublabname'),
('sublab2','sublabname'),
('sublab3','sublabname'),
('sublab4', 'sublabname'),
], string="Laboratorios", default='sublab1')

@api.model
def init(self):
default_data = [
{'area_ejecutante1': 'lab1', 'laboratorio1': 'sublab3'},
{'area_ejecutante1': 'lab2', 'laboratorio1': 'sublab1'},
{'area_ejecutante1': 'lab1', 'laboratorio1': 'sublab4'},
{'area_ejecutante1': 'lab2', 'laboratorio1': 'sublab2'},
]
for data in default_data:
# Ensure no duplicates
if not self.search([('area_ejecutante1', '=', data['area_ejecutante1']),
('laboratorio1', '=', data['laboratorio1'])]):
self.create(data)

By running this code the new table in the pgdb is created and the records are loaded in it.
I visualize the pgdb in pgAdmin

Dương Nguyễn

So your project.project model have m2o of your custom model right, in the __init__.py file you should your custom model first

Nicolás
Autor

Exactly Dương, the project.project model have m2o of my custom model.

I did what you mentioned on the init.py and it solved the problem!! I now can visualize the model in the m2o field!

I have a question. If I want to make it dependent on the value selected in a Selection field, should I use the @api.onchange decorator and change the domain? Or is there another way to achieve this?

This is what I did, but it doesn't work.

@api.onchange('area_ejecutante')
def _onchange_area_ejecutante(self):
if self.area_ejecutante == 'lie':
return {'domain': {'laboratorio1': [('area_ejecutante1', '=', 'lie')]}}
elif self.area_ejecutante == 'ima':
return {'domain': {'laboratorio1': [('area_ejecutante1', '=', 'ima')]}}
else:
return {'domain': {'laboratorio1': []}}

Thank you!

Dương Nguyễn

You can use a compute field instead

Nicolás
Autor

Hi Dương,
do you mean on the many2one field?
By trying to do so (adding the compute="myonchangefunction" on the m2o field) my module fails.

I would need that the options of the m2o field vary depending on the value of a Selection field.

e.g, in the selection field i would choose the laboratory, and m2o field should show the sublabs of the lab selected. Not all the sublabs of all the labs.

Thank you!

Dương Nguyễn

which odoo version?
You onchange function should assign field like this
if self.area_ejecutante1 == '':
self.field = ""

Nicolás
Autor

Hi Dương,
I solved it by following Long's answer in this issue that you were also involved in: https://www.odoo.com/es_ES/forum/ayuda-1/issue-return-dynamic-domain-for-field-with-on-change-method-in-odoo-17-253508.

Thank you so much.

The only thing I need to finish now is how the information is displayed in my Many2one field. Currently, I see the format [modelname, id]. I read that the name_get method should be used, but I haven't been able to make it work yet.

Thank you again. Best regards,

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
space characters are femoved directly after typen them
type
Avatar
0
Juli 24
1916
using a attribute of another module table as a foreign key
foreignkey
Avatar
0
Feb. 18
3974
How to implement foreign key in open erp
foreignkey
Avatar
Avatar
Avatar
2
März 15
9350
About Odoo Inventory Gelöst
type Inventory
Avatar
Avatar
Avatar
2
Dez. 24
3540
What is the purpose of Subtypes in Odoo? Gelöst
sub type
Avatar
Avatar
1
Juni 23
3572
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