Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
server_actions
1 Reply
34820 Views
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
Discard
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
Discard
Dhinesh

+1 for prompt answer...

Darrel
Author

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!

Sign up
Related Posts Replies Views Activity
server action for paid
server_actions
Avatar
Avatar
2
Aug 24
3349
When button is clicked, the form will proceed to next stage and execute codes
server_actions
Avatar
0
Jan 25
3251
Update provider order in purchase tab on product details Solved
server_actions
Avatar
Avatar
Avatar
2
Jun 23
3008
Need Help Identifying Server Actions and Job Numbers
server_actions
Avatar
0
May 23
3761
How to create a sever action on website ?
server_actions
Avatar
Avatar
1
Jun 16
7370
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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