Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Access an object field from another object

Subscriure's

Get notified when there's activity on this post

This question has been flagged
newmodule
1 Respondre
4464 Vistes
Avatar
Pau Ubach

I have the following situation: 

An object A has a view with a field many2one of the object B, and B has a many2one of the object C.

A also has a related field A1 which displays a field (C1) in the object C, but we can select its value directly in A view.

I can select an existing B or create a new one. The same with C.

When I select to create new B and C I get the form view for the new object C. 

 

How can I set the value in C1 to be equal to A1?

 

I'm trying with:

def default_get(self, cr, uid, fields, context=None):
            _logger.info('Inside bdd_project.default_get')
            if context is None:
                context = {}
            res = super(bdd_project, self).default_get(cr, uid, fields, context=context)
            pl_obj = self.pool.get('bdd.pricelist')
            pl = pl_obj.browse(cr, uid, context.get('cus_id'), context=context)
            if 'cus_id' in fields:
                _logger.info('Inside if cus_id: value %s', pl.cus_id)
                res.update({'cus_id': pl.cus_id})
            return res

 

where bdd_project would represent the object C and bdd_pricelist would be A.

pl.cus_id is returning None.

0
Avatar
Descartar
Avatar
Ivan
Best Answer

Pau, the notion of having a related field means that you SHOULD NOT edit the value directly.  If you want to sync C1 with the value of A1 which is selected by User, then you should not define A1 as a related field, but define it as a normal field.

Then you on write (or create) of A, you can update the related C1 field value based on the value set by user.

0
Avatar
Descartar
Pau Ubach
Autor

The normal flow should be from C to A, I mean that C1 should be already defined when the view A is opened, and that's why it's a related field. But there's a rare scenario where an user could want start defining from A to C, and that's why I need to implement it this way.

Ivan

Pau, even if it is a rare chance, you still need to implement the synchronization, i.e. change A1 if C1 is updated and C1 if A1 is updated. You still can default A1 to display whatever value C1 is holding. Another approach that you may want to consider is to display B in A's form and C in B's form, hence user can change C1 from C's form instead of changing it from A's form. More longwinded for user, I understand.

Pau Ubach
Autor

John, what do you mean by implement the synchronization? Do you have a link to any document explaining how to do it? The request is to display C1 in A, and then filter B by this value.

Ivan

Pau, your first problem description is that user need to be able to change A1 and then C1 need to be change to be equal to A1. Does this still a requirement? If so, my answer stands. Synchronization is basically changing C1 when A1 is changed by user and A1 if C1 is selected by user. You need to inherit method write of both class A and C. For, say class A, you need to detect if there is any change in A1, and then change the related C1 value to be the same as A1, vv. If your first problem description is not correct, then I would suggest that you restate what you really need so the answer can be crafted more accurately.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
How to debug view XML when openerp doesn't say anything about it? Solved
newmodule
Avatar
Avatar
Avatar
2
de març 15
8682
Adding new modules in OpenERP
newmodule
Avatar
Avatar
2
de març 15
4393
Integrity Error with calendar.event module
newmodule
Avatar
0
de març 15
4298
Display a day in a schedule for a period
newmodule
Avatar
0
de març 15
4697
MRP module installed, but not available in the home screen Solved
mrp newmodule
Avatar
Avatar
1
de juny 16
4623
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now