1
votes

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
How are you defining the form for your implementation.project? Also, please show your full classCésar

1 Answers

0
votes

In Your currenct example, field tasks is one2many to project.task model by field project_id:

'tasks': fields.one2many('project.task', 'project_id', "Task Activities"),

, which means that Odoo expects project.task model to have many2one field project_id that references implementation.project model, but project.task model still have field project_id as foreign key to project.project model:

'project_id': fields.many2one('project.project', 'Project', ...)

, but Your implementation.project is completely new model (and database table).

May be inheritance by delegation will better suit for Your needs?

Also look in inheritance doc

In this case, your implementation.project model will look like:

class implementation_project(osv.Model):
    _name = 'implementation.project'
    _inherits = {'project.project': 'project_id'}

    _columns = {
        'project_id': fields.many2one('project.project', 'Project'),
    }

This will allow to use all fields of project.project model on Your own model, with out no changes.

For examples You may look at product.template and product.product models code