[fix] Period closing voucher

This commit is contained in:
Nabin Hait 2016-05-23 16:28:39 +05:30
parent 832988e2fd
commit 03b08e7a91
3 changed files with 8 additions and 7 deletions

View File

@ -172,9 +172,9 @@ class TestJournalEntry(unittest.TestCase):
jv.submit() jv.submit()
def make_journal_entry(account1, account2, amount, cost_center=None, exchange_rate=1, save=True, submit=False): def make_journal_entry(account1, account2, amount, cost_center=None, posting_date=None, exchange_rate=1, save=True, submit=False):
jv = frappe.new_doc("Journal Entry") jv = frappe.new_doc("Journal Entry")
jv.posting_date = "2013-02-14" jv.posting_date = posting_date or "2013-02-14"
jv.company = "_Test Company" jv.company = "_Test Company"
jv.user_remark = "test" jv.user_remark = "test"
jv.multi_currency = 1 jv.multi_currency = 1

View File

@ -55,6 +55,7 @@ class PeriodClosingVoucher(AccountsController):
if flt(acc.balance_in_company_currency): if flt(acc.balance_in_company_currency):
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": acc.account, "account": acc.account,
"cost_center": acc.cost_center,
"account_currency": acc.account_currency, "account_currency": acc.account_currency,
"debit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \ "debit_in_account_currency": abs(flt(acc.balance_in_account_currency)) \
if flt(acc.balance_in_account_currency) < 0 else 0, if flt(acc.balance_in_account_currency) < 0 else 0,
@ -84,12 +85,12 @@ class PeriodClosingVoucher(AccountsController):
"""Get balance for pl accounts""" """Get balance for pl accounts"""
return frappe.db.sql(""" return frappe.db.sql("""
select select
t1.account, t2.account_currency, t1.account, t1.cost_center, t2.account_currency,
sum(t1.debit_in_account_currency) - sum(t1.credit_in_account_currency) as balance_in_account_currency, sum(t1.debit_in_account_currency) - sum(t1.credit_in_account_currency) as balance_in_account_currency,
sum(t1.debit) - sum(t1.credit) as balance_in_company_currency sum(t1.debit) - sum(t1.credit) as balance_in_company_currency
from `tabGL Entry` t1, `tabAccount` t2 from `tabGL Entry` t1, `tabAccount` t2
where t1.account = t2.name and t2.report_type = 'Profit and Loss' where t1.account = t2.name and t2.report_type = 'Profit and Loss'
and t2.docstatus < 2 and t2.company = %s and t2.docstatus < 2 and t2.company = %s
and t1.posting_date between %s and %s and t1.posting_date between %s and %s
group by t1.account group by t1.account, t1.cost_center
""", (self.company, self.get("year_start_date"), self.posting_date), as_dict=1) """, (self.company, self.get("year_start_date"), self.posting_date), as_dict=1)

View File

@ -6,7 +6,7 @@ from __future__ import unicode_literals
import unittest import unittest
import frappe import frappe
from frappe.utils import flt, today from frappe.utils import flt, today
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year, now
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
class TestPeriodClosingVoucher(unittest.TestCase): class TestPeriodClosingVoucher(unittest.TestCase):
@ -14,10 +14,10 @@ class TestPeriodClosingVoucher(unittest.TestCase):
year_start_date = get_fiscal_year(today())[1] year_start_date = get_fiscal_year(today())[1]
make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400, make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400,
"_Test Cost Center - _TC", submit=True) "_Test Cost Center - _TC", posting_date=now(), submit=True)
make_journal_entry("_Test Account Cost for Goods Sold - _TC", make_journal_entry("_Test Account Cost for Goods Sold - _TC",
"_Test Bank - _TC", 600, "_Test Cost Center - _TC", submit=True) "_Test Bank - _TC", 600, "_Test Cost Center - _TC", posting_date=now(), submit=True)
random_expense_account = frappe.db.sql(""" random_expense_account = frappe.db.sql("""
select t1.account, select t1.account,