Tutorial Odoo 9.0 Part 8 : Onchange & Model constraints
จาก Morange Wiki
รุ่นแก้ไขเมื่อ 06:04, 15 กรกฎาคม 2559 โดย Sirawich (คุย | มีส่วนร่วม) (หน้าที่ถูกสร้างด้วย ' <h2>Onchange</h2> แก้ไขไฟล์ดังนี้ <br/><br/> openacademy/models.py <pre> r.taken_seats =...')
Onchange
แก้ไขไฟล์ดังนี้
openacademy/models.py
r.taken_seats = 0.0 else: r.taken_seats = 100.0 * len(r.attendee_ids) / r.seats @api.onchange('seats', 'attendee_ids') def _verify_valid_seats(self): if self.seats < 0: return { 'warning': { 'title': "Incorrect 'seats' value", 'message': "The number of available seats may not be negative", }, } if self.seats < len(self.attendee_ids): return { 'warning': { 'title': "Too many attendees", 'message': "Increase seats or remove excess attendees", }, }
เมื่อมีการปรับเปลี่ยนค่าของ seats หรือ attendee จะทำให้ _verify_valid_seat ทำงาน
หากค่าของ seats น้อยกว่า 0 จะมีข้อความแจ้งเตือนดังภาพ
หากค่าของ seats น้อยกว่า attendee จะมีข้อความแจ้งเตือนดังภาพ