Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Integrity Error on object creation

Subscribe

Get notified when there's activity on this post

This question has been flagged
3 Replies
6801 Views
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
Discard
Avatar
Yulybaseball
Author Best Answer

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
Discard
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
Best Answer

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
Discard
Avatar
Ivan
Best Answer

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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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