fix: First preference to parent cost center rather than round off cost center

(cherry picked from commit 0ac11a5b30)
This commit is contained in:
Deepesh Garg
2022-04-20 12:18:11 +05:30
committed by mergify-bot
parent f70fca1c9e
commit a2d95fc62b

View File

@@ -273,7 +273,7 @@ def round_off_debit_credit(gl_map):
def make_round_off_gle(gl_map, debit_credit_diff, precision):
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(
gl_map[0].company
gl_map[0].company, gl_map[0].voucher_type, gl_map[0].voucher_no
)
round_off_account_exists = False
round_off_gle = frappe._dict()
@@ -314,10 +314,17 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
gl_map.append(round_off_gle)
def get_round_off_account_and_cost_center(company):
def get_round_off_account_and_cost_center(company, voucher_type, voucher_no):
round_off_account, round_off_cost_center = frappe.get_cached_value(
"Company", company, ["round_off_account", "round_off_cost_center"]
) or [None, None]
# Give first preference to parent cost center for round off GLE
if frappe.db.has_column(voucher_type, "cost_center"):
parent_cost_center = frappe.db.get_value(voucher_type, voucher_no, "cost_center")
if parent_cost_center:
round_off_cost_center = parent_cost_center
if not round_off_account:
frappe.throw(_("Please mention Round Off Account in Company"))