Skip to content

Commit

Permalink
[IMP] hr_attendance_modification_tracking: implement `@model_create_m…
Browse files Browse the repository at this point in the history
…ulti`

Enable batch creation of records by applying the `@model_create_multi` decorator,
improving performance when creating multiple records at once.
  • Loading branch information
hirenST committed Oct 11, 2024
1 parent 4bd6d75 commit 69238aa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions hr_attendance_modification_tracking/models/hr_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ class HrAttendance(models.Model):
"be applied.",
)

@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
tolerance = timedelta(seconds=60)
now = fields.Datetime.now()
for check in ["check_in", "check_out"]:
if (
vals.get(check, False)
and abs(fields.Datetime.from_string(vals.get(check)) - now) > tolerance
):
vals.update({"time_changed_manually": True})
break
return super().create(vals)
for vals in vals_list:
for check in ["check_in", "check_out"]:
if (
vals.get(check, False)
and abs(fields.Datetime.from_string(vals.get(check)) - now)
> tolerance
):
vals.update({"time_changed_manually": True})
break
return super().create(vals_list)

def write(self, vals):
tolerance = timedelta(seconds=60)
Expand Down

0 comments on commit 69238aa

Please sign in to comment.