Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Intelligence artificielle
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Supermarché
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Homme à tout faire
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenir partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Integrity Error on object creation

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
3 Réponses
6910 Vues
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
Ignorer
Avatar
Yulybaseball
Auteur Meilleure réponse

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
Ignorer
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
Meilleure réponse

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
Ignorer
Avatar
Ivan
Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenir partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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