mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
refactor: dynamic DB field types
(cherry picked from commit 9d0ebe3427)
This commit is contained in:
@@ -6,6 +6,7 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, qb, query_builder, scrub
|
from frappe import _, qb, query_builder, scrub
|
||||||
|
from frappe.database.schema import get_definition
|
||||||
from frappe.desk.reportview import build_match_conditions
|
from frappe.desk.reportview import build_match_conditions
|
||||||
from frappe.query_builder import Criterion
|
from frappe.query_builder import Criterion
|
||||||
from frappe.query_builder.functions import Date, Substring, Sum
|
from frappe.query_builder.functions import Date, Substring, Sum
|
||||||
@@ -1335,53 +1336,56 @@ class InitSQLProceduresForAR:
|
|||||||
Initialize SQL Procedures, Functions and Temporary tables to build Receivable / Payable report
|
Initialize SQL Procedures, Functions and Temporary tables to build Receivable / Payable report
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_varchar_type = get_definition("Data")
|
||||||
|
_currency_type = get_definition("Currency")
|
||||||
# Temporary Tables
|
# Temporary Tables
|
||||||
_voucher_balance_name = "_ar_voucher_balance"
|
_voucher_balance_name = "_ar_voucher_balance"
|
||||||
_voucher_balance_definition = f"""
|
_voucher_balance_definition = f"""
|
||||||
create temporary table `{_voucher_balance_name}`(
|
create temporary table `{_voucher_balance_name}`(
|
||||||
name varchar(224),
|
name {_varchar_type},
|
||||||
voucher_type varchar(140),
|
voucher_type {_varchar_type},
|
||||||
voucher_no varchar(140),
|
voucher_no {_varchar_type},
|
||||||
party varchar(140),
|
party {_varchar_type},
|
||||||
party_account varchar(140),
|
party_account {_varchar_type},
|
||||||
posting_date date,
|
posting_date date,
|
||||||
account_currency varchar(140),
|
account_currency {_varchar_type},
|
||||||
cost_center varchar(140),
|
cost_center {_varchar_type},
|
||||||
invoiced decimal(21,9),
|
invoiced {_currency_type},
|
||||||
paid decimal(21,9),
|
paid {_currency_type},
|
||||||
credit_note decimal(21,9),
|
credit_note {_currency_type},
|
||||||
invoiced_in_account_currency decimal(21,9),
|
invoiced_in_account_currency {_currency_type},
|
||||||
paid_in_account_currency decimal(21,9),
|
paid_in_account_currency {_currency_type},
|
||||||
credit_note_in_account_currency decimal(21,9)) engine=memory;
|
credit_note_in_account_currency {_currency_type}) engine=memory;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_row_def_table_name = "_ar_ple_row"
|
_row_def_table_name = "_ar_ple_row"
|
||||||
_row_def_table_definition = f"""
|
_row_def_table_definition = f"""
|
||||||
create temporary table `{_row_def_table_name}`(
|
create temporary table `{_row_def_table_name}`(
|
||||||
name varchar(224),
|
name {_varchar_type},
|
||||||
account varchar(140),
|
account {_varchar_type},
|
||||||
voucher_type varchar(140),
|
voucher_type {_varchar_type},
|
||||||
voucher_no varchar(140),
|
voucher_no {_varchar_type},
|
||||||
against_voucher_type varchar(140),
|
against_voucher_type {_varchar_type},
|
||||||
against_voucher_no varchar(140),
|
against_voucher_no {_varchar_type},
|
||||||
party_type varchar(140),
|
party_type {_varchar_type},
|
||||||
cost_center varchar(140),
|
cost_center {_varchar_type},
|
||||||
party varchar(140),
|
party {_varchar_type},
|
||||||
posting_date date,
|
posting_date date,
|
||||||
due_date date,
|
due_date date,
|
||||||
account_currency varchar(140),
|
account_currency {_varchar_type},
|
||||||
amount decimal(21,9),
|
amount {_currency_type},
|
||||||
amount_in_account_currency decimal(21,9)) engine=memory;
|
amount_in_account_currency {_currency_type}) engine=memory;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Function
|
# Function
|
||||||
genkey_function_name = "ar_genkey"
|
genkey_function_name = "ar_genkey"
|
||||||
genkey_function_sql = f"""
|
genkey_function_sql = f"""
|
||||||
create function `{genkey_function_name}`(rec row type of `{_row_def_table_name}`, allocate bool) returns char(224)
|
create function `{genkey_function_name}`(rec row type of `{_row_def_table_name}`, allocate bool) returns char(40)
|
||||||
begin
|
begin
|
||||||
if allocate then
|
if allocate then
|
||||||
return sha2(concat_ws(',', rec.account, rec.against_voucher_type, rec.against_voucher_no, rec.party), 224);
|
return sha1(concat_ws(',', rec.account, rec.against_voucher_type, rec.against_voucher_no, rec.party));
|
||||||
else
|
else
|
||||||
return sha2(concat_ws(',', rec.account, rec.voucher_type, rec.voucher_no, rec.party), 224);
|
return sha1(concat_ws(',', rec.account, rec.voucher_type, rec.voucher_no, rec.party));
|
||||||
end if;
|
end if;
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
@@ -1402,12 +1406,12 @@ class InitSQLProceduresForAR:
|
|||||||
allocate_procedure_sql = f"""
|
allocate_procedure_sql = f"""
|
||||||
create procedure ar_allocate_to_tmp_table(in ple row type of `{_row_def_table_name}`)
|
create procedure ar_allocate_to_tmp_table(in ple row type of `{_row_def_table_name}`)
|
||||||
begin
|
begin
|
||||||
declare invoiced decimal(21,9) default 0;
|
declare invoiced {_currency_type} default 0;
|
||||||
declare invoiced_in_account_currency decimal(21,9) default 0;
|
declare invoiced_in_account_currency {_currency_type} default 0;
|
||||||
declare paid decimal(21,9) default 0;
|
declare paid {_currency_type} default 0;
|
||||||
declare paid_in_account_currency decimal(21,9) default 0;
|
declare paid_in_account_currency {_currency_type} default 0;
|
||||||
declare credit_note decimal(21,9) default 0;
|
declare credit_note {_currency_type} default 0;
|
||||||
declare credit_note_in_account_currency decimal(21,9) default 0;
|
declare credit_note_in_account_currency {_currency_type} default 0;
|
||||||
|
|
||||||
|
|
||||||
if ple.amount > 0 then
|
if ple.amount > 0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user