Restrict on2many items lets say limit is 15 for adding in one2many items.
it should show error if crossed 15.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Restrict on2many items lets say limit is 15 for adding in one2many items.
it should show error if crossed 15.
Hi,
Use @api.constrains to limit the adding of item in a one2many field
Here is sample code:
class SaleOrder(models.Model):
_name = 'sale.order'
_description = 'Sale Order'
name = fields.Char(string='Name')
sale_lines = fields.One2many('sale.order.line', 'order_id', string='Sale Lines')
@api.constrains('sale_lines')
def _check_sale_lines(self):
for record in self:
if len(record.sale_lines) > 15:
raise ValidationError('Not more than 15lines')
When a user attempts to add more than 15 lines to a sale order, the constraint will be triggered and prevent the change from being saved.
Hope it helps
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ| Related Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
|---|---|---|---|---|
|
0
พ.ย. 25
|
163 | |||
|
0
พ.ย. 25
|
3314 | |||
|
0
ต.ค. 25
|
389 | |||
|
2
ส.ค. 25
|
3865 | |||
|
1
ก.ค. 25
|
1896 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.