Purchase Invoice via API with Linked To Purchase Order

Hi There,
I am creating purchase invoice of an existing Purchase order via the following API.
Purchase invoice is created via API and connection has been made with the existing Purhcase Order But Status of Purchase order is still “To Receive and Bill” . It should be “To Recieve” .

This flow is working fine when I use UI to create Purchase Invoice.

API: {{api_hostname}}/api/resource/Purchase%20Invoice
body:
{
“purchase_order”: “PUR-ORD-2024-00025”,
“supplier”: “Ajooni Biotech Limited”,
“bill_no”:“AASRFGHJKL”,
“docstatus”: 1,
“items”: [
{
“item_code”: “AFABS11P50”,
“qty”: 10,
“rate”: 1000.0,
“purchase_order”: “PUR-ORD-2024-00025”
}
]

}

attached screenshot showing status with purchase invoice in connection and purchase invoice is submitted.


change the value of status field also via api

This is not working.

I tried updating by the PUT API

API: {{api_hostname}}/api/resource/Purchase%20Order/
Body:
{
“status”: “To Receive”
}

Response:
“exception”: “frappe.exceptions.UpdateAfterSubmitError: Not allowed to change Status after submission from To Receive and Bill to To Receive”,
“exc_type”: “UpdateAfterSubmitError”,

before submit doc

Why is this so?
We need to first submit the Purchaser order then after we should make a purchase invoice for the Purchase Order.

Why is this not happening, when I am doing it using the erpNext UI.