← Back to team overview

openerp-community team mailing list archive

How to make a many2many relation between 2 new class

 

Hello,

For a client, I have make a specific customization :

In, i must create 2 new class with many2many relation between each.

Do you know a best solution ?

This is my solution :

# new class contract
class mymodule_contract(osv.osv):
    _name = 'mymodule.contract'
    _inherit = 'project.project'
    _description = 'My module contract: a contract is a special project
linked with a partner'

    _columns = {
                'partners': fields.many2many('res.partner',
'project_partner_rel', 'project_id', 'partner_id', 'Partners'),
 #I have removed others columns for this sample
                }


mymodule_contract()

# new class project
class mymodule_project(osv.osv):
    _name = 'mymodule.project'
    _inherit = 'project.project'
    _description = 'My ameliored project.'

    _columns = {
                'contracts': fields.many2many('mymodule.contract',
'project_contract_rel', 'project_id', 'contract_id', 'Contracts'),
 #I have removed others columns for this sample
                }

mymodule_project()

# This class is used to create the many2many relation (with column name
projects) on the mymodule.contract object.
class mymodule_contract_col(osv.osv):
    _inherit = 'mymodule.contract'
    _description = 'project.project'

    _columns = {
                'projects': fields.many2many('mymodule.project',
'project_contract_rel', 'contract_id', 'project_id', 'Projects'),
                }

mymodule_contract_col()

Thanks.


Best Regards.

David.