Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: per_billed for return DN (backport #30868) #30971

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,4 @@ 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.v13_0.set_per_billed_in_return_delivery_note
29 changes: 29 additions & 0 deletions erpnext/patches/v13_0/set_per_billed_in_return_delivery_note.py
Original file line number Diff line number Diff line change
@@ -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")
38 changes: 38 additions & 0 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down