diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index dac6c453f546f6cf43eed6e0701c725668e4eee4..d06ca743976f0f39d34750e040f62fbd4ebfdb58 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -151,6 +151,5 @@ class AccountsSettings(Document): def drop_ar_sql_procedures(self): from erpnext.accounts.report.accounts_receivable.accounts_receivable import InitSQLProceduresForAR - frappe.db.sql(f"drop function if exists {InitSQLProceduresForAR.genkey_function_name}") frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.init_procedure_name}") frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.allocate_procedure_name}") diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index fc19ae35fc4333505bdc266abcbf2694d00f0b70..f76164b6beefd5546e1be4040420e12d07985760 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -1385,27 +1385,14 @@ class InitSQLProceduresForAR: amount_in_account_currency {_currency_type}) engine=memory; """ - # Function - genkey_function_name = "ar_genkey" - genkey_function_sql = f""" - create function `{genkey_function_name}`(rec row type of `{_row_def_table_name}`, allocate bool) returns char(40) - begin - if allocate then - return sha1(concat_ws(',', rec.account, rec.against_voucher_type, rec.against_voucher_no, rec.party)); - else - return sha1(concat_ws(',', rec.account, rec.voucher_type, rec.voucher_no, rec.party)); - end if; - end - """ - # Procedures init_procedure_name = "ar_init_tmp_table" init_procedure_sql = f""" create procedure ar_init_tmp_table(in ple row type of `{_row_def_table_name}`) begin - if not exists (select name from `{_voucher_balance_name}` where name = `{genkey_function_name}`(ple, false)) + if not exists (select name from `{_voucher_balance_name}` where name = sha1(concat_ws(',', ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party))) then - insert into `{_voucher_balance_name}` values (`{genkey_function_name}`(ple, false), ple.voucher_type, ple.voucher_no, ple.party, ple.account, ple.posting_date, ple.account_currency, ple.cost_center, 0, 0, 0, 0, 0, 0); + insert into `{_voucher_balance_name}` values (sha1(concat_ws(',', ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party)), ple.voucher_type, ple.voucher_no, ple.party, ple.account, ple.posting_date, ple.account_currency, ple.cost_center, 0, 0, 0, 0, 0, 0); end if; end; """ @@ -1447,16 +1434,13 @@ class InitSQLProceduresForAR: end if; - insert into `{_voucher_balance_name}` values (`{genkey_function_name}`(ple, true), ple.against_voucher_type, ple.against_voucher_no, ple.party, ple.account, ple.posting_date, ple.account_currency,'', invoiced, paid, 0, invoiced_in_account_currency, paid_in_account_currency, 0); + insert into `{_voucher_balance_name}` values (sha1(concat_ws(',', ple.account, ple.voucher_type, ple.voucher_no, ple.party)), ple.against_voucher_type, ple.against_voucher_no, ple.party, ple.account, ple.posting_date, ple.account_currency,'', invoiced, paid, 0, invoiced_in_account_currency, paid_in_account_currency, 0); end; """ def __init__(self): existing_procedures = frappe.db.get_routines() - if self.genkey_function_name not in existing_procedures: - frappe.db.sql(self.genkey_function_sql) - if self.init_procedure_name not in existing_procedures: frappe.db.sql(self.init_procedure_sql)