PO, Project, PINV - Missing Links

I have the following situation at hand

  • Purchase Order - linked to Project
  • Project - linked to PO and PINV
  • 2 Purchase Invoices - linked to Project, and Payments, not linked to PO

now the Purchase Order say “To Deliver and Bill”, where factually it has been billed and paid already.

Is there any way to create the missing links between my PINV’s and the PO without cancelling all documents from the Payment Entries via PINV’s up to the Project and re-create everything?

As a last resort I wouldn’t mind to do this in the db directly if there is not other way.

Have you checked the root cause as to why it remains open? Are some of the PO positions not linked to the billed items (check the references in Purchase Order.items) or is there a valuation difference? We have cases (in the sales part), where we manually need to add the references ( frappe.model.set_value) when e.g. creating aggregated invoices… In case the valuation differs, as far as I know you will have to change the status of the order to “Closed”…

Hope this is helpful.

well in my case it is most probably a user error. Someone did it in the wrong way. which I am trying to fix. I guess someone Created a PINV from a project which at that time may not have been connected correctly to the PO. Something along those lines.

Got it. In that case you will need the order number (items.purchase_order) and the name of the position line (items.po_detail)…

do you believe there is a way to adjust those values without untying all documents involved in this?

To automatically close, as fra as I know you need to set the traces. Otherwise, you will have to set the status of the purchase order to “Closed”…