跳至内容
菜单
此问题已终结
1 回复
5703 查看

Hi I'm new to Odoo and I'm trying to get the address from the contacts model when this value is changed, is there any way to do it? I try this but I get an error:

# -*- coding: utf-8 -*-
from odoo import models, fields, api

class ClassCompany(models.Model):
    _name = "company.data"
    name = fields.Char(string='Name of the company')
    ceo=fields.Many2one('res.partner'string='CEO of the company')
    address= fields.Char(string="Address")
    date_of_foundation=fields.Date(string="Foundation date")

    @api.onchange('ceo')
    def _get_direction(self):
        new_address=self.env['res.partner'].search([('name''='self.ceo)]).address
        self.address=new_address
形象
丢弃
编写者

Thank you Usman, it worked perfectly.

最佳答案


    @api.onchange('ceo')
    def _get_direction(self):
        new_address=self.env['res.partner'].search([('id''='self.ceo.id)]).street or false
        self.address=new_address

or use Related fields to get proper result

形象
丢弃
相关帖文 回复 查看 活动
1
10月 23
2049
2
10月 23
2293
2
10月 23
5756
3
9月 23
2592
2
8月 23
4303