Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v16 bug: SO unlinked from PO on cancellation #43944

Open
casesolved-co-uk opened this issue Oct 31, 2024 · 0 comments
Open

v16 bug: SO unlinked from PO on cancellation #43944

casesolved-co-uk opened this issue Oct 31, 2024 · 0 comments
Labels

Comments

@casesolved-co-uk
Copy link
Contributor

casesolved-co-uk commented Oct 31, 2024

Information about bug

The accounts controller has specific functionality to unlink SOs from POs when the SO is cancelled. This seems counter-intuitive, consider the following use-case:

  • Create a PO from an SO. When the SO is no longer required and is cancelled, the user should be asked whether they also wish to cancel the PO, because they would need to inform the supplier. If the PO is not cancelled, it would still make sense that the PO remains linked to the SO for traceability;
  • One common reason for cancelling an SO is to amend it, therefore the link from the PO should also be amended to point to the new SO;
  • If the link is being removed to allow for easy SO deletion, I would argue deletion should be prevented and fail specifically because the link exists if the PO is still active. For many use-cases, a PO would not be linked to an SO anyway.
  • If on amending the Sales Order the PO Sales Order Item link no longer exists, it could be cleared but doesn't really matter because it is a data field and not a link field anyway.

if self.doctype == "Sales Order":
self.unlink_ref_doc_from_po()
def unlink_ref_doc_from_po(self):
so_items = []
for item in self.items:
so_items.append(item.name)
linked_po = list(
set(
frappe.get_all(
"Purchase Order Item",
filters={
"sales_order": self.name,
"sales_order_item": ["in", so_items],
"docstatus": ["<", 2],
},
pluck="parent",
)
)
)
if linked_po:
frappe.db.set_value(
"Purchase Order Item",
{"sales_order": self.name, "sales_order_item": ["in", so_items], "docstatus": ["<", 2]},
{"sales_order": None, "sales_order_item": None},
)
frappe.msgprint(_("Purchase Orders {0} are un-linked").format("\n".join(linked_po)))

To further support this bug, it does not align with the operation for creating further POs from an amended SO. At several points the SO client code checks the item quantity against the ordered quantity, the ordered quantity having being set upon PO creation, but not cleared on SO cancellation to align with the link removal above:

let pending_items = this.frm.doc.items.some((item) => {
let pending_qty = flt(item.stock_qty) - flt(item.ordered_qty);
return pending_qty > 0;
});

me.frm.doc.items.forEach((d) => {
let ordered_qty = me.get_ordered_qty(d, me.frm.doc);
let pending_qty = (flt(d.stock_qty) - ordered_qty) / flt(d.conversion_factor);
if (pending_qty > 0) {
po_items.push({
doctype: "Sales Order Item",
name: d.name,
item_name: d.item_name,
item_code: d.item_code,
pending_qty: pending_qty,
uom: d.uom,
supplier: d.supplier,
});
}
});

This means if you cancel an SO, and also cancel the PO manually, you cannot create the PO from the SO again, because the ordered quantity is still set, and is read-only so cannot be cleared manually.

What should happen:

Upon SO cancellation, the user should be asked if the PO(s) should also be cancelled and prompted to inform their Supplier:

  • If yes, the SO & PO cancelled and the SO ordered quantity cleared
  • If no, the PO remains unchanged and the SO cancelled

Upon SO amend and the PO is still active:

  • SO links should be updated on the PO Items

Upon SO Item amend of line already linked from an active PO:

  • Amend of quantity: Warn the user that the PO will no longer accurately reflect the SO. An increase in SO quantity will be picked up by creation of further POs. A decrease will result in excess stock;
  • Line deletion: clear the PO Sales Order Item field. This could trigger a warning on the PO line: "Originating Sales Order line has been removed on amend"

Backport:
version-15
version-14

Module

accounts, buying, selling

Version

ERPNext - develop v16

Installation method

None

Relevant log output / Stack trace / Full Error Message.

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant