[perpetual accounting] make gl entries relevant for different transactions

This commit is contained in:
Nabin Hait
2013-08-06 16:00:50 +05:30
parent 69f350a4d0
commit 43eba26dcf
29 changed files with 259 additions and 222 deletions

View File

@@ -69,6 +69,7 @@ class DocType:
def validate_posting_date(self):
from accounts.utils import validate_fiscal_year
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, "Posting Date")
def check_credit_limit(self):
master_type, master_name = webnotes.conn.get_value("Account",

View File

@@ -33,7 +33,7 @@ class DocType:
def validate(self):
self.check_for_duplicate()
self.validate_expense_account()
def check_for_duplicate(self):
res = webnotes.conn.sql("""select name, user from `tabPOS Setting`
where ifnull(user, '') = %s and name != %s and company = %s""",
@@ -47,6 +47,6 @@ class DocType:
(res[0][0], self.doc.company), raise_exception=1)
def validate_expense_account(self):
if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
if cint(webnotes.defaults.get_global_default("perpetual_accounting")) \
and not self.doc.expense_account:
msgprint(_("Expense Account is mandatory"), raise_exception=1)

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-05-24 12:15:51",
"docstatus": 0,
"modified": "2013-08-01 16:50:05",
"modified": "2013-08-05 16:51:22",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -163,7 +163,7 @@
"reqd": 1
},
{
"depends_on": "eval:sys_defaults.auto_inventory_accounting",
"depends_on": "eval:sys_defaults.perpetual_accounting",
"doctype": "DocField",
"fieldname": "expense_account",
"fieldtype": "Link",

View File

@@ -235,29 +235,29 @@ class DocType(BuyingController):
raise Exception
def set_against_expense_account(self):
auto_inventory_accounting = \
cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
perpetual_accounting = cint(webnotes.defaults.get_global_default("perpetual_accounting"))
if auto_inventory_accounting:
if perpetual_accounting:
stock_not_billed_account = self.get_company_default("stock_received_but_not_billed")
against_accounts = []
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "entries"}):
if auto_inventory_accounting and item.item_code in stock_items:
if perpetual_accounting and item.item_code in stock_items:
# in case of auto inventory accounting, against expense account is always
# Stock Received But Not Billed for a stock item
item.expense_head = item.cost_center = None
item.expense_head = stock_not_billed_account
item.cost_center = None
if stock_not_billed_account not in against_accounts:
against_accounts.append(stock_not_billed_account)
elif not item.expense_head:
msgprint(_("""Expense account is mandatory for item: """) + (item.item_code or item.item_name),
raise_exception=1)
msgprint(_("Expense account is mandatory for item") + ": " +
(item.item_code or item.item_name), raise_exception=1)
elif item.expense_head not in against_accounts:
# if no auto_inventory_accounting or not a stock item
# if no perpetual_accounting or not a stock item
against_accounts.append(item.expense_head)
self.doc.against_expense_account = ",".join(against_accounts)
@@ -340,9 +340,8 @@ class DocType(BuyingController):
self.update_prevdoc_status()
def make_gl_entries(self):
from accounts.general_ledger import make_gl_entries
auto_inventory_accounting = \
cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
perpetual_accounting = \
cint(webnotes.defaults.get_global_default("perpetual_accounting"))
gl_entries = []
@@ -379,18 +378,15 @@ class DocType(BuyingController):
valuation_tax += (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
# item gl entries
stock_item_and_auto_inventory_accounting = False
if auto_inventory_accounting:
stock_account = self.get_company_default("stock_received_but_not_billed")
stock_item_and_perpetual_accounting = False
stock_items = self.get_stock_items()
for item in self.doclist.get({"parentfield": "entries"}):
if auto_inventory_accounting and item.item_code in stock_items:
if perpetual_accounting and item.item_code in stock_items:
if flt(item.valuation_rate):
# if auto inventory accounting enabled and stock item,
# then do stock related gl entries
# expense will be booked in sales invoice
stock_item_and_auto_inventory_accounting = True
stock_item_and_perpetual_accounting = True
valuation_amt = (flt(item.amount, self.precision("amount", item)) +
flt(item.item_tax_amount, self.precision("item_tax_amount", item)) +
@@ -398,7 +394,7 @@ class DocType(BuyingController):
gl_entries.append(
self.get_gl_dict({
"account": stock_account,
"account": item.expense_head,
"against": self.doc.credit_to,
"debit": valuation_amt,
"remarks": self.doc.remarks or "Accounting Entry for Stock"
@@ -417,7 +413,7 @@ class DocType(BuyingController):
})
)
if stock_item_and_auto_inventory_accounting and valuation_tax:
if stock_item_and_perpetual_accounting and valuation_tax:
# credit valuation tax amount in "Expenses Included In Valuation"
# this will balance out valuation amount included in cost of goods sold
gl_entries.append(
@@ -444,6 +440,7 @@ class DocType(BuyingController):
)
if gl_entries:
from accounts.general_ledger import make_gl_entries
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
def on_cancel(self):

View File

@@ -27,9 +27,9 @@ test_dependencies = ["Item", "Cost Center"]
test_ignore = ["Serial No"]
class TestPurchaseInvoice(unittest.TestCase):
def test_gl_entries_without_auto_inventory_accounting(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
self.assertTrue(not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")))
def test_gl_entries_without_perpetual_accounting(self):
webnotes.defaults.set_global_default("perpetual_accounting", 0)
self.assertTrue(not cint(webnotes.defaults.get_global_default("perpetual_accounting")))
wrapper = webnotes.bean(copy=test_records[0])
wrapper.run_method("calculate_taxes_and_totals")
@@ -54,9 +54,9 @@ class TestPurchaseInvoice(unittest.TestCase):
for d in gl_entries:
self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
def test_gl_entries_with_auto_inventory_accounting(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_inventory_accounting")), 1)
def test_gl_entries_with_perpetual_accounting(self):
webnotes.defaults.set_global_default("perpetual_accounting", 1)
self.assertEqual(cint(webnotes.defaults.get_global_default("perpetual_accounting")), 1)
pi = webnotes.bean(copy=test_records[1])
pi.run_method("calculate_taxes_and_totals")
@@ -81,11 +81,11 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
def test_gl_entries_with_aia_for_non_stock_items(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_inventory_accounting")), 1)
webnotes.defaults.set_global_default("perpetual_accounting", 1)
self.assertEqual(cint(webnotes.defaults.get_global_default("perpetual_accounting")), 1)
pi = webnotes.bean(copy=test_records[1])
pi.doclist[1].item_code = "_Test Non Stock Item"
@@ -112,7 +112,7 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
def test_purchase_invoice_calculation(self):
wrapper = webnotes.bean(copy=test_records[0])

View File

@@ -332,7 +332,7 @@ cur_frm.set_query("income_account", "entries", function(doc) {
});
// expense account
if (sys_defaults.auto_inventory_accounting) {
if (sys_defaults.perpetual_accounting) {
cur_frm.fields_dict['entries'].grid.get_field('expense_account').get_query = function(doc) {
return {
filters: {

View File

@@ -61,6 +61,8 @@ class DocType(SellingController):
self.validate_proj_cust()
self.validate_with_previous_doc()
self.validate_uom_is_integer("stock_uom", "qty")
self.validate_warehouse_with_company([d.warehouse
for d in self.doclist.get({"parentfield": "entries"})])
sales_com_obj = get_obj('Sales Common')
sales_com_obj.check_stop_sales_order(self)
@@ -586,6 +588,10 @@ class DocType(SellingController):
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2),
update_outstanding=update_outstanding, merge_entries=False)
warehouse_list = list(set([d.warehouse for d in
self.doclist.get({"parentfield": "entries"})]))
self.sync_stock_account_balance(warehouse_list)
def make_customer_gl_entry(self, gl_entries):
if self.doc.grand_total:
gl_entries.append(
@@ -627,7 +633,7 @@ class DocType(SellingController):
)
# expense account gl entries
if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
if cint(webnotes.defaults.get_global_default("perpetual_accounting")) \
and cint(self.doc.update_stock):
for item in self.doclist.get({"parentfield": "entries"}):
@@ -635,7 +641,7 @@ class DocType(SellingController):
if item.buying_amount:
gl_entries += self.get_gl_entries_for_stock(item.expense_account,
-1*item.buying_amount, cost_center=item.cost_center)
-1*item.buying_amount, item.warehouse, cost_center=item.cost_center)
def make_pos_gl_entries(self, gl_entries):
if cint(self.doc.is_pos) and self.doc.cash_bank_account and self.doc.paid_amount:

View File

@@ -294,7 +294,7 @@ class TestSalesInvoice(unittest.TestCase):
"Batched for Billing")
def test_sales_invoice_gl_entry_without_aii(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
si = webnotes.bean(copy=test_records[1])
si.insert()
@@ -329,7 +329,7 @@ class TestSalesInvoice(unittest.TestCase):
def atest_pos_gl_entry_with_aii(self):
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
webnotes.defaults.set_global_default("perpetual_accounting", 1)
old_default_company = webnotes.conn.get_default("company")
webnotes.conn.set_default("company", "_Test Company")
@@ -389,11 +389,11 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEquals(gl_count[0][0], 16)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
webnotes.conn.set_default("company", old_default_company)
def test_sales_invoice_gl_entry_with_aii_no_item_code(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
webnotes.defaults.set_global_default("perpetual_accounting", 1)
si_copy = webnotes.copy_doclist(test_records[1])
si_copy[1]["item_code"] = None
@@ -417,10 +417,10 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
def test_sales_invoice_gl_entry_with_aii_non_stock_item(self):
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
webnotes.defaults.set_global_default("perpetual_accounting", 1)
si_copy = webnotes.copy_doclist(test_records[1])
si_copy[1]["item_code"] = "_Test Non Stock Item"
@@ -444,7 +444,7 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEquals(expected_values[i][1], gle.debit)
self.assertEquals(expected_values[i][2], gle.credit)
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
webnotes.defaults.set_global_default("perpetual_accounting", 0)
def _insert_purchase_receipt(self):
from stock.doctype.purchase_receipt.test_purchase_receipt import test_records \