Skip to content

Commit

Permalink
fix: use flag _skip_merge instead of skipping merge based on agains…
Browse files Browse the repository at this point in the history
…t account
  • Loading branch information
vorasmit committed Nov 9, 2024
1 parent fc67374 commit ebf74c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def make_supplier_gl_entry(self, gl_entries):
self.add_supplier_gl_entry(gl_entries, base_grand_total, grand_total)

def add_supplier_gl_entry(
self, gl_entries, base_grand_total, grand_total, against_account=None, remarks=None
self, gl_entries, base_grand_total, grand_total, against_account=None, remarks=None, skip_merge=False
):
against_voucher = self.name
if self.is_return and self.return_against and not self.update_outstanding_for_self:
Expand All @@ -923,6 +923,7 @@ def add_supplier_gl_entry(
"against_voucher_type": self.doctype,
"project": self.project,
"cost_center": self.cost_center,
"_skip_merge": skip_merge,
}

if remarks:
Expand Down Expand Up @@ -1446,6 +1447,7 @@ def make_gl_entries_for_tax_withholding(self, gl_entries):
-tds_amount,
against_account=row.account_head,
remarks=_("TDS Deducted"),
skip_merge=True,
)

def make_payment_gl_entries(self, gl_entries):
Expand Down
53 changes: 40 additions & 13 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import (
get_dimension_filter_map,
)
from erpnext.accounts.doctype.accounting_period.accounting_period import ClosedAccountingPeriod
from erpnext.accounts.doctype.accounting_period.accounting_period import (
ClosedAccountingPeriod,
)
from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget
from erpnext.accounts.utils import create_payment_ledger_entry
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
from erpnext.exceptions import (
InvalidAccountDimensionError,
MandatoryAccountDimensionError,
)


def make_gl_entries(
Expand Down Expand Up @@ -98,7 +103,11 @@ def get_accounting_dimensions_for_offsetting_entry(gl_map, company):
frappe.qb.from_(acc_dimension)
.inner_join(dimension_detail)
.on(acc_dimension.name == dimension_detail.parent)
.select(acc_dimension.fieldname, acc_dimension.name, dimension_detail.offsetting_account)
.select(
acc_dimension.fieldname,
acc_dimension.name,
dimension_detail.offsetting_account,
)
.where(
(acc_dimension.disabled == 0)
& (dimension_detail.company == company)
Expand Down Expand Up @@ -196,7 +205,12 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None):
for sub_cost_center, percentage in cost_center_allocation:
gle = copy.deepcopy(d)
gle.cost_center = sub_cost_center
for field in ("debit", "credit", "debit_in_account_currency", "credit_in_account_currency"):
for field in (
"debit",
"credit",
"debit_in_account_currency",
"credit_in_account_currency",
):
gle[field] = flt(flt(d.get(field)) * percentage / 100, precision)
new_gl_map.append(gle)

Expand Down Expand Up @@ -235,6 +249,10 @@ def merge_similar_entries(gl_map, precision=None):
merge_properties = get_merge_properties(accounting_dimensions)

for entry in gl_map:
if entry._skip_merge:
merged_gl_map.append(entry)
continue

entry.merge_key = get_merge_key(entry, merge_properties)
# if there is already an entry in this account then just add it
# to that entry
Expand Down Expand Up @@ -291,7 +309,6 @@ def get_merge_properties(dimensions=None):
"project",
"finance_book",
"voucher_no",
"against",
]
if dimensions:
merge_properties.extend(dimensions)
Expand Down Expand Up @@ -513,7 +530,8 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
if not round_off_for_opening:
frappe.throw(
_("Please set '{0}' in Company: {1}").format(
frappe.bold("Round Off for Opening"), get_link_to_form("Company", gl_map[0].company)
frappe.bold("Round Off for Opening"),
get_link_to_form("Company", gl_map[0].company),
)
)

Expand Down Expand Up @@ -542,8 +560,8 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
round_off_gle.update(
{
"account": account,
"debit_in_account_currency": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
"credit_in_account_currency": debit_credit_diff if debit_credit_diff > 0 else 0,
"debit_in_account_currency": (abs(debit_credit_diff) if debit_credit_diff < 0 else 0),
"credit_in_account_currency": (debit_credit_diff if debit_credit_diff > 0 else 0),
"debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
"credit": debit_credit_diff if debit_credit_diff > 0 else 0,
"cost_center": round_off_cost_center,
Expand Down Expand Up @@ -574,7 +592,10 @@ def update_accounting_dimensions(round_off_gle):

if dimensions and has_all_dimensions:
dimension_values = frappe.db.get_value(
round_off_gle["voucher_type"], round_off_gle["voucher_no"], dimensions, as_dict=1
round_off_gle["voucher_type"],
round_off_gle["voucher_no"],
dimensions,
as_dict=1,
)

for dimension in dimensions:
Expand All @@ -583,7 +604,9 @@ def update_accounting_dimensions(round_off_gle):

def get_round_off_account_and_cost_center(company, voucher_type, voucher_no, use_company_default=False):
round_off_account, round_off_cost_center, round_off_for_opening = frappe.get_cached_value(
"Company", company, ["round_off_account", "round_off_cost_center", "round_off_for_opening"]
"Company",
company,
["round_off_account", "round_off_cost_center", "round_off_for_opening"],
) or [None, None, None]

# Use expense account as fallback
Expand All @@ -608,7 +631,8 @@ def get_round_off_account_and_cost_center(company, voucher_type, voucher_no, use
if not round_off_cost_center:
frappe.throw(
_("Please mention '{0}' in Company: {1}").format(
frappe.bold("Round Off Cost Center"), get_link_to_form("Company", company)
frappe.bold("Round Off Cost Center"),
get_link_to_form("Company", company),
)
)

Expand Down Expand Up @@ -741,7 +765,9 @@ def validate_against_pcv(is_opening, posting_date, company):
)

last_pcv_date = frappe.db.get_value(
"Period Closing Voucher", {"docstatus": 1, "company": company}, "max(period_end_date)"
"Period Closing Voucher",
{"docstatus": 1, "company": company},
"max(period_end_date)",
)

if last_pcv_date and getdate(posting_date) <= getdate(last_pcv_date):
Expand Down Expand Up @@ -772,7 +798,8 @@ def validate_allowed_dimensions(gl_entry, dimension_filter_map):
if value["is_mandatory"] and not gl_entry.get(dimension):
frappe.throw(
_("{0} is mandatory for account {1}").format(
frappe.bold(frappe.unscrub(dimension)), frappe.bold(gl_entry.account)
frappe.bold(frappe.unscrub(dimension)),
frappe.bold(gl_entry.account),
),
MandatoryAccountDimensionError,
)
Expand Down
1 change: 0 additions & 1 deletion erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ def update_value_in_dict(data, key, gle):
gle.get("account"),
gle.get("party_type"),
gle.get("party"),
gle.get("against"),
]

if immutable_ledger:
Expand Down

0 comments on commit ebf74c3

Please sign in to comment.