Book gl entry automatically due to rounding loss with test cases
This commit is contained in:
parent
98c515fe7d
commit
80069a6379
@ -101,7 +101,7 @@
|
||||
"label": "Account Type",
|
||||
"oldfieldname": "account_type",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "\nBank\nCash\nTax\nChargeable\nWarehouse\nReceivable\nPayable\nEquity\nFixed Asset\nCost of Goods Sold\nExpense Account\nIncome Account\nStock Received But Not Billed\nExpenses Included In Valuation\nStock Adjustment\nStock\nTemporary",
|
||||
"options": "\nBank\nCash\nTax\nChargeable\nWarehouse\nReceivable\nPayable\nEquity\nFixed Asset\nCost of Goods Sold\nExpense Account\nRound Off\nIncome Account\nStock Received But Not Billed\nExpenses Included In Valuation\nStock Adjustment\nStock\nTemporary",
|
||||
"permlevel": 0,
|
||||
"search_index": 0
|
||||
},
|
||||
@ -171,7 +171,7 @@
|
||||
"icon": "icon-money",
|
||||
"idx": 1,
|
||||
"in_create": 0,
|
||||
"modified": "2015-04-27 20:07:37.147184",
|
||||
"modified": "2015-05-28 14:10:40.606010",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Account",
|
||||
|
@ -117,8 +117,8 @@ def get():
|
||||
_("Print and Stationary"): {
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
_("Rounded Off"): {
|
||||
"account_type": "Expense Account"
|
||||
_("Round Off"): {
|
||||
"account_type": "Round Off"
|
||||
},
|
||||
_("Salary"): {
|
||||
"account_type": "Expense Account"
|
||||
|
25
erpnext/accounts/doctype/gl_entry/test_gl_entry.py
Normal file
25
erpnext/accounts/doctype/gl_entry/test_gl_entry.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe, unittest
|
||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||
|
||||
class TestGLEntry(unittest.TestCase):
|
||||
def test_round_off_entry(self):
|
||||
frappe.db.set_value("Company", "_Test Company", "round_off_account", "_Test Write Off - _TC")
|
||||
frappe.db.set_value("Company", "_Test Company", "round_off_cost_center", "_Test Cost Center - _TC")
|
||||
|
||||
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||
"_Test Account Bank Account - _TC", 100, "_Test Cost Center - _TC", submit=False)
|
||||
|
||||
jv.get("accounts")[0].debit = 100.01
|
||||
jv.flags.ignore_validate = True
|
||||
jv.submit()
|
||||
|
||||
round_off_entry = frappe.db.sql("""select name from `tabGL Entry`
|
||||
where voucher_type='Journal Entry' and voucher_no = %s
|
||||
and account='_Test Write Off - _TC' and cost_center='_Test Cost Center - _TC'
|
||||
and ifnull(debit, 0) = 0 and ifnull(credit, 0) = '.01'""", jv.name)
|
||||
|
||||
self.assertTrue(round_off_entry)
|
@ -5,7 +5,6 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import flt, cstr
|
||||
from frappe import _
|
||||
import copy
|
||||
from frappe.model.meta import get_field_precision
|
||||
from erpnext.accounts.utils import validate_expense_against_budget
|
||||
|
||||
@ -88,7 +87,8 @@ def validate_account_for_auto_accounting_for_stock(gl_map):
|
||||
|
||||
for entry in gl_map:
|
||||
if entry.account in aii_accounts:
|
||||
frappe.throw(_("Account: {0} can only be updated via Stock Transactions").format(entry.account), StockAccountInvalidTransaction)
|
||||
frappe.throw(_("Account: {0} can only be updated via Stock Transactions")
|
||||
.format(entry.account), StockAccountInvalidTransaction)
|
||||
|
||||
def round_off_debit_credit(gl_map):
|
||||
precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),
|
||||
@ -101,6 +101,7 @@ def round_off_debit_credit(gl_map):
|
||||
debit_credit_diff += entry.debit - entry.credit
|
||||
|
||||
debit_credit_diff = flt(debit_credit_diff, precision)
|
||||
print debit_credit_diff, 1.0 / (10**precision)
|
||||
if abs(debit_credit_diff) >= (2.0 / (10**precision)):
|
||||
frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.")
|
||||
.format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
|
||||
@ -117,7 +118,12 @@ def make_round_off_gle(gl_map, debit_credit_diff):
|
||||
if not round_off_cost_center:
|
||||
frappe.throw(_("Please mention Round Off Cost Center in Company"))
|
||||
|
||||
round_off_gle = copy.deepcopy(gl_map[0])
|
||||
|
||||
round_off_gle = frappe._dict()
|
||||
for k in ["voucher_type", "voucher_no", "company",
|
||||
"posting_date", "remarks", "fiscal_year", "is_opening"]:
|
||||
round_off_gle[k] = gl_map[0][k]
|
||||
|
||||
round_off_gle.update({
|
||||
"account": round_off_account,
|
||||
"debit": abs(debit_credit_diff) if debit_credit_diff < 0 else 0,
|
||||
@ -128,6 +134,7 @@ def make_round_off_gle(gl_map, debit_credit_diff):
|
||||
"against_voucher_type": None,
|
||||
"against_voucher": None
|
||||
})
|
||||
|
||||
gl_map.append(round_off_gle)
|
||||
|
||||
|
||||
|
2
erpnext/change_log/current/round_off_gl_entry.md
Normal file
2
erpnext/change_log/current/round_off_gl_entry.md
Normal file
@ -0,0 +1,2 @@
|
||||
- Introduce `Round Off` account to book rounding loss automatically
|
||||
- Added 2 new fields 'Round Off Account' and 'Round Off Cost Center' in Company
|
@ -4,6 +4,10 @@
|
||||
frappe.provide("erpnext.company");
|
||||
|
||||
frappe.ui.form.on("Company", {
|
||||
onload: function(frm) {
|
||||
erpnext.company.setup_queries(frm);
|
||||
},
|
||||
|
||||
onload_post_render: function(frm) {
|
||||
frm.get_field("delete_company_transactions").$input.addClass("btn-danger");
|
||||
},
|
||||
@ -114,98 +118,44 @@ cur_frm.cscript.change_abbr = function() {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.default_bank_account.get_query = function(doc) {
|
||||
return{
|
||||
filters: [
|
||||
['Account', 'account_type', '=', 'Bank'],
|
||||
['Account', 'is_group', '=', 0],
|
||||
['Account', 'company', '=', doc.name]
|
||||
]
|
||||
erpnext.company.setup_queries = function(frm) {
|
||||
$.each([
|
||||
["default_bank_account", {"account_type": "Bank"}],
|
||||
["default_cash_account", {"account_type": "Cash"}],
|
||||
["default_receivable_account", {"account_type": "Receivable"}],
|
||||
["default_payable_account", {"account_type": "Payable"}],
|
||||
["default_expense_account", {"report_type": "Profit and Loss"}],
|
||||
["default_income_account", {"report_type": "Profit and Loss"}],
|
||||
["round_off_account", {"account_type": "Profit and Loss"}],
|
||||
["cost_center", {}],
|
||||
["round_off_cost_center", {}]
|
||||
], function(i, v) {
|
||||
erpnext.company.set_custom_query(frm, v);
|
||||
});
|
||||
|
||||
if (sys_defaults.auto_accounting_for_stock) {
|
||||
$.each([
|
||||
["stock_adjustment_account", {"report_type": "Profit and Loss"}],
|
||||
["expenses_included_in_valuation", {"report_type": "Profit and Loss"}],
|
||||
["stock_received_but_not_billed", {"report_type": "Balance Sheet"}]
|
||||
], function(i, v) {
|
||||
erpnext.company.set_custom_query(frm, v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.default_cash_account.get_query = function(doc) {
|
||||
return{
|
||||
filters: [
|
||||
['Account', 'account_type', '=', 'Cash'],
|
||||
['Account', 'is_group', '=', 0],
|
||||
['Account', 'company', '=', doc.name]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.default_receivable_account.get_query = function(doc) {
|
||||
return{
|
||||
filters:{
|
||||
'company': doc.name,
|
||||
"is_group": 0,
|
||||
"account_type": "Receivable"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.default_payable_account.get_query = function(doc) {
|
||||
return{
|
||||
filters:{
|
||||
'company': doc.name,
|
||||
"is_group": 0,
|
||||
"account_type": "Payable"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.fields_dict.default_expense_account.get_query = function(doc) {
|
||||
return{
|
||||
filters:{
|
||||
'company': doc.name,
|
||||
"is_group": 0,
|
||||
"report_type": "Profit and Loss"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.default_income_account.get_query = function(doc) {
|
||||
return{
|
||||
filters:{
|
||||
'company': doc.name,
|
||||
"is_group": 0,
|
||||
"report_type": "Profit and Loss"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.cost_center.get_query = function(doc) {
|
||||
return{
|
||||
filters:{
|
||||
'company': doc.name,
|
||||
"is_group": 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sys_defaults.auto_accounting_for_stock) {
|
||||
cur_frm.fields_dict["stock_adjustment_account"].get_query = function(doc) {
|
||||
erpnext.company.set_custom_query = function(frm, v) {
|
||||
var filters = {
|
||||
"company": frm.doc.company,
|
||||
"is_group": 0
|
||||
};
|
||||
|
||||
for (var key in v[1])
|
||||
filters[key] = v[1][key];
|
||||
|
||||
frm.set_query(v[0], function() {
|
||||
return {
|
||||
"filters": {
|
||||
"report_type": "Profit and Loss",
|
||||
"company": doc.name,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.fields_dict["expenses_included_in_valuation"].get_query =
|
||||
cur_frm.fields_dict["stock_adjustment_account"].get_query;
|
||||
|
||||
cur_frm.fields_dict["stock_received_but_not_billed"].get_query = function(doc) {
|
||||
return {
|
||||
"filters": {
|
||||
"report_type": "Balance Sheet",
|
||||
"company": doc.name,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
filters: filters
|
||||
};
|
||||
});
|
||||
}
|
@ -114,6 +114,7 @@ class Company(Document):
|
||||
def set_default_accounts(self):
|
||||
self._set_default_account("default_cash_account", "Cash")
|
||||
self._set_default_account("default_bank_account", "Bank")
|
||||
self._set_default_account("round_off_account", "Round Off")
|
||||
|
||||
if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")):
|
||||
self._set_default_account("stock_received_but_not_billed", "Stock Received But Not Billed")
|
||||
@ -161,6 +162,7 @@ class Company(Document):
|
||||
cc_doc.insert()
|
||||
|
||||
frappe.db.set(self, "cost_center", _("Main") + " - " + self.abbr)
|
||||
frappe.db.set(self, "round_off_cost_center", _("Main") + " - " + self.abbr)
|
||||
|
||||
def before_rename(self, olddn, newdn, merge=False):
|
||||
if merge:
|
||||
|
Loading…
Reference in New Issue
Block a user