Merge pull request #36684 from deepeshgarg007/gl_transaction_currency

feat: Transaction currency columns in GL report
This commit is contained in:
Deepesh Garg 2023-08-17 16:06:23 +05:30 committed by GitHub
commit c70abaa43a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 4 deletions

View File

@ -32,7 +32,11 @@
"finance_book", "finance_book",
"to_rename", "to_rename",
"due_date", "due_date",
"is_cancelled" "is_cancelled",
"transaction_currency",
"debit_in_transaction_currency",
"credit_in_transaction_currency",
"transaction_exchange_rate"
], ],
"fields": [ "fields": [
{ {
@ -253,15 +257,40 @@
"fieldname": "is_cancelled", "fieldname": "is_cancelled",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Is Cancelled" "label": "Is Cancelled"
},
{
"fieldname": "transaction_currency",
"fieldtype": "Link",
"label": "Transaction Currency",
"options": "Currency"
},
{
"fieldname": "transaction_exchange_rate",
"fieldtype": "Float",
"label": "Transaction Exchange Rate"
},
{
"fieldname": "debit_in_transaction_currency",
"fieldtype": "Currency",
"label": "Debit Amount in Transaction Currency",
"options": "transaction_currency"
},
{
"fieldname": "credit_in_transaction_currency",
"fieldtype": "Currency",
"label": "Credit Amount in Transaction Currency",
"options": "transaction_currency"
} }
], ],
"icon": "fa fa-list", "icon": "fa fa-list",
"idx": 1, "idx": 1,
"in_create": 1, "in_create": 1,
"modified": "2020-04-07 16:22:33.766994", "links": [],
"modified": "2023-08-16 21:38:44.072267",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "GL Entry", "name": "GL Entry",
"naming_rule": "Expression (old style)",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
@ -290,5 +319,6 @@
"quick_entry": 1, "quick_entry": 1,
"search_fields": "voucher_no,account,posting_date,against_voucher", "search_fields": "voucher_no,account,posting_date,against_voucher",
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC" "sort_order": "DESC",
"states": []
} }

View File

@ -188,6 +188,11 @@ frappe.query_reports["General Ledger"] = {
"fieldname": "show_net_values_in_party_account", "fieldname": "show_net_values_in_party_account",
"label": __("Show Net Values in Party Account"), "label": __("Show Net Values in Party Account"),
"fieldtype": "Check" "fieldtype": "Check"
},
{
"fieldname": "add_values_in_transaction_currency",
"label": __("Add Columns in Transaction Currency"),
"fieldtype": "Check"
} }
] ]
} }

View File

@ -182,12 +182,18 @@ def get_gl_entries(filters, accounting_dimensions):
if accounting_dimensions: if accounting_dimensions:
dimension_fields = ", ".join(accounting_dimensions) + "," dimension_fields = ", ".join(accounting_dimensions) + ","
transaction_currency_fields = ""
if filters.get("add_values_in_transaction_currency"):
transaction_currency_fields = (
"debit_in_transaction_currency, credit_in_transaction_currency, transaction_currency,"
)
gl_entries = frappe.db.sql( gl_entries = frappe.db.sql(
""" """
select select
name as gl_entry, posting_date, account, party_type, party, name as gl_entry, posting_date, account, party_type, party,
voucher_type, voucher_no, {dimension_fields} voucher_type, voucher_no, {dimension_fields}
cost_center, project, cost_center, project, {transaction_currency_fields}
against_voucher_type, against_voucher, account_currency, against_voucher_type, against_voucher, account_currency,
remarks, against, is_opening, creation {select_fields} remarks, against, is_opening, creation {select_fields}
from `tabGL Entry` from `tabGL Entry`
@ -195,6 +201,7 @@ def get_gl_entries(filters, accounting_dimensions):
{order_by_statement} {order_by_statement}
""".format( """.format(
dimension_fields=dimension_fields, dimension_fields=dimension_fields,
transaction_currency_fields=transaction_currency_fields,
select_fields=select_fields, select_fields=select_fields,
conditions=get_conditions(filters), conditions=get_conditions(filters),
order_by_statement=order_by_statement, order_by_statement=order_by_statement,
@ -562,6 +569,34 @@ def get_columns(filters):
"fieldtype": "Float", "fieldtype": "Float",
"width": 130, "width": 130,
}, },
]
if filters.get("add_values_in_transaction_currency"):
columns += [
{
"label": _("Debit (Transaction)"),
"fieldname": "debit_in_transaction_currency",
"fieldtype": "Currency",
"width": 130,
"options": "transaction_currency",
},
{
"label": _("Credit (Transaction)"),
"fieldname": "credit_in_transaction_currency",
"fieldtype": "Currency",
"width": 130,
"options": "transaction_currency",
},
{
"label": "Transaction Currency",
"fieldname": "transaction_currency",
"fieldtype": "Link",
"options": "Currency",
"width": 70,
},
]
columns += [
{"label": _("Voucher Type"), "fieldname": "voucher_type", "width": 120}, {"label": _("Voucher Type"), "fieldname": "voucher_type", "width": 120},
{ {
"label": _("Voucher No"), "label": _("Voucher No"),

View File

@ -805,8 +805,28 @@ class AccountsController(TransactionBase):
gl_dict, account_currency, self.get("conversion_rate"), self.company_currency gl_dict, account_currency, self.get("conversion_rate"), self.company_currency
) )
# Update details in transaction currency
gl_dict.update(
{
"transaction_currency": self.get("currency") or self.company_currency,
"transaction_exchange_rate": self.get("conversion_rate", 1),
"debit_in_transaction_currency": self.get_value_in_transaction_currency(
account_currency, args, "debit"
),
"credit_in_transaction_currency": self.get_value_in_transaction_currency(
account_currency, args, "credit"
),
}
)
return gl_dict return gl_dict
def get_value_in_transaction_currency(self, account_currency, args, field):
if account_currency == self.get("currency"):
return args.get(field + "_in_account_currency")
else:
return flt(args.get(field, 0) / self.get("conversion_rate", 1))
def validate_qty_is_not_zero(self): def validate_qty_is_not_zero(self):
if self.doctype != "Purchase Receipt": if self.doctype != "Purchase Receipt":
for item in self.items: for item in self.items: