Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2226 Lượt xem

i wants to add 2nd constraint in my Model below, what is the best correct way or method to do so.

(''check_price, 'CHECK(price >= 0)', 'The value of Inquiry -> Price can\'t be negative.'),


from odoo import models, fields


class CRMLeadsInquiry(models.Model):

    _inherit = "crm.lead"


    product_id = fields.Many2one('product.product', string='Product Name', required=False)

    qty = fields.Integer(string='Quantity', default=1)

   price = fields.Float(string='Price', default=1)


    _sql_constraints = [

            ('check_qty', 'CHECK(qty >= 0)', 'The value of Inquiry -> Quantity can\'t be negative.'),

    ]

note: if it can be, how many i _sql_constraints i can add? is there any limitations?

regards


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

so limitation.
example:

_sql_constraints = [
(
'unique_edi_document_by_move_by_format',
'UNIQUE(edi_format_id, move_id)',
'Only one edi document by move by format',
),
]


Ảnh đại diện
Huỷ bỏ
Tác giả

thanks @Arian Shariat for reply, will add as per advise.

set as answer if worket🙏

Câu trả lời hay nhất

_sql_constraints = [ ('unique_field_1_field_2',  'unique(field_1, field_2)', 'The combination field must be unique.') ]

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 23
2019
1
thg 7 23
4285
2
thg 10 23
3341
1
thg 8 23
4122
2
thg 7 25
3815