fix: cost center wise ledger posting for pcv (#28477)

This commit is contained in:
Saqib 2021-11-22 12:24:32 +05:30 committed by GitHub
parent 78851ecb70
commit cb52e6dd6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -88,9 +88,10 @@ class PeriodClosingVoucher(AccountsController):
for acc in pl_accounts: for acc in pl_accounts:
if flt(acc.bal_in_company_currency): if flt(acc.bal_in_company_currency):
cost_center = acc.cost_center if self.cost_center_wise_pnl else company_cost_center
gl_entry = self.get_gl_dict({ gl_entry = self.get_gl_dict({
"account": self.closing_account_head, "account": self.closing_account_head,
"cost_center": acc.cost_center or company_cost_center, "cost_center": cost_center,
"finance_book": acc.finance_book, "finance_book": acc.finance_book,
"account_currency": acc.account_currency, "account_currency": acc.account_currency,
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency)) if flt(acc.bal_in_account_currency) > 0 else 0, "debit_in_account_currency": abs(flt(acc.bal_in_account_currency)) if flt(acc.bal_in_account_currency) > 0 else 0,

View File

@ -66,8 +66,8 @@ class TestPeriodClosingVoucher(unittest.TestCase):
company = create_company() company = create_company()
surplus_account = create_account() surplus_account = create_account()
cost_center1 = create_cost_center("Test Cost Center 1") cost_center1 = create_cost_center("Main")
cost_center2 = create_cost_center("Test Cost Center 2") cost_center2 = create_cost_center("Western Branch")
create_sales_invoice( create_sales_invoice(
company=company, company=company,
@ -86,7 +86,10 @@ class TestPeriodClosingVoucher(unittest.TestCase):
debit_to="Debtors - TPC" debit_to="Debtors - TPC"
) )
pcv = self.make_period_closing_voucher() pcv = self.make_period_closing_voucher(submit=False)
pcv.cost_center_wise_pnl = 1
pcv.save()
pcv.submit()
surplus_account = pcv.closing_account_head surplus_account = pcv.closing_account_head
expected_gle = ( expected_gle = (
@ -149,7 +152,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
self.assertEqual(pcv_gle, expected_gle) self.assertEqual(pcv_gle, expected_gle)
def make_period_closing_voucher(self): def make_period_closing_voucher(self, submit=True):
surplus_account = create_account() surplus_account = create_account()
cost_center = create_cost_center("Test Cost Center 1") cost_center = create_cost_center("Test Cost Center 1")
pcv = frappe.get_doc({ pcv = frappe.get_doc({
@ -163,6 +166,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
"remarks": "test" "remarks": "test"
}) })
pcv.insert() pcv.insert()
if submit:
pcv.submit() pcv.submit()
return pcv return pcv