diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index ae03a3562c..3e22681009 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -207,6 +207,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.rejected_qty = -1* source_doc.rejected_qty target_doc.qty = -1* source_doc.qty target_doc.purchase_order = source_doc.purchase_order + target_doc.purchase_order_item = source_doc.purchase_order_item target_doc.rejected_warehouse = source_doc.rejected_warehouse elif doctype == "Purchase Invoice": target_doc.received_qty = -1* source_doc.received_qty diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 57dbc59839..d9e336d0bc 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -346,4 +346,5 @@ execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where pur erpnext.patches.v7_0.repost_gle_for_pi_with_update_stock #2016-11-01 erpnext.patches.v7_1.add_account_user_role_for_timesheet erpnext.patches.v7_0.set_base_amount_in_invoice_payment_table -erpnext.patches.v7_1.update_invoice_status \ No newline at end of file +erpnext.patches.v7_1.update_invoice_status +erpnext.patches.v7_0.po_status_issue_for_pr_return \ No newline at end of file diff --git a/erpnext/patches/v7_0/po_status_issue_for_pr_return.py b/erpnext/patches/v7_0/po_status_issue_for_pr_return.py new file mode 100644 index 0000000000..6e92ffb8a0 --- /dev/null +++ b/erpnext/patches/v7_0/po_status_issue_for_pr_return.py @@ -0,0 +1,36 @@ +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + parent_list = [] + count = 0 + for data in frappe.db.sql(""" + select + `tabPurchase Receipt Item`.purchase_order, `tabPurchase Receipt Item`.name, + `tabPurchase Receipt Item`.item_code, `tabPurchase Receipt Item`.idx, + `tabPurchase Receipt Item`.parent + from + `tabPurchase Receipt Item`, `tabPurchase Receipt` + where + `tabPurchase Receipt Item`.parent = `tabPurchase Receipt`.name and + `tabPurchase Receipt Item`.purchase_order_item is null and + `tabPurchase Receipt Item`.purchase_order is not null and + `tabPurchase Receipt`.is_return = 1""", as_dict=1): + name = frappe.db.get_value('Purchase Order Item', + {'item_code': data.item_code, 'parent': data.purchase_order, 'idx': data.idx}, 'name') + + if name: + frappe.db.set_value('Purchase Receipt Item', data.name, 'purchase_order_item', name, update_modified=False) + parent_list.append(data.parent) + + count +=1 + if count % 200 == 0: + frappe.db.commit() + + if len(parent_list) > 0: + for parent in set(parent_list): + doc = frappe.get_doc('Purchase Receipt', parent) + doc.update_qty(update_modified=False) \ No newline at end of file