mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
refactor: utility to drop existing procedures and include cost center
This commit is contained in:
@@ -26,9 +26,20 @@ frappe.ui.form.on("Accounts Settings", {
|
|||||||
add_taxes_from_taxes_and_charges_template(frm) {
|
add_taxes_from_taxes_and_charges_template(frm) {
|
||||||
toggle_tax_settings(frm, "add_taxes_from_taxes_and_charges_template");
|
toggle_tax_settings(frm, "add_taxes_from_taxes_and_charges_template");
|
||||||
},
|
},
|
||||||
|
|
||||||
add_taxes_from_item_tax_template(frm) {
|
add_taxes_from_item_tax_template(frm) {
|
||||||
toggle_tax_settings(frm, "add_taxes_from_item_tax_template");
|
toggle_tax_settings(frm, "add_taxes_from_item_tax_template");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
drop_ar_procedures: function (frm) {
|
||||||
|
frm.call({
|
||||||
|
doc: frm.doc,
|
||||||
|
method: "drop_ar_sql_procedures",
|
||||||
|
callback: function (r) {
|
||||||
|
frappe.show_alert(__("Procedures dropped"), 5);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggle_tax_settings(frm, field_name) {
|
function toggle_tax_settings(frm, field_name) {
|
||||||
|
|||||||
@@ -90,6 +90,8 @@
|
|||||||
"receivable_payable_remarks_length",
|
"receivable_payable_remarks_length",
|
||||||
"accounts_receivable_payable_tuning_section",
|
"accounts_receivable_payable_tuning_section",
|
||||||
"receivable_payable_fetch_method",
|
"receivable_payable_fetch_method",
|
||||||
|
"column_break_ntmi",
|
||||||
|
"drop_ar_procedures",
|
||||||
"legacy_section",
|
"legacy_section",
|
||||||
"ignore_is_opening_check_for_reporting",
|
"ignore_is_opening_check_for_reporting",
|
||||||
"payment_request_settings",
|
"payment_request_settings",
|
||||||
@@ -631,6 +633,17 @@
|
|||||||
"fieldname": "add_taxes_from_taxes_and_charges_template",
|
"fieldname": "add_taxes_from_taxes_and_charges_template",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Automatically Add Taxes from Taxes and Charges Template"
|
"label": "Automatically Add Taxes from Taxes and Charges Template"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_ntmi",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.receivable_payable_fetch_method == \"Raw SQL\"",
|
||||||
|
"description": "Drops existing SQL Procedures and Function setup by Accounts Receivable report",
|
||||||
|
"fieldname": "drop_ar_procedures",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"label": "Drop Procedures"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"grid_page_length": 50,
|
"grid_page_length": 50,
|
||||||
|
|||||||
@@ -154,3 +154,11 @@ class AccountsSettings(Document):
|
|||||||
),
|
),
|
||||||
title=_("Auto Tax Settings Error"),
|
title=_("Auto Tax Settings Error"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
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}")
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ class ReceivablePayableReport:
|
|||||||
party_account `account`,
|
party_account `account`,
|
||||||
posting_date,
|
posting_date,
|
||||||
account_currency,
|
account_currency,
|
||||||
|
cost_center,
|
||||||
sum(invoiced) `invoiced`,
|
sum(invoiced) `invoiced`,
|
||||||
sum(paid) `paid`,
|
sum(paid) `paid`,
|
||||||
sum(credit_note) `credit_note`,
|
sum(credit_note) `credit_note`,
|
||||||
@@ -388,6 +389,7 @@ class ReceivablePayableReport:
|
|||||||
"paid_in_account_currency",
|
"paid_in_account_currency",
|
||||||
"credit_note_in_account_currency",
|
"credit_note_in_account_currency",
|
||||||
"outstanding_in_account_currency",
|
"outstanding_in_account_currency",
|
||||||
|
"cost_center",
|
||||||
]:
|
]:
|
||||||
_d[field] = x.get(field)
|
_d[field] = x.get(field)
|
||||||
|
|
||||||
@@ -1346,14 +1348,13 @@ class InitSQLProceduresForAR:
|
|||||||
party_account varchar(140),
|
party_account varchar(140),
|
||||||
posting_date date,
|
posting_date date,
|
||||||
account_currency varchar(140),
|
account_currency varchar(140),
|
||||||
|
cost_center varchar(140),
|
||||||
invoiced decimal(21,9),
|
invoiced decimal(21,9),
|
||||||
paid decimal(21,9),
|
paid decimal(21,9),
|
||||||
credit_note decimal(21,9),
|
credit_note decimal(21,9),
|
||||||
outstanding decimal(21,9),
|
|
||||||
invoiced_in_account_currency decimal(21,9),
|
invoiced_in_account_currency decimal(21,9),
|
||||||
paid_in_account_currency decimal(21,9),
|
paid_in_account_currency decimal(21,9),
|
||||||
credit_note_in_account_currency decimal(21,9),
|
credit_note_in_account_currency decimal(21,9)) engine=memory;
|
||||||
outstanding_in_account_currency decimal(21,9)) engine=memory;
|
|
||||||
"""
|
"""
|
||||||
_row_def_table_name = "_ple_row"
|
_row_def_table_name = "_ple_row"
|
||||||
_row_def_table_definition = f"""
|
_row_def_table_definition = f"""
|
||||||
@@ -1394,7 +1395,7 @@ class InitSQLProceduresForAR:
|
|||||||
begin
|
begin
|
||||||
if not exists (select name from `{_voucher_balance_name}` where name = genkey(ple, false))
|
if not exists (select name from `{_voucher_balance_name}` where name = genkey(ple, false))
|
||||||
then
|
then
|
||||||
insert into `{_voucher_balance_name}` values (genkey(ple, false), ple.voucher_type, ple.voucher_no, ple.party, ple.account, ple.posting_date, ple.account_currency, 0, 0, 0, 0, 0, 0, 0, 0);
|
insert into `{_voucher_balance_name}` values (genkey(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);
|
||||||
end if;
|
end if;
|
||||||
end;
|
end;
|
||||||
"""
|
"""
|
||||||
@@ -1436,17 +1437,21 @@ class InitSQLProceduresForAR:
|
|||||||
|
|
||||||
end if;
|
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, 0, invoiced_in_account_currency, paid_in_account_currency, 0, 0);
|
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);
|
||||||
end;
|
end;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def get_existing_procedures(self):
|
||||||
existing_procedures = frappe.db.sql(
|
procedures = frappe.db.sql(
|
||||||
f"select routine_name from information_schema.routines where routine_type in ('FUNCTION','PROCEDURE') and routine_schema='{frappe.conf.db_name}';"
|
f"select routine_name from information_schema.routines where routine_type in ('FUNCTION','PROCEDURE') and routine_schema='{frappe.conf.db_name}';"
|
||||||
)
|
)
|
||||||
if existing_procedures:
|
if procedures:
|
||||||
# normalize
|
# normalize
|
||||||
existing_procedures = [x[0] for x in existing_procedures]
|
procedures = [x[0] for x in procedures]
|
||||||
|
return procedures
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
existing_procedures = self.get_existing_procedures()
|
||||||
|
|
||||||
if self.genkey_function_name not in existing_procedures:
|
if self.genkey_function_name not in existing_procedures:
|
||||||
frappe.db.sql(self.genkey_function_sql)
|
frappe.db.sql(self.genkey_function_sql)
|
||||||
|
|||||||
Reference in New Issue
Block a user