From a7fc278b609869672b907651c0c4ec7d455c2317 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:54:56 +0530 Subject: [PATCH] fix(job card): only hold during draft state (backport #31243) (#31249) * fix(job card): only hold during draft state (#31243) (cherry picked from commit ee5bc58e9ba8b4c4b4ab255101919974302068e6) # Conflicts: # erpnext/patches.txt * chore: conflicts Co-authored-by: Ankush Menat --- .../doctype/job_card/job_card.py | 2 +- erpnext/patches.txt | 2 +- .../patches/v13_0/job_card_status_on_hold.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v13_0/job_card_status_on_hold.py diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index cc2f8c60e58..dadaaf9aa96 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -621,7 +621,7 @@ class JobCard(Document): self.set_status(update_status) def set_status(self, update_status=False): - if self.status == "On Hold": + if self.status == "On Hold" and self.docstatus == 0: return self.status = {0: "Open", 1: "Submitted", 2: "Cancelled"}[self.docstatus or 0] diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 584d65c6c2c..63b146d99fe 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -366,4 +366,4 @@ erpnext.patches.v13_0.requeue_recoverable_reposts erpnext.patches.v13_0.create_accounting_dimensions_in_orders erpnext.patches.v13_0.set_per_billed_in_return_delivery_note erpnext.patches.v13_0.update_employee_advance_status - +erpnext.patches.v13_0.job_card_status_on_hold diff --git a/erpnext/patches/v13_0/job_card_status_on_hold.py b/erpnext/patches/v13_0/job_card_status_on_hold.py new file mode 100644 index 00000000000..8c67c3c858e --- /dev/null +++ b/erpnext/patches/v13_0/job_card_status_on_hold.py @@ -0,0 +1,19 @@ +import frappe + + +def execute(): + job_cards = frappe.get_all( + "Job Card", + {"status": "On Hold", "docstatus": ("!=", 0)}, + pluck="name", + ) + + for idx, job_card in enumerate(job_cards): + try: + doc = frappe.get_doc("Job Card", job_card) + doc.set_status() + doc.db_set("status", doc.status, update_modified=False) + if idx % 100 == 0: + frappe.db.commit() + except Exception: + continue