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
    • Umělá inteligence
    • 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
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

Integrity Error on object creation

Odebírat

Get notified when there's activity on this post

This question has been flagged
3 Odpovědi
6861 Zobrazení
Avatar
Yulybaseball

Hi there:

I am developing a new model called implementation.project; it inherits from project.project. This is the class declaration:

class implementation_project(osv.Model):
    _name = 'implementation.project'
    _inherit = 'project.project'

Some fields (columns) are added to this class (model or whatever). Original model (project.project) has a one2many field called 'tasks'. When I try to create new 'implementation.project' record, the enigmatic Odoo raises this error:

IntegrityError: insert or update on table "project_task_type_rel" violates foreign key constraint "project_task_type_rel_project_id_fkey"
DETAIL:  Key (project_id)=(6) is not present in table "project_project".

Obviously!!!! It has to exist project.project record to create anything that inherits from him!!! I guess Odoo (according to some, a good platform to develop) has the ability to know how to proceed in this case... or not????

So, how to create new record from 'implementation.project'????

 

Thanks in advance.

 

1
Avatar
Zrušit
Avatar
Yulybaseball
Autor Nejlepší odpověď

Note: I am sorry for posting an answer. It should be a Comment, but I can't: surprinsigly, I need 50 karma to do that... even for an answer to my question.

@Bole, first of all, THANK YOU VERY MUCH!!! It works!!!

Second, what you explained is entirely logical... but I assumed Odoo would better understand the inheritance. Why I have to assume I have to "redeclare" parent fields??? Please, it's an inheritance!!! If I have a model, and I have to inherit from it... what is the sense of the inheritance if I have to redeclare all fields??? (Assuming all parent fields are relations to other models).

Third, OK, I understand developers must know how works the platform they are going to develop on... but how to know how Odoo works? Where is the developer documentation?  

Fourth, I am sorry. I went to mark your reply as the Accepted one, but I need more Karma... 

 

 

2
Avatar
Zrušit
DAJ MI 5, Bole

correction.. you do not REDECLARE... you OVERRIDE inherited field in order to change (correct) the relation ... as for documentation... we (some developers) have a wery good friend ... his name is google.... try asking our mutual firend does he know something about "openerp technical memento" ... also... check http://doc.openerp.com for v7 or https://www.odoo.com/documentation/8.0/ for v8 ... after that.. you affocurse have this forum... and a lot of private blogistes .... so .. resources are all over.. all you need is time to read it and more time to understand it :)

Avatar
DAJ MI 5, Bole
Nejlepší odpověď

Well... 
class implementation_project(osv.Model):
    _name = 'implementation.project'
    _inherit = 'project.project'

What you did is, you created a completley new object 'implementation.project' wich inherited all fields from original class...
and then you added some new custom fields...
But, what you did NOT do is.. change some of inherited fields... one of them is :
'type_ids': fields.many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),

SO now you have your new model, with task type related to old model.. 
what you should do is override that field like:
'type_ids': fields.many2many('project.task.type', 'implementation_project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}), 
in order to establish a new relatin table between your new created model and old task_type model... 

Now cretaing record should work just fine.. 

hope it helps : )

p.s. 
odoo is nice platform for rapid development of businees apps... but, in order to use it you have to firs know how it works...
in other words RTFM :)

 

1
Avatar
Zrušit
Avatar
Ivan
Nejlepší odpověď

Odoo has a couple of way that you can inherit an object from.  One way is how you did, which is using the _inherit attribute with a string value that matches the name of the model that you want to inherit.  This way Odoo will extend the original model.  The class name bears no "meaning" to the ORM model.  The _name attribute, however may change the _name attribute of the original model (can't say for sure as I haven't really check it out).  When you create a record, you need to specify all the values of the necessary fields.  All values will be written on the same table.

The second way is to use _inherits = {'model.name': 'field_name'}.  This is done, e.g. for product.product in which it inherit product.template (check out the odoo/odoo/addons/product/product.py file).  This is a creation of another class that inherits a different parent class.  The sub class will have 'field_name' but all the fields/columns that belongs to the parent class will be written in the parent's class table.  When you create a record, you need to specify all the values of the necessary fields.  Values belonging to parent class will be written into the parent's table and values beloging to child class will be written in the child's table.

The third way, usually used for mixin is to use _inherit = ['mixin.model'].  You can also checkout product.product as it also inherits 'mail.thread'.  As it is just extension of capability, it adds no additional fields.

 

0
Avatar
Zrušit
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
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 Svenska ภาษาไทย 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