当前位置:网站首页>Constraints of odoo
Constraints of odoo
2022-07-16 09:08:00 【Jiang Zhenjian 15954039008】
There are two ways to implement constraints :
SQL Constraints are an effective way to ensure data consistency . But if more complex inspections are needed , We need Python constraint .
1、sql constraint
SQL Constraints are defined by model attributes _sql_constraints(name, sql_definition, message).
The following code :
_sql_constraints = [
(‘code_company_uniq’, ‘unique (code,company_id)’, ‘ Account number must be unique !’)
]
Realization effect :
Amount cannot be less than 0 The realization effect of :
2、python constraint
grammar :@api.constrains(‘date_end’)
If realized, it shall not be lower than the expected price 90% The effect of the quotation :
To realize date judgment ( The end date cannot be before today ), The code is as follows :
from odoo.exceptions import ValidationError
...
@api.constrains('date_end')
def _check_date_end(self):
for record in self:
if record.date_end < fields.Date.today():
raise ValidationError(" The end date cannot be before today ")
# all records passed the test, don't return anything
summary :
SQL Constraints are usually greater than Python Constraints are more effective . When performance is important , I prefer SQL constraint instead of Python constraint .
边栏推荐
猜你喜欢

ADB环境配置

Three methods are used to simulate the implementation of the library function strlen to deepen the understanding of strlen

Virtualization path of GPU resource pool

Problems encountered when using yolov5

成员函数之析构函数

LeetCode 2155. All subscripts with the highest score in the group

odoo cli介绍(一)

Hcip second experiment

dtcloud 的消息机制(二)

Memory mapping principle and detailed explanation (very practical)
随机推荐
Simulate the implementation of the library function strcpy, and further understand strcpy (deeply understand the overlapping problem, and prevent the memory from overlapping with the source)
HCIP第五天笔记
Message mechanism of dtcloud (I)
I opened the permission of datastutio and automatically generated an SQL task that has been executing, which indicates that the permission allocation has not been completed
odoo多公司
Input get focus
Flink SQL asks which function was last month?
QT+VS 工程在 Release/Debug 文件夹下导入相关 DLL (非常实用)
字符串库函数和内存操作库函数详解及模拟实现
Why do more and more people want to take the PMP project management certification?
如何报考PMP项目管理认证考试?
音视频学习(七)——AAC音频码流
首届人工智能安全大赛启动报名 三大赛题等你来战
CloudCompare&PCL 点云最小二乘法拟合平面
容错、熔断的使用与扩展
Jupyterab installation
天田AMADA数控折弯机触摸屏维修RGM21003主机电路板维修
Vscode input! No prompt, unable to automatically complete the solution (latest)
Hardware iic+dma operation sharing based on stm32f405
GPU资源池的虚拟化路径