Search code examples
pythonxmlodooodoo-8

i want to change the actual city field in res.partner adress to a many2one field without adding new field


My code looks like :

# -*- encoding: utf-8 -*-

from openerp import models,fields, api

class ResPartner(models.Model):
    _name = 'res.partner'
    _inherit = 'res.partner'

    city_id = fields.Many2one('res.city','Ville',stored = True 
                               ,ondelete='restrict')

class ResCity(models.Model):
    _name = "res.city"
    _description = "Ville"

    name = fields.Char(u"Nom",required = True)
    state_id = fields.Many2one("res.country.state", 'Zone',ondelete='restrict')

so after i've add the view in xml but my request is that i need to change the actual field without adding a new one the old : city = fields.char the new should look like : city = fields.many2one


Solution

  • Just override the old API defined city field in old API:

    from openerp import models,fields, api
    from openerp.osv import fields as ofields
    
    class ResPartner(models.Model):
        _inherit = 'res.partner'
    
        _columns = {
            'city': ofields.many2one('res.city', 'Ville', ondelete='restrict'),
        }
    

    Have in mind, that lot of views won't work anymore, for example the partner kanban view.