Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
5743 Weergaven

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
Avatar
Annuleer
Auteur

Thank you Usman, it worked perfectly.

Beste antwoord


    @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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
okt. 23
2078
2
okt. 23
2315
2
okt. 23
5776
3
sep. 23
2620
2
aug. 23
4329