Insert warehouse field in items table using hook

Hye everyone,

In purchase order item table in purchase order doctype, warehouse field is compulsory. So what im trying here is to fill all the item_code with their warehouse automatically when the hit save button.

Previously i have tried on Custom script, but the warehouse field fetching is not consistent. Sometimes it manages to fill the warehouse, but mostly it cant fill it. Seem like there are background process that always override the warehouse field.

Now, im trying to use hook event method. Im able to fill all the warehouse field for each items at save using before_insert but the problem is when im trying to add new item, then at resave, it didnt read my py code at all. Have tried all event hook available but the only work so far is before_insert.

Any idea how to handle event after first save?.

Thanks guys.

for after first save event use the on_update hook


Have tried that, on_update hook didn’t work this time on Purchase Order.

The only working hook event is before_insert .