class product_info(osv.osv):
_name='product.info'
_columns={
'id':fields.integer('ID'),
'product_id':fields.many2one('product.product','Name',required=True),
'prod_category':fields.many2one('product.category','category'),
'valid_from':fields.date('Valid From'),
'valid_to':fields.date('Valid to'),
}
_sql_constraints=[('unique_product_id','unique(product_id)','Error! Product Name Already Exist!')]
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Can you share the log of your server, frequently there is a warning if the data base already exist that inform you yo must create the sql constraint manually, due to some records doesn't comply the constriant.
Yes, I would check this also. SQL constraints only work if ALL of the existing data in PostgreSQL satisfy the constraint. if you install your module and any data DOES NOT satisfy the constraint, it will fail.
You can teke reference from the sales_team module for the same
_sql_constraints = [
('code_uniq', 'unique (code)', 'The code of the sales team must be unique !')
]
or you can refer this link Constraints Help
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ