From e7e8149fbe8ea4829795308fd6e698567178d0f5 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 25 Feb 2024 11:59:44 +0530 Subject: [PATCH 1/7] feat: update billed amount in PO and PR (cherry picked from commit 9f6535472d50e651fa99ef7b9001ce913acb6902) # Conflicts: # erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json --- .../purchase_invoice/purchase_invoice.json | 20 +++++++++++++++++++ .../purchase_invoice/purchase_invoice.py | 15 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index f85fc878ab4..70fe93b011f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -22,6 +22,8 @@ "is_paid", "is_return", "return_against", + "update_billed_amount_in_purchase_order", + "update_billed_amount_in_purchase_receipt", "apply_tds", "tax_withholding_category", "amended_from", @@ -412,6 +414,20 @@ "read_only": 1, "search_index": 1 }, + { + "default": "0", + "depends_on": "eval: doc.is_return", + "fieldname": "update_billed_amount_in_purchase_order", + "fieldtype": "Check", + "label": "Update Billed Amount in Purchase Order" + }, + { + "default": "1", + "depends_on": "eval: doc.is_return", + "fieldname": "update_billed_amount_in_purchase_receipt", + "fieldtype": "Check", + "label": "Update Billed Amount in Purchase Receipt" + }, { "fieldname": "section_addresses", "fieldtype": "Section Break", @@ -1612,7 +1628,11 @@ "idx": 204, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-11-29 15:35:44.697496", +======= + "modified": "2024-02-25 11:20:28.366808", +>>>>>>> 9f6535472d (feat: update billed amount in PO and PR) "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 45b24826400..23459458163 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -193,6 +193,7 @@ class PurchaseInvoice(BuyingController): supplied_items: DF.Table[PurchaseReceiptItemSupplied] supplier: DF.Link supplier_address: DF.Link | None + supplier_group: DF.Link | None supplier_name: DF.Data | None supplier_warehouse: DF.Link | None tax_category: DF.Link | None @@ -214,6 +215,8 @@ class PurchaseInvoice(BuyingController): total_qty: DF.Float total_taxes_and_charges: DF.Currency unrealized_profit_loss_account: DF.Link | None + update_billed_amount_in_purchase_order: DF.Check + update_billed_amount_in_purchase_receipt: DF.Check update_stock: DF.Check use_company_roundoff_cost_center: DF.Check use_transaction_date_exchange_rate: DF.Check @@ -679,6 +682,11 @@ class PurchaseInvoice(BuyingController): super(PurchaseInvoice, self).on_submit() self.check_prev_docstatus() + + if self.is_return and not self.update_billed_amount_in_purchase_order: + # NOTE status updating bypassed for is_return + self.status_updater = [] + self.update_status_updater_args() self.update_prevdoc_status() @@ -1426,6 +1434,10 @@ class PurchaseInvoice(BuyingController): self.check_on_hold_or_closed_status() + if self.is_return and not self.update_billed_amount_in_purchase_order: + # NOTE status updating bypassed for is_return + self.status_updater = [] + self.update_status_updater_args() self.update_prevdoc_status() @@ -1520,6 +1532,9 @@ class PurchaseInvoice(BuyingController): frappe.throw(_("Supplier Invoice No exists in Purchase Invoice {0}").format(pi)) def update_billing_status_in_pr(self, update_modified=True): + if self.is_return and not self.update_billed_amount_in_purchase_receipt: + return + updated_pr = [] po_details = [] From bac2f663443e14efc2c472d5e9400fe3d5113cf4 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 25 Feb 2024 19:40:28 +0530 Subject: [PATCH 2/7] test: po billed amount against debit note (cherry picked from commit 81dbfe189e66f48cee4a37c54544aeaa4f0b3c2e) # Conflicts: # erpnext/buying/doctype/purchase_order/test_purchase_order.py --- .../purchase_order/test_purchase_order.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 1216fb92658..ea722b72dc0 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -1037,6 +1037,68 @@ class TestPurchaseOrder(FrappeTestCase): self.assertTrue(frappe.db.get_value("Subcontracting Order", {"purchase_order": po.name})) +<<<<<<< HEAD +======= + def test_purchase_order_advance_payment_status(self): + from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry + from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request + + po = create_purchase_order() + self.assertEqual( + frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated" + ) + + pr = make_payment_request(dt=po.doctype, dn=po.name, submit_doc=True, return_doc=True) + self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated") + + pe = get_payment_entry(po.doctype, po.name).save().submit() + self.assertEqual( + frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Fully Paid" + ) + + pe.reload() + pe.cancel() + self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated") + + pr.reload() + pr.cancel() + self.assertEqual( + frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated" + ) + + def test_po_billed_amount_against_return_entry(self): + from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_debit_note + + # Create a Purchase Order and Fully Bill it + po = create_purchase_order() + pi = make_pi_from_po(po.name) + pi.insert() + pi.submit() + + # Debit Note - 50% Qty & enable updating PO billed amount + pi_return = make_debit_note(pi.name) + pi_return.items[0].qty = -5 + pi_return.update_billed_amount_in_purchase_order = 1 + pi_return.submit() + + # Check if the billed amount reduced + po.reload() + self.assertEqual(po.per_billed, 50) + + pi_return.reload() + pi_return.cancel() + + # Debit Note - 50% Qty & disable updating PO billed amount + pi_return = make_debit_note(pi.name) + pi_return.items[0].qty = -5 + pi_return.update_billed_amount_in_purchase_order = 0 + pi_return.submit() + + # Check if the billed amount stayed the same + po.reload() + self.assertEqual(po.per_billed, 100) + +>>>>>>> 81dbfe189e (test: po billed amount against debit note) def prepare_data_for_internal_transfer(): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier From e67d579ac4e31f8e9eaf600653cf6fba65b1479c Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 25 Feb 2024 20:03:33 +0530 Subject: [PATCH 3/7] test: pr billed amount against debit note (cherry picked from commit 6d408448943c47f0a3632d5772a0786b14c75a59) --- .../purchase_receipt/test_purchase_receipt.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 7b6cea5990b..053cb1d98bd 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -2405,6 +2405,41 @@ class TestPurchaseReceipt(FrappeTestCase): "Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle", 1 ) + def test_pr_billed_amount_against_return_entry(self): + from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_debit_note + from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( + make_purchase_invoice as make_pi_from_pr, + ) + + # Create a Purchase Receipt and Fully Bill it + pr = make_purchase_receipt(qty=10) + pi = make_pi_from_pr(pr.name) + pi.insert() + pi.submit() + + # Debit Note - 50% Qty & enable updating PR billed amount + pi_return = make_debit_note(pi.name) + pi_return.items[0].qty = -5 + pi_return.update_billed_amount_in_purchase_receipt = 1 + pi_return.submit() + + # Check if the billed amount reduced + pr.reload() + self.assertEqual(pr.per_billed, 50) + + pi_return.reload() + pi_return.cancel() + + # Debit Note - 50% Qty & disable updating PR billed amount + pi_return = make_debit_note(pi.name) + pi_return.items[0].qty = -5 + pi_return.update_billed_amount_in_purchase_receipt = 0 + pi_return.submit() + + # Check if the billed amount stayed the same + pr.reload() + self.assertEqual(pr.per_billed, 100) + def prepare_data_for_internal_transfer(): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier From eadea0207c9841e120c763538982be7aa81ee79e Mon Sep 17 00:00:00 2001 From: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:13:49 +0530 Subject: [PATCH 4/7] chore: resolve conflicts --- .../doctype/purchase_invoice/purchase_invoice.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 70fe93b011f..a163640f25e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -1628,11 +1628,7 @@ "idx": 204, "is_submittable": 1, "links": [], -<<<<<<< HEAD - "modified": "2023-11-29 15:35:44.697496", -======= - "modified": "2024-02-25 11:20:28.366808", ->>>>>>> 9f6535472d (feat: update billed amount in PO and PR) + "modified": "2024-02-25 11:20:28.366808" "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", @@ -1695,4 +1691,4 @@ "timeline_field": "supplier", "title_field": "title", "track_changes": 1 -} \ No newline at end of file +} From 99d1f1d67b1fe3df7a168e11f26d7e13e0c59cc9 Mon Sep 17 00:00:00 2001 From: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:15:49 +0530 Subject: [PATCH 5/7] chore: resolve conflicts --- .../purchase_order/test_purchase_order.py | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index ea722b72dc0..c48e87b0d46 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -1037,35 +1037,6 @@ class TestPurchaseOrder(FrappeTestCase): self.assertTrue(frappe.db.get_value("Subcontracting Order", {"purchase_order": po.name})) -<<<<<<< HEAD -======= - def test_purchase_order_advance_payment_status(self): - from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry - from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request - - po = create_purchase_order() - self.assertEqual( - frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated" - ) - - pr = make_payment_request(dt=po.doctype, dn=po.name, submit_doc=True, return_doc=True) - self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated") - - pe = get_payment_entry(po.doctype, po.name).save().submit() - self.assertEqual( - frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Fully Paid" - ) - - pe.reload() - pe.cancel() - self.assertEqual(frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Initiated") - - pr.reload() - pr.cancel() - self.assertEqual( - frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated" - ) - def test_po_billed_amount_against_return_entry(self): from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_debit_note @@ -1098,7 +1069,6 @@ class TestPurchaseOrder(FrappeTestCase): po.reload() self.assertEqual(po.per_billed, 100) ->>>>>>> 81dbfe189e (test: po billed amount against debit note) def prepare_data_for_internal_transfer(): from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier From 48992cd205dc5a111ad844d28a10fe0bd3a14994 Mon Sep 17 00:00:00 2001 From: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:18:27 +0530 Subject: [PATCH 6/7] chore: resolve conflicts --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 23459458163..2b6c6b64377 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -193,7 +193,6 @@ class PurchaseInvoice(BuyingController): supplied_items: DF.Table[PurchaseReceiptItemSupplied] supplier: DF.Link supplier_address: DF.Link | None - supplier_group: DF.Link | None supplier_name: DF.Data | None supplier_warehouse: DF.Link | None tax_category: DF.Link | None From 87f36ce425707446e88c8865cff2b7e8fbbe2309 Mon Sep 17 00:00:00 2001 From: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:24:14 +0530 Subject: [PATCH 7/7] chore: fix typo --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index a163640f25e..313a314ee26 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -1628,7 +1628,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2024-02-25 11:20:28.366808" + "modified": "2024-02-25 11:20:28.366808", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice",