Skip to content

Commit

Permalink
fix: make offsetting entry for all doctypes
Browse files Browse the repository at this point in the history
(cherry picked from commit 22ba121)
  • Loading branch information
GursheenK authored and mergify[bot] committed Aug 18, 2023
1 parent c1f1a21 commit f578c32
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
43 changes: 0 additions & 43 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,51 +913,8 @@ def build_gl_map(self):
item=d,
)
)

self.make_acc_dimensions_offsetting_entry(gl_map, d)

return gl_map

def make_acc_dimensions_offsetting_entry(self, gl_map, d):
accounting_dimensions = frappe.db.get_list("Accounting Dimension", {"disabled": 0}, pluck="name")
for dimension in accounting_dimensions:
dimension_details = frappe.db.get_values(
"Accounting Dimension Detail",
{"parent": dimension, "company": self.company},
["automatically_post_balancing_accounting_entry", "offsetting_account"],
)
dimension_details = dimension_details[0] if len(dimension_details) > 0 else None
if dimension_details and dimension_details[0] == 1:
offsetting_account = dimension_details[1]
gl_map.append(
self.get_gl_dict(
{
"account": offsetting_account,
"party_type": d.party_type,
"due_date": self.due_date,
"party": d.party,
"against": d.against_account,
"debit": flt(d.credit, d.precision("credit")),
"credit": flt(d.debit, d.precision("credit")),
"account_currency": d.account_currency,
"debit_in_account_currency": flt(
d.credit_in_account_currency, d.precision("credit_in_account_currency")
),
"credit_in_account_currency": flt(
d.debit_in_account_currency, d.precision("debit_in_account_currency")
),
"against_voucher_type": d.reference_type,
"against_voucher": d.reference_name,
"remarks": _("Offsetting for Accounting Dimension") + " - {0}".format(dimension),
"voucher_detail_no": d.reference_detail_no,
"cost_center": d.cost_center,
"project": d.project,
"finance_book": self.finance_book,
},
item=d,
)
)

def make_gl_entries(self, cancel=0, adv_adj=0):
from erpnext.accounts.general_ledger import make_gl_entries

Expand Down
45 changes: 45 additions & 0 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def make_gl_entries(
from_repost=False,
):
if gl_map:
make_acc_dimensions_offsetting_entry(gl_map)
if not cancel:
validate_accounting_period(gl_map)
validate_disabled_accounts(gl_map)
Expand All @@ -51,6 +52,50 @@ def make_gl_entries(
make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)


def make_acc_dimensions_offsetting_entry(gl_map):
accounting_dimensions_to_offset = get_accounting_dimensions_for_offsetting_entry(gl_map)
if len(accounting_dimensions_to_offset) == 0:
return

offsetting_entries = []
for gle in gl_map:
for dimension in accounting_dimensions_to_offset:
dimension_details = frappe.db.get_values(
"Accounting Dimension Detail",
{"parent": dimension, "company": gle.company},
["automatically_post_balancing_accounting_entry", "offsetting_account"],
)
dimension_details = dimension_details[0] if len(dimension_details) > 0 else None
if dimension_details and dimension_details[0] == 1:
offsetting_account = dimension_details[1]
offsetting_entry = gle.copy()
offsetting_entry.update(
{
"account": offsetting_account,
"debit": flt(gle.credit),
"credit": flt(gle.debit),
"debit_in_account_currency": flt(gle.credit_in_account_currency),
"credit_in_account_currency": flt(gle.debit_in_account_currency),
"remarks": _("Offsetting for Accounting Dimension") + " - {0}".format(dimension),
"against_voucher": None,
}
)
offsetting_entry["against_voucher_type"] = None
offsetting_entries.append(offsetting_entry)
gl_map += offsetting_entries


def get_accounting_dimensions_for_offsetting_entry(gl_map):
acc_dimensions = frappe.db.get_list("Accounting Dimension", {"disabled": 0}, pluck="name")
accounting_dimensions_to_offset = []
for acc_dimension in acc_dimensions:
fieldname = acc_dimension.lower().replace(" ", "_")
values = set([entry[fieldname] for entry in gl_map])
if len(values) > 1:
accounting_dimensions_to_offset.append(acc_dimension)
return accounting_dimensions_to_offset


def validate_disabled_accounts(gl_map):
accounts = [d.account for d in gl_map if d.account]

Expand Down

0 comments on commit f578c32

Please sign in to comment.