بنقرة واحدة
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.