Skip to Content
Menu
This question has been flagged
3 Replies
1438 Views

Hello,

I have a form called "Admission Attendance Form". In that form I have fields for "Test", "Standard", "Date" , "Academic Year" and two Checkboxes for "Present" and "Absent". I want that when attendance for a student is marked against a specific Standard,Date,  Test and Academic Year, then in next shift student with same information should be unable to mark attendance. 

Please help.

Avatar
Discard
sir this is form...suppose asad ali marked his attendance....



Mailtrack Sender notified by
Mailtrack 27/11/19, 12:19:45

On Wed, 27 Nov 2019 at 12:19, Yaseen Jamii <yaseenjamii666@gmail.com> wrote:




Mailtrack Sender notified by
Mailtrack 27/11/19, 12:17:26

On Wed, 27 Nov 2019 at 12:11, Muhammad Anees <ranaanees30@gmail.com> wrote:

A new answer on How to restrict a student from marking attendance again: has been posted. Click here to access the post :

See post

Sent by Odoo S.A. using Odoo.





Mailtrack Sender notified by
Mailtrack 27/11/19, 12:17:26

On Wed, 27 Nov 2019 at 12:11, Muhammad Anees <ranaanees30@gmail.com> wrote:

A new answer on How to restrict a student from marking attendance again: has been posted. Click here to access the post :

See post

Sent by Odoo S.A. using Odoo.

Best Answer

Hello Yaseen,

You can do this in two ways.

1. By Inheriting Create Method

2. sql_constraints

---

1. By Inheriting Create Method

From the create method, you can search in the DB, the record with the same values already exists or not.

Like This,


@api.model
def create(self, vals):
res = super(YourClass, self).create(vals)
attendance_obj = self.env['your.model']
already_created_attendance = attendance_obj.search(
[('related_field_1', '=', res.related_field_1.id),
('related_field_2', '=', res.related_field_2.id),
('date', '=', res.date),
('char_field_1', '=', res.char_field_1)])
if len(already_created_attendance) > 1:
raise ValidationError(_('Attendance is already created'))
return res

Here in the example, I use related_field_1, char_field_1, etc.. you can use your fields instead.

2. _sql_constraints

_sql_constraints = [
('attendance_unique', 'unique(field_1, field_2, field_2, field_4)',
'Attendance Already Exist!'),
]


Thanks & Regards

Avinash Nadu Kandy

Avatar
Discard