一键导入
odoo-orm-api
Master the Odoo ORM for data manipulation, environment management, and CRUD operations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Master the Odoo ORM for data manipulation, environment management, and CRUD operations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
A router skill that identifies and recommends the most appropriate Odoo skill for a given user request.
Create HTTP endpoints for Websites and APIs.
Comprehensive guide to Odoo fields, including basic, relational, computed, and robust technical features (indexing, company_dependent, properties).
Configure Access Control Lists (ACLs) using CSV files.
Write automated tests using TransactionCase and Form emulators to ensure code quality.
Define List, Form, and Search views in XML.
| name | Odoo ORM API |
| description | Master the Odoo ORM for data manipulation, environment management, and CRUD operations. |
Manipulate data programmatically using the Odoo Object-Relational Mapping (ORM) API.
self.env)The environment stores the context, the cursor, and the user.
self.env.user: The current user record.self.env.company: The current company record.self.env.context: A dictionary containing session data (lang, timezone, etc.).self.env.ref(xml_id): Get a record by its XML ID.Methods in Odoo models are executed with the current user's privileges. To change this:
sudo(): Switch to the Superuser (bypass security rules).
self.env['res.partner'].sudo().create({'name': 'Admin Contact'})
with_context(**kwargs): Add or modify context keys.
self.with_context(lang='fr_FR').name # Translates name to French
with_company(company): Switch the active company.search(domain, limit=None, offset=0, order=None): Returns a recordset.
properties = self.env['estate.property'].search([
('state', '=', 'new'),
('expected_price', '<', 100000)
], limit=10)
search_count(domain): Returns the number of records (integer).browse(ids): Returns a recordset from a list of IDs.
property = self.env['estate.property'].browse([1, 2, 3])
(field, operator, value).
=, !=, >, >=, <, <=, like, ilike, in, not in.& (AND, default), | (OR), ! (NOT).create(vals_list): Create new records.
# Single record
new_prop = self.env['estate.property'].create({'name': 'New House', 'expected_price': 50000})
# Multiple records (faster)
props = self.env['estate.property'].create([{'name': 'H1'}, {'name': 'H2'}])
write(vals): Update records.
# Updates ALL records in the recordset 'properties'
properties.write({'state': 'offer_received'})
unlink(): Delete records.
properties.unlink()
Use Odoo exceptions to stop execution and warn the user.
from odoo.exceptions import UserError, ValidationError
# Validations
if record.selling_price < record.expected_price * 0.9:
raise ValidationError("Selling price cannot be lower than 90% of expected price.")
# User Warnings
if not record.partner_id:
raise UserError("You must select a partner first.")
Optimization tools for recordsets.
mapped(field_name): Returns a list of values (or recordset if method returns records).
prices = properties.mapped('selling_price')
partners = properties.mapped('partner_id') # Returns recordset
filtered(func_or_field): Returns a subset of records.
# Filter by field boolean value
sold_props = properties.filtered('is_sold')
# Filter by lambda
expensive_props = properties.filtered(lambda p: p.expected_price > 500000)