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
    • Artificial Intelligence
    • 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ó
    • Property Management
    • 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
    • Referral Program
    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
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

What does <field name="model_id" ref="XXXX"> refer to?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
server_actions
1 Respondre
34907 Vistes
Avatar
Darrel

I'm currently looking at stored server actions in XML. Here is an example of one, from the crm addon:

        <record id="action_mark_as_lost" model="ir.actions.server">
            <field name="name">Mark As Lost</field>
            <field name="model_id" ref="model_crm_lead"/>
            <field name="state">code</field>
            <field name="code">
                if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
                    self.case_mark_lost(cr, uid, context['active_ids'], context=context)
            </field>
        </record>

What is "model_crm_lead?" Odoo generally refers to models by the name defined in the model, so it's referring to the crm.lead model, shouldn't the tag be:

<field name="model_id" ref="crm.lead"/>

I thought perhaps it is using the class name instead of the internal model name (for some reason), and prefacing it with "model_<MODEL_CLASS_NAME>" but I'm only guessing and don't really know how this field works or where it is explained.

Edit: Is it "model_<MODEL_TABLE_NAME>"? It's that isn't it?

0
Avatar
Descartar
Avatar
Marvin Taboada
Best Answer

Hello Darrel, before providing an answer, let me put some background information here.

Background:

At loading data by installing resources (models, fields, model-records, views, record rules, actions, menu entries, etc.), Odoo registers mapping records for all resources in the 'ir_model_data' table ('ir.model.data' object), so we can reference those records later, even from other modules.

Mapping records in 'ir_model_data' have the following remarkable columns:

  • module: module name, string literal (not its id)
  • model: fully-qualified dot-separated object name (also known as the object's technical name)
  • res_id: The resource id/Database ID (the PK of the record in the table where the resource is stored)
  • name: record name, a string literal that in conjunction with the module name uniquely identify the record/resource

The record name in conjunction with the module name form what we know as the resource External ID which has the following fully-qualified form: 'module_name.resource_name'.

Records defined in XML data define their External IDs by means of the 'id' attribute of the 'record' tag.

The 'id' attribute can explicitly include 'module_name.' (fully-qualified form) or not. In the later case (relative form) the module that declares the resource is assumed:
* https://github.com/odoo/odoo/blob/8.0/openerp/tools/convert.py#L707

The above long story was required to have enough background for the answer that follows.

Answer:

At processing child 'field' tags of any 'record' tag, the 'ref' attribute is expected to have the External ID of a referenced existing record (fully-qualified or relative form):
* https://github.com/odoo/odoo/blob/8.0/openerp/tools/convert.py#L727
* https://github.com/odoo/odoo/blob/8.0/openerp/tools/convert.py#L836

Mapping records that reference models are created at initializing modules/models/fields. As they lack a corresponding XML record and cannot declare its corresponding External ID by this means, the ORM creates its External ID based in the 'model_' prefix and the object's technical name (dots replaced by underscores):
* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L382

This is why records that reference models ('ir.model' records) have the following form: model_XXXXX

Records for some other resources also have known prefixes for their External IDs:

  • Modules: https://github.com/odoo/odoo/blob/8.0/openerp/modules/db.py#L90
  • Models: https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L382
  • Fields: https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L444

SELECT * FROM "ir_model_data" WHERE name LIKE 'module_%'; -- most are 'ir.module.module' records
SELECT * FROM "ir_model_data" WHERE name LIKE 'model_%' ORDER by module, name; -- all/most are 'ir.model' records
SELECT * FROM "ir_model_data" WHERE name LIKE 'field_%' ORDER BY module, name; -- all/most are 'ir.model.fields' records

Records for other resources may follow some convention or simply not:

SELECT * FROM "ir_model_data" WHERE name LIKE 'view_%' ORDER by module, name; -- all/most are 'ir.ui.view' records
SELECT * FROM "ir_model_data" WHERE model LIKE 'ir.ui.view' AND name NOT LIKE 'view_%' ORDER by module, name; -- 'ir.ui.view' records with unconventional names

I hope this helps you to clarify your doubts.

Regards,
Marvin

21
Avatar
Descartar
Dhinesh

+1 for prompt answer...

Darrel
Autor

Thanks a lot for the thorough answer Marvin. That's a lot of detailed info about Odoo I would have had a devil of a time digging up. I upvoted, and would set your answer to accepted, but the system won't let me.

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
server action for paid
server_actions
Avatar
Avatar
2
d’ag. 24
3413
When button is clicked, the form will proceed to next stage and execute codes
server_actions
Avatar
0
de gen. 25
3421
Update provider order in purchase tab on product details Solved
server_actions
Avatar
Avatar
Avatar
2
de juny 23
3052
Need Help Identifying Server Actions and Job Numbers
server_actions
Avatar
0
de maig 23
3830
How to create a sever action on website ?
server_actions
Avatar
Avatar
1
de juny 16
7418
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 Svenska ภาษาไทย 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