From faa3260fe3c2aefa2277a9ac42a38d5512023bd5 Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Wed, 11 May 2022 16:49:28 +0530 Subject: [PATCH 1/2] fix: per_billed for return DN (#30868) * fix: per_billed for return DN * chore: move patch from v14 to v13 (cherry picked from commit 1a70701eca30fd1d1faeb24e8f5d2bf5f775f2d0) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 7 ++++ .../set_per_billed_in_return_delivery_note.py | 29 ++++++++++++++ .../delivery_note/test_delivery_note.py | 38 +++++++++++++++++++ .../delivery_note_item.json | 6 ++- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v13_0/set_per_billed_in_return_delivery_note.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5d95f824dce3..820cf58ce398 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -359,8 +359,15 @@ erpnext.patches.v13_0.enable_ksa_vat_docs #1 erpnext.patches.v13_0.create_gst_custom_fields_in_quotation erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype +<<<<<<< HEAD erpnext.patches.v13_0.set_return_against_in_pos_invoice_references erpnext.patches.v13_0.copy_custom_field_filters_to_website_item erpnext.patches.v13_0.set_available_for_use_date_if_missing erpnext.patches.v13_0.education_deprecation_warning erpnext.patches.v13_0.create_accounting_dimensions_in_orders +======= +erpnext.patches.v14_0.discount_accounting_separation +erpnext.patches.v14_0.delete_employee_transfer_property_doctype +erpnext.patches.v13_0.create_accounting_dimensions_in_orders +erpnext.patches.v13_0.set_per_billed_in_return_delivery_note +>>>>>>> 1a70701eca (fix: per_billed for return DN (#30868)) diff --git a/erpnext/patches/v13_0/set_per_billed_in_return_delivery_note.py b/erpnext/patches/v13_0/set_per_billed_in_return_delivery_note.py new file mode 100644 index 000000000000..a4d701244925 --- /dev/null +++ b/erpnext/patches/v13_0/set_per_billed_in_return_delivery_note.py @@ -0,0 +1,29 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe + + +def execute(): + dn = frappe.qb.DocType("Delivery Note") + dn_item = frappe.qb.DocType("Delivery Note Item") + + dn_list = ( + frappe.qb.from_(dn) + .inner_join(dn_item) + .on(dn.name == dn_item.parent) + .select(dn.name) + .where(dn.docstatus == 1) + .where(dn.is_return == 1) + .where(dn.per_billed < 100) + .where(dn_item.returned_qty > 0) + .run(as_dict=True) + ) + + frappe.qb.update(dn_item).inner_join(dn).on(dn.name == dn_item.parent).set( + dn_item.returned_qty, 0 + ).where(dn.is_return == 1).where(dn_item.returned_qty > 0).run() + + for d in dn_list: + dn_doc = frappe.get_doc("Delivery Note", d.get("name")) + dn_doc.run_method("update_billing_status") diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index f97e7ca9c680..0738bfbd8fc0 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -962,6 +962,44 @@ def test_payment_terms_are_fetched_when_creating_sales_invoice(self): automatically_fetch_payment_terms(enable=0) + def test_returned_qty_in_return_dn(self): + # SO ---> SI ---> DN + # | + # |---> DN(Partial Sales Return) ---> SI(Credit Note) + # | + # |---> DN(Partial Sales Return) ---> SI(Credit Note) + + from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note + from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice + + so = make_sales_order(qty=10) + si = make_sales_invoice(so.name) + si.insert() + si.submit() + dn = make_delivery_note(si.name) + dn.insert() + dn.submit() + self.assertEqual(dn.items[0].returned_qty, 0) + self.assertEqual(dn.per_billed, 100) + + from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice + + dn1 = create_delivery_note(is_return=1, return_against=dn.name, qty=-3) + si1 = make_sales_invoice(dn1.name) + si1.insert() + si1.submit() + dn1.reload() + self.assertEqual(dn1.items[0].returned_qty, 0) + self.assertEqual(dn1.per_billed, 100) + + dn2 = create_delivery_note(is_return=1, return_against=dn.name, qty=-4) + si2 = make_sales_invoice(dn2.name) + si2.insert() + si2.submit() + dn2.reload() + self.assertEqual(dn2.items[0].returned_qty, 0) + self.assertEqual(dn2.per_billed, 100) + def create_delivery_note(**args): dn = frappe.new_doc("Delivery Note") diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index e2eb2a4bbb27..2d7abc8a0d68 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -737,7 +737,9 @@ "depends_on": "returned_qty", "fieldname": "returned_qty", "fieldtype": "Float", - "label": "Returned Qty in Stock UOM" + "label": "Returned Qty in Stock UOM", + "no_copy": 1, + "read_only": 1 }, { "fieldname": "incoming_rate", @@ -778,7 +780,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-03-31 18:36:24.671913", + "modified": "2022-05-02 12:09:39.610075", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", From 28cd089538420706beccd2e8403b2c4507618658 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 11 May 2022 19:41:35 +0530 Subject: [PATCH 2/2] chore: conflicts --- erpnext/patches.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 820cf58ce398..94e7bfc16d25 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -359,15 +359,9 @@ erpnext.patches.v13_0.enable_ksa_vat_docs #1 erpnext.patches.v13_0.create_gst_custom_fields_in_quotation erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances erpnext.patches.v13_0.change_default_item_manufacturer_fieldtype -<<<<<<< HEAD erpnext.patches.v13_0.set_return_against_in_pos_invoice_references erpnext.patches.v13_0.copy_custom_field_filters_to_website_item erpnext.patches.v13_0.set_available_for_use_date_if_missing erpnext.patches.v13_0.education_deprecation_warning erpnext.patches.v13_0.create_accounting_dimensions_in_orders -======= -erpnext.patches.v14_0.discount_accounting_separation -erpnext.patches.v14_0.delete_employee_transfer_property_doctype -erpnext.patches.v13_0.create_accounting_dimensions_in_orders erpnext.patches.v13_0.set_per_billed_in_return_delivery_note ->>>>>>> 1a70701eca (fix: per_billed for return DN (#30868))