Skip to content

Commit

Permalink
fix: patch for purchase receipt status
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 1, 2021
1 parent 427a98d commit 1438a23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions erpnext/patches.txt
Expand Up @@ -763,3 +763,4 @@ erpnext.patches.v13_0.setup_gratuity_rule_for_india_and_uae
erpnext.patches.v13_0.setup_uae_vat_fields
execute:frappe.db.set_value('System Settings', None, 'app_name', 'ERPNext')
erpnext.patches.v13_0.rename_discharge_date_in_ip_record
erpnext.patches.v12_0.purchase_receipt_status
30 changes: 30 additions & 0 deletions erpnext/patches/v12_0/purchase_receipt_status.py
@@ -0,0 +1,30 @@
""" This patch fixes old purchase receipts (PR) where even after submitting
the PR, the `status` remains "Draft". `per_billed` field was copied over from previous
doc (PO), hence it is recalculated for setting new correct status of PR.
"""

import frappe

logger = frappe.logger("patch", allow_site=True, file_count=50)

def execute():
affected_purchase_receipts = frappe.db.sql(
"""select name from `tabPurchase Receipt`
where status = 'Draft' and per_billed = 100 and docstatus = 1"""
)

if not affected_purchase_receipts:
return

logger.info("purchase_receipt_status: begin patch, PR count: {}"
.format(len(affected_purchase_receipts)))


for pr in affected_purchase_receipts:
pr_name = pr[0]
logger.info("purchase_receipt_status: patching PR - {}".format(pr_name))

pr_doc = frappe.get_doc("Purchase Receipt", pr_name)

pr_doc.update_billing_status(update_modified=False)
pr_doc.set_status(update=True, update_modified=False)

0 comments on commit 1438a23

Please sign in to comment.