Update doc on hooks before_save

Hi, how I can update some doc using hooks? I have create a custom field on Salary Slip, and I want to fill that field using doc_events on hook.

I already tried

doc_events = {
    "Salary Slip": {
        "before_save": "attendance_manager.salary_slip.before_save"

and the method is

def before_save(doc, method):
    doc.custom_field = "value"

but it not working

I already tried with on_update event and call doc.save() but it ended infinity loop

any suggestion?


I found the solution. I need to return the doc.

def before_save(doc, method):
    doc.custom_field = "value"
    return doc

and I use before_validate instead of before_save

Can you tell me what is the value that you send to salary slip field

because I want to get total absent days for employee from attendance table to salary slip