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: improved the conditions for determining voucher subtypes #43273

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,11 @@ def get_voucher_subtype(self):
return "Purchase Return"
elif self.doctype == "Delivery Note" and self.is_return:
return "Sales Return"
elif (self.doctype == "Sales Invoice" and self.is_return) or self.doctype == "Purchase Invoice":
elif self.doctype == "Sales Invoice" and self.is_return:
return "Credit Note"
elif (self.doctype == "Purchase Invoice" and self.is_return) or self.doctype == "Sales Invoice":
elif self.doctype == "Sales Invoice" and self.is_debit_note:
return "Debit Note"
elif self.doctype == "Purchase Invoice" and self.is_return:
return "Debit Note"
return self.doctype

Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,4 @@ erpnext.patches.v15_0.set_standard_stock_entry_type
erpnext.patches.v15_0.set_difference_amount_in_asset_value_adjustment
erpnext.patches.v15_0.link_purchase_item_to_asset_doc
erpnext.patches.v15_0.migrate_to_utm_analytics
erpnext.patches.v15_0.update_sub_voucher_type_in_gl_entries
57 changes: 57 additions & 0 deletions erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import frappe


def execute():
update_purchase_invoices()
update_sales_invoices()
update_sales_debit_notes()


def update_purchase_invoices():
invoices = frappe.get_all(
"Purchase Invoice",
filters={"docstatus": 1, "is_return": 0},
pluck="name",
)

if not invoices:
return

update_gl_entry(doctype="Purchase Invoice", invoices=invoices, value="Purchase Invoice")


def update_sales_invoices():
invoices = frappe.get_all(
"Sales Invoice",
filters={"docstatus": 1, "is_return": 0, "is_debit_note": 0},
pluck="name",
)
if not invoices:
return

update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Sales Invoice")


def update_sales_debit_notes():
invoices = frappe.get_all(
"Sales Invoice",
filters={"docstatus": 1, "is_debit_note": 1},
pluck="name",
)

if not invoices:
return

update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Debit Note")


def update_gl_entry(doctype, invoices, value):
gl_entry = frappe.qb.DocType("GL Entry")
(
frappe.qb.update(gl_entry)
.set("voucher_subtype", value)
.where(gl_entry.voucher_subtype.isnotnull())
.where(gl_entry.voucher_no.isin(invoices))
.where(gl_entry.voucher_type == doctype)
.run()
)
Loading