-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into early-payment-loss
- Loading branch information
Showing
107 changed files
with
1,234 additions
and
2,281 deletions.
There are no files selected for viewing
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
erpnext/accounts/doctype/account_closing_balance/account_closing_balance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
// frappe.ui.form.on("Account Closing Balance", { | ||
// refresh(frm) { | ||
|
||
// }, | ||
// }); |
164 changes: 164 additions & 0 deletions
164
erpnext/accounts/doctype/account_closing_balance/account_closing_balance.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{ | ||
"actions": [], | ||
"creation": "2023-02-21 15:20:59.586811", | ||
"default_view": "List", | ||
"doctype": "DocType", | ||
"document_type": "Document", | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"closing_date", | ||
"account", | ||
"cost_center", | ||
"debit", | ||
"credit", | ||
"account_currency", | ||
"debit_in_account_currency", | ||
"credit_in_account_currency", | ||
"project", | ||
"company", | ||
"finance_book", | ||
"period_closing_voucher", | ||
"is_period_closing_voucher_entry" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "closing_date", | ||
"fieldtype": "Date", | ||
"in_filter": 1, | ||
"in_list_view": 1, | ||
"label": "Closing Date", | ||
"oldfieldname": "posting_date", | ||
"oldfieldtype": "Date", | ||
"search_index": 1 | ||
}, | ||
{ | ||
"fieldname": "account", | ||
"fieldtype": "Link", | ||
"in_filter": 1, | ||
"in_list_view": 1, | ||
"in_standard_filter": 1, | ||
"label": "Account", | ||
"oldfieldname": "account", | ||
"oldfieldtype": "Link", | ||
"options": "Account", | ||
"search_index": 1 | ||
}, | ||
{ | ||
"fieldname": "cost_center", | ||
"fieldtype": "Link", | ||
"in_filter": 1, | ||
"in_list_view": 1, | ||
"label": "Cost Center", | ||
"oldfieldname": "cost_center", | ||
"oldfieldtype": "Link", | ||
"options": "Cost Center" | ||
}, | ||
{ | ||
"fieldname": "debit", | ||
"fieldtype": "Currency", | ||
"label": "Debit Amount", | ||
"oldfieldname": "debit", | ||
"oldfieldtype": "Currency", | ||
"options": "Company:company:default_currency" | ||
}, | ||
{ | ||
"fieldname": "credit", | ||
"fieldtype": "Currency", | ||
"label": "Credit Amount", | ||
"oldfieldname": "credit", | ||
"oldfieldtype": "Currency", | ||
"options": "Company:company:default_currency" | ||
}, | ||
{ | ||
"fieldname": "account_currency", | ||
"fieldtype": "Link", | ||
"label": "Account Currency", | ||
"options": "Currency" | ||
}, | ||
{ | ||
"fieldname": "debit_in_account_currency", | ||
"fieldtype": "Currency", | ||
"label": "Debit Amount in Account Currency", | ||
"options": "account_currency" | ||
}, | ||
{ | ||
"fieldname": "credit_in_account_currency", | ||
"fieldtype": "Currency", | ||
"label": "Credit Amount in Account Currency", | ||
"options": "account_currency" | ||
}, | ||
{ | ||
"fieldname": "project", | ||
"fieldtype": "Link", | ||
"label": "Project", | ||
"options": "Project" | ||
}, | ||
{ | ||
"fieldname": "company", | ||
"fieldtype": "Link", | ||
"in_filter": 1, | ||
"in_list_view": 1, | ||
"in_standard_filter": 1, | ||
"label": "Company", | ||
"oldfieldname": "company", | ||
"oldfieldtype": "Link", | ||
"options": "Company", | ||
"search_index": 1 | ||
}, | ||
{ | ||
"fieldname": "finance_book", | ||
"fieldtype": "Link", | ||
"label": "Finance Book", | ||
"options": "Finance Book" | ||
}, | ||
{ | ||
"fieldname": "period_closing_voucher", | ||
"fieldtype": "Link", | ||
"in_standard_filter": 1, | ||
"label": "Period Closing Voucher", | ||
"options": "Period Closing Voucher", | ||
"search_index": 1 | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "is_period_closing_voucher_entry", | ||
"fieldtype": "Check", | ||
"label": "Is Period Closing Voucher Entry" | ||
} | ||
], | ||
"icon": "fa fa-list", | ||
"in_create": 1, | ||
"links": [], | ||
"modified": "2023-03-06 08:56:36.393237", | ||
"modified_by": "Administrator", | ||
"module": "Accounts", | ||
"name": "Account Closing Balance", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "Accounts User" | ||
}, | ||
{ | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "Accounts Manager" | ||
}, | ||
{ | ||
"export": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "Auditor" | ||
} | ||
], | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"states": [] | ||
} |
127 changes: 127 additions & 0 deletions
127
erpnext/accounts/doctype/account_closing_balance/account_closing_balance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe.model.document import Document | ||
from frappe.utils import cint, cstr | ||
|
||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( | ||
get_accounting_dimensions, | ||
) | ||
|
||
|
||
class AccountClosingBalance(Document): | ||
pass | ||
|
||
|
||
def make_closing_entries(closing_entries, voucher_name): | ||
accounting_dimensions = get_accounting_dimensions() | ||
company = closing_entries[0].get("company") | ||
closing_date = closing_entries[0].get("closing_date") | ||
|
||
previous_closing_entries = get_previous_closing_entries( | ||
company, closing_date, accounting_dimensions | ||
) | ||
combined_entries = closing_entries + previous_closing_entries | ||
|
||
merged_entries = aggregate_with_last_account_closing_balance( | ||
combined_entries, accounting_dimensions | ||
) | ||
|
||
for key, value in merged_entries.items(): | ||
cle = frappe.new_doc("Account Closing Balance") | ||
cle.update(value) | ||
cle.update(value["dimensions"]) | ||
cle.update( | ||
{ | ||
"period_closing_voucher": voucher_name, | ||
"closing_date": closing_date, | ||
} | ||
) | ||
cle.submit() | ||
|
||
|
||
def aggregate_with_last_account_closing_balance(entries, accounting_dimensions): | ||
merged_entries = {} | ||
for entry in entries: | ||
key, key_values = generate_key(entry, accounting_dimensions) | ||
merged_entries.setdefault( | ||
key, | ||
{ | ||
"debit": 0, | ||
"credit": 0, | ||
"debit_in_account_currency": 0, | ||
"credit_in_account_currency": 0, | ||
}, | ||
) | ||
|
||
merged_entries[key]["dimensions"] = key_values | ||
merged_entries[key]["debit"] += entry.get("debit") | ||
merged_entries[key]["credit"] += entry.get("credit") | ||
merged_entries[key]["debit_in_account_currency"] += entry.get("debit_in_account_currency") | ||
merged_entries[key]["credit_in_account_currency"] += entry.get("credit_in_account_currency") | ||
|
||
return merged_entries | ||
|
||
|
||
def generate_key(entry, accounting_dimensions): | ||
key = [ | ||
cstr(entry.get("account")), | ||
cstr(entry.get("account_currency")), | ||
cstr(entry.get("cost_center")), | ||
cstr(entry.get("project")), | ||
cstr(entry.get("finance_book")), | ||
cint(entry.get("is_period_closing_voucher_entry")), | ||
] | ||
|
||
key_values = { | ||
"company": cstr(entry.get("company")), | ||
"account": cstr(entry.get("account")), | ||
"account_currency": cstr(entry.get("account_currency")), | ||
"cost_center": cstr(entry.get("cost_center")), | ||
"project": cstr(entry.get("project")), | ||
"finance_book": cstr(entry.get("finance_book")), | ||
"is_period_closing_voucher_entry": cint(entry.get("is_period_closing_voucher_entry")), | ||
} | ||
for dimension in accounting_dimensions: | ||
key.append(cstr(entry.get(dimension))) | ||
key_values[dimension] = cstr(entry.get(dimension)) | ||
|
||
return tuple(key), key_values | ||
|
||
|
||
def get_previous_closing_entries(company, closing_date, accounting_dimensions): | ||
entries = [] | ||
last_period_closing_voucher = frappe.db.get_all( | ||
"Period Closing Voucher", | ||
filters={"docstatus": 1, "company": company, "posting_date": ("<", closing_date)}, | ||
fields=["name"], | ||
order_by="posting_date desc", | ||
limit=1, | ||
) | ||
|
||
if last_period_closing_voucher: | ||
account_closing_balance = frappe.qb.DocType("Account Closing Balance") | ||
query = frappe.qb.from_(account_closing_balance).select( | ||
account_closing_balance.company, | ||
account_closing_balance.account, | ||
account_closing_balance.account_currency, | ||
account_closing_balance.debit, | ||
account_closing_balance.credit, | ||
account_closing_balance.debit_in_account_currency, | ||
account_closing_balance.credit_in_account_currency, | ||
account_closing_balance.cost_center, | ||
account_closing_balance.project, | ||
account_closing_balance.finance_book, | ||
account_closing_balance.is_period_closing_voucher_entry, | ||
) | ||
|
||
for dimension in accounting_dimensions: | ||
query = query.select(account_closing_balance[dimension]) | ||
|
||
query = query.where( | ||
account_closing_balance.period_closing_voucher == last_period_closing_voucher[0].name | ||
) | ||
entries = query.run(as_dict=1) | ||
|
||
return entries |
9 changes: 9 additions & 0 deletions
9
erpnext/accounts/doctype/account_closing_balance/test_account_closing_balance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
|
||
|
||
class TestAccountClosingBalance(FrappeTestCase): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.