Skip to content

Commit

Permalink
fix: close PO on SCO close
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Dec 11, 2023
1 parent 89a0e9c commit b023e5d
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from frappe.utils import flt

from erpnext.buying.doctype.purchase_order.purchase_order import is_subcontracting_order_created
from erpnext.buying.doctype.purchase_order.purchase_order import update_status as update_po_status
from erpnext.controllers.subcontracting_controller import SubcontractingController
from erpnext.stock.stock_balance import update_bin_qty
from erpnext.stock.utils import get_bin
Expand Down Expand Up @@ -308,6 +309,9 @@ def update_status(self, status=None, update_modified=True):
"Subcontracting Order", self.name, "status", status, update_modified=update_modified
)

if status == "Closed":
update_po_status("Closed", self.purchase_order)


@frappe.whitelist()
def make_subcontracting_receipt(source_name, target_doc=None):
Expand Down

4 comments on commit b023e5d

@ophl55
Copy link

@ophl55 ophl55 commented on b023e5d Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s-aga-r

Why should the PO be closed when the SCO gets closed?
Out of my point of view the PO should be set "Closed" only by the user. It should be open until the user sets it "Closed" or it gets "Completed" by submitting the PR.

The other way around makes more sense to me. The SCO should be automatically closed if the user closes the PO.
Currently there is no possibility to close a SCO by the user. Even if you close the PO you are still able to book SCR against the SCO. In the statistics the positions are also still open. But it makes absolutely no sense to let the SCO running when the related PO is already closed for reasons. We definetly require the option to close a SCO manually or automatically when the PO gets closed.

What do you think, shall I raise an issue for that?

@ophl55
Copy link

@ophl55 ophl55 commented on b023e5d Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another note: Currently the field "status" is missing the option "Closed" even though the code sets exactly that value.
Please check here: https://github.com/frappe/erpnext/blob/b562b4cf99e68108a0d7ba3a90e60ef3d7d01b0f/erpnext/subcontracting/doctype/subcontracting_order/subcontracting_order.json#L373C24-L373C24

@s-aga-r
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ophl55

Why should the PO be closed when the SCO gets closed?

There can be only one SCO against a Purchase Order, if the SCO gets closed the PO can't be completed.

The other way around makes more sense to me. The SCO should be automatically closed if the user closes the PO.

Will add this as well.

@ophl55
Copy link

@ophl55 ophl55 commented on b023e5d Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s-aga-r

Thank you for your fast reply. Feel free to contact me if you have any questions or need any support e.g. for reviewing the pull request.
For the sake of completeness here you can find the feature request: #38702

Have a nice day!

Please sign in to comment.