Hello Yathithya Kathirvel,
You are getting this error because of the changes which was done regarding , stopping of the change of the account assignment category once the follow-on document exits in the system. So as per the change system reads the code and then checks for the old PO's follow-on Documents and once its true it won't allow to update it and you will get the error " account assignment cannot be changed after GR or Invoice" . I am not sure if you can maintain for the older PO's but for new PO's your code will work fine. Even if you try to update through FM/BADI , then again it will re-trigger the error message.
Thanks
Gaurav Gautam