From a1525d9b8e45c6b71f1a9e490af82e2e84b09c25 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 7 Oct 2024 21:43:49 +0530 Subject: [PATCH 1/3] chore: Allow apps to extend voucher subtypes --- erpnext/controllers/accounts_controller.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 30ebc1794fe..328b2b76346 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1068,6 +1068,11 @@ class AccountsController(TransactionBase): "Stock Entry": "stock_entry_type", "Asset Capitalization": "entry_type", } + + extended_voucher_types = frappe.get_hooks("voucher_subtypes") or {} + for key, value in extended_voucher_types.items(): + voucher_subtypes[key] = value[0] + if self.doctype in voucher_subtypes: return self.get(voucher_subtypes[self.doctype]) elif self.doctype == "Purchase Receipt" and self.is_return: @@ -1078,6 +1083,7 @@ class AccountsController(TransactionBase): return "Credit Note" elif (self.doctype == "Purchase Invoice" and self.is_return) or self.doctype == "Sales Invoice": return "Debit Note" + return self.doctype def get_value_in_transaction_currency(self, account_currency, gl_dict, field): From 8a1e38a43b8f47ef388a5d7f57b8e84212bbe2b3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 7 Oct 2024 22:14:10 +0530 Subject: [PATCH 2/3] chore: Allow apps to extend voucher subtypes --- erpnext/controllers/accounts_controller.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 328b2b76346..9f2190560c5 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1069,9 +1069,11 @@ class AccountsController(TransactionBase): "Asset Capitalization": "entry_type", } - extended_voucher_types = frappe.get_hooks("voucher_subtypes") or {} - for key, value in extended_voucher_types.items(): - voucher_subtypes[key] = value[0] + for method_name in frappe.get_hooks("voucher_subtypes"): + voucher_subtype = frappe.get_attr(method_name)(self) + + if voucher_subtype: + return voucher_subtype if self.doctype in voucher_subtypes: return self.get(voucher_subtypes[self.doctype]) From ca8820b5660f371ec9bd05ac6afe104c55168b18 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 7 Oct 2024 23:32:50 +0530 Subject: [PATCH 3/3] chore: Allow apps to extend voucher subtypes --- erpnext/controllers/accounts_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 9f2190560c5..56f462a8d6b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1072,8 +1072,8 @@ class AccountsController(TransactionBase): for method_name in frappe.get_hooks("voucher_subtypes"): voucher_subtype = frappe.get_attr(method_name)(self) - if voucher_subtype: - return voucher_subtype + if voucher_subtype: + return voucher_subtype if self.doctype in voucher_subtypes: return self.get(voucher_subtypes[self.doctype])