Merge pull request #25109 from ankush/po_to_pr_fixes
fix: incorrect status creating PR from PO after creating PI
This commit is contained in:
commit
fe72e17a7b
@ -368,7 +368,6 @@ def make_purchase_receipt(source_name, target_doc=None):
|
||||
"Purchase Order": {
|
||||
"doctype": "Purchase Receipt",
|
||||
"field_map": {
|
||||
"per_billed": "per_billed",
|
||||
"supplier_warehouse":"supplier_warehouse"
|
||||
},
|
||||
"validation": {
|
||||
|
@ -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
erpnext/patches/v12_0/purchase_receipt_status.py
Normal file
30
erpnext/patches/v12_0/purchase_receipt_status.py
Normal file
@ -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)
|
@ -176,7 +176,7 @@ class PurchaseReceipt(BuyingController):
|
||||
if flt(self.per_billed) < 100:
|
||||
self.update_billing_status()
|
||||
else:
|
||||
self.status = "Completed"
|
||||
self.db_set("status", "Completed")
|
||||
|
||||
|
||||
# Updating stock ledger should always be called after updating prevdoc status,
|
||||
|
@ -912,6 +912,57 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
ste1.cancel()
|
||||
po.cancel()
|
||||
|
||||
|
||||
def test_po_to_pi_and_po_to_pr_worflow_full(self):
|
||||
"""Test following behaviour:
|
||||
- Create PO
|
||||
- Create PI from PO and submit
|
||||
- Create PR from PO and submit
|
||||
"""
|
||||
from erpnext.buying.doctype.purchase_order import test_purchase_order
|
||||
from erpnext.buying.doctype.purchase_order import purchase_order
|
||||
|
||||
po = test_purchase_order.create_purchase_order()
|
||||
|
||||
pi = purchase_order.make_purchase_invoice(po.name)
|
||||
pi.submit()
|
||||
|
||||
pr = purchase_order.make_purchase_receipt(po.name)
|
||||
pr.submit()
|
||||
|
||||
pr.load_from_db()
|
||||
|
||||
self.assertEqual(pr.status, "Completed")
|
||||
self.assertEqual(pr.per_billed, 100)
|
||||
|
||||
def test_po_to_pi_and_po_to_pr_worflow_partial(self):
|
||||
"""Test following behaviour:
|
||||
- Create PO
|
||||
- Create partial PI from PO and submit
|
||||
- Create PR from PO and submit
|
||||
"""
|
||||
from erpnext.buying.doctype.purchase_order import test_purchase_order
|
||||
from erpnext.buying.doctype.purchase_order import purchase_order
|
||||
|
||||
po = test_purchase_order.create_purchase_order()
|
||||
|
||||
pi = purchase_order.make_purchase_invoice(po.name)
|
||||
pi.items[0].qty /= 2 # roughly 50%, ^ this function only creates PI with 1 item.
|
||||
pi.submit()
|
||||
|
||||
pr = purchase_order.make_purchase_receipt(po.name)
|
||||
pr.save()
|
||||
# per_billed is only updated after submission.
|
||||
self.assertEqual(flt(pr.per_billed), 0)
|
||||
|
||||
pr.submit()
|
||||
|
||||
pi.load_from_db()
|
||||
pr.load_from_db()
|
||||
|
||||
self.assertEqual(pr.status, "To Bill")
|
||||
self.assertAlmostEqual(pr.per_billed, 50.0, places=2)
|
||||
|
||||
def get_sl_entries(voucher_type, voucher_no):
|
||||
return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference
|
||||
from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s
|
||||
|
Loading…
x
Reference in New Issue
Block a user