원클릭으로
odoo-constraints
Ensure data consistency using SQL Constraints and Python Constraints.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Ensure data consistency using SQL Constraints and Python Constraints.
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).
Master the Odoo ORM for data manipulation, environment management, and CRUD operations.
Configure Access Control Lists (ACLs) using CSV files.
Write automated tests using TransactionCase and Form emulators to ensure code quality.
| name | Odoo Constraints |
| description | Ensure data consistency using SQL Constraints and Python Constraints. |
Prevent invalid data from being saved to the database.
Enforced by the PostgreSQL database. Efficient and atomic.
_sql_constraints model attribute.('constraint_name', 'SQL CHECK/UNIQUE', 'Error Message').Example:
class EstateProperty(models.Model):
_name = "estate.property"
_sql_constraints = [
('check_expected_price', 'CHECK(expected_price > 0)', 'The expected price must be positive.'),
('check_selling_price', 'CHECK(selling_price >= 0)', 'The selling price must be positive.'),
('name_uniq', 'UNIQUE(name)', 'Property name must be unique!'),
]
Enforced by Odoo server application logic. Used for complex validations that SQL cannot handle easily.
@api.constrains('field1', 'field2')odoo.exceptions.ValidationError if check fails.Example:
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare
@api.constrains('selling_price', 'expected_price')
def _check_selling_price(self):
for record in self:
# Skip check if no selling price is set
if float_is_zero(record.selling_price, precision_digits=2):
continue
# Check if selling price is lower than 90% of expected
if float_compare(record.selling_price, record.expected_price * 0.9, precision_digits=2) == -1:
raise ValidationError("Selling price cannot be lower than 90% of the expected price.")
float_compare and float_is_zero when working with monetary fields to avoid rounding errors.@api.constrains are modified.