From 623b4c21cd70f709940ee938ddac9c2a86c7c3f0 Mon Sep 17 00:00:00 2001 From: Poorvi-R-Bhat Date: Tue, 9 Jul 2024 14:59:31 +0530 Subject: [PATCH] fix: corrected mismatch in the Purchase Receipt Status #15620 (#42138) --- erpnext/controllers/status_updater.py | 5 ++++- .../purchase_receipt/purchase_receipt.json | 3 ++- .../purchase_receipt/test_purchase_receipt.py | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 17f072ebb07b..a0b102dbc540 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -102,7 +102,10 @@ def validate_status(status, options): ["To Bill", "eval:self.per_billed == 0 and self.docstatus == 1"], ["Partly Billed", "eval:self.per_billed > 0 and self.per_billed < 100 and self.docstatus == 1"], ["Return Issued", "eval:self.per_returned == 100 and self.docstatus == 1"], - ["Completed", "eval:self.per_billed == 100 and self.docstatus == 1"], + [ + "Completed", + "eval:(self.per_billed == 100 and self.docstatus == 1) or (self.docstatus == 1 and self.grand_total == 0 and self.per_returned != 100 and self.is_return == 0)", + ], ["Cancelled", "eval:self.docstatus==2"], ["Closed", "eval:self.status=='Closed' and self.docstatus != 2"], ], diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json index 0c460b4aabf4..0027818edc36 100755 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json @@ -1111,6 +1111,7 @@ "depends_on": "eval:!doc.__islocal", "fieldname": "per_returned", "fieldtype": "Percent", + "in_list_view": 1, "label": "% Returned", "no_copy": 1, "print_hide": 1, @@ -1272,7 +1273,7 @@ "idx": 261, "is_submittable": 1, "links": [], - "modified": "2024-04-08 20:23:03.699201", + "modified": "2024-07-04 14:50:10.538472", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt", diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 54b16284b167..d8417f02c6ef 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -8,6 +8,7 @@ import erpnext from erpnext.accounts.doctype.account.test_account import get_inventory_account +from erpnext.buying.doctype.supplier.test_supplier import create_supplier from erpnext.controllers.accounts_controller import InvalidQtyError from erpnext.controllers.buying_controller import QtyMismatchError from erpnext.stock import get_warehouse_account_map @@ -3269,6 +3270,22 @@ def test_do_not_use_batchwise_valuation_rate(self): doc.flags.ignore_validate = True doc.save() + def test_status_mapping(self): + item_code = "item_for_status" + create_item(item_code) + create_item("item_for_status") + warehouse = create_warehouse("Stores") + supplier = "Test Supplier" + create_supplier(supplier_name=supplier) + pr = make_purchase_receipt( + item_code=item_code, + warehouse=warehouse, + qty=1, + rate=0, + ) + self.assertEqual(pr.grand_total, 0.0) + self.assertEqual(pr.status, "Completed") + def prepare_data_for_internal_transfer(): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier @@ -3512,7 +3529,6 @@ def make_purchase_receipt(**args): pr.insert() if not args.do_not_submit: pr.submit() - pr.load_from_db() return pr