Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
typeforeignkeymismatch
2 Odpovědi
2549 Zobrazení
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
Zrušit
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
Nejlepší odpověď

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
Zrušit
Avatar
Nicolás
Autor Nejlepší odpověď

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
Zrušit
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,

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
space characters are femoved directly after typen them
type
Avatar
0
čvc 24
1917
using a attribute of another module table as a foreign key
foreignkey
Avatar
0
úno 18
3977
How to implement foreign key in open erp
foreignkey
Avatar
Avatar
Avatar
2
bře 15
9354
About Odoo Inventory Vyřešeno
type Inventory
Avatar
Avatar
Avatar
2
pro 24
3543
What is the purpose of Subtypes in Odoo? Vyřešeno
sub type
Avatar
Avatar
1
čvn 23
3573
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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