-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43273 from ljain112/fix-voucher-types
fix: improved the conditions for determining voucher subtypes
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) |