mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 18:04:46 +00:00
[fix] [minor] auto accounting for stock transactions
This commit is contained in:
@@ -12,19 +12,6 @@ class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
def validate(self):
|
||||
self.validate_auto_accounting_for_stock()
|
||||
|
||||
def validate_auto_accounting_for_stock(self):
|
||||
if cint(self.doc.auto_accounting_for_stock) == 1:
|
||||
previous_val = cint(webnotes.conn.get_value("Accounts Settings",
|
||||
None, "auto_accounting_for_stock"))
|
||||
if cint(self.doc.auto_accounting_for_stock) != previous_val:
|
||||
from accounts.utils import validate_stock_and_account_balance, \
|
||||
create_stock_in_hand_jv
|
||||
validate_stock_and_account_balance()
|
||||
create_stock_in_hand_jv(reverse=cint(self.doc.auto_accounting_for_stock) < previous_val)
|
||||
|
||||
def on_update(self):
|
||||
for key in ["auto_accounting_for_stock"]:
|
||||
webnotes.conn.set_default(key, self.doc.fields.get(key, ''))
|
||||
|
||||
@@ -32,6 +32,18 @@ class TestJournalVoucher(unittest.TestCase):
|
||||
|
||||
self.assertTrue(not webnotes.conn.sql("""select name from `tabJournal Voucher Detail`
|
||||
where against_jv=%s""", jv_invoice.doc.name))
|
||||
|
||||
def test_jv_against_stock_account(self):
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
|
||||
|
||||
jv = webnotes.bean(copy=test_records[0])
|
||||
jv.doclist[1].account = "_Test Account Stock in Hand - _TC"
|
||||
jv.insert()
|
||||
|
||||
from accounts.general_ledger import StockAccountInvalidTransaction
|
||||
self.assertRaises(StockAccountInvalidTransaction, jv.submit)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
|
||||
|
||||
def test_monthly_budget_crossed_ignore(self):
|
||||
webnotes.conn.set_value("Company", "_Test Company", "monthly_bgt_flag", "Ignore")
|
||||
|
||||
@@ -90,7 +90,6 @@ class DocType(SellingController):
|
||||
get_obj('Authorization Control').validate_approving_authority(self.doc.doctype,
|
||||
self.doc.company, self.doc.grand_total, self)
|
||||
|
||||
self.set_buying_amount()
|
||||
self.check_prev_docstatus()
|
||||
|
||||
self.update_status_updater_args()
|
||||
|
||||
@@ -330,13 +330,12 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
self.assertFalse(gle)
|
||||
|
||||
def atest_pos_gl_entry_with_aii(self):
|
||||
def test_pos_gl_entry_with_aii(self):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.conn.sql("delete from `tabGL Entry`")
|
||||
webnotes.conn.sql("delete from `tabBin`")
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
|
||||
|
||||
old_default_company = webnotes.conn.get_default("company")
|
||||
webnotes.conn.set_default("company", "_Test Company")
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
self._insert_pos_settings()
|
||||
|
||||
@@ -360,20 +359,18 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
["_Test Item", "_Test Warehouse - _TC", -1.0])
|
||||
|
||||
# check gl entries
|
||||
stock_in_hand_account = webnotes.conn.get_value("Company", "_Test Company",
|
||||
"stock_in_hand_account")
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
|
||||
order by account asc, debit asc""", si.doc.name, as_dict=1)
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
|
||||
expected_gl_entries = sorted([
|
||||
[si.doc.debit_to, 630.0, 0.0],
|
||||
[pos[1]["income_account"], 0.0, 500.0],
|
||||
[pos[2]["account_head"], 0.0, 80.0],
|
||||
[pos[3]["account_head"], 0.0, 50.0],
|
||||
[stock_in_hand_account, 0.0, 75.0],
|
||||
["_Test Account Stock In Hand - _TC", 0.0, 75.0],
|
||||
[pos[1]["expense_account"], 75.0, 0.0],
|
||||
[si.doc.debit_to, 0.0, 600.0],
|
||||
["_Test Account Bank Account - _TC", 600.0, 0.0]
|
||||
@@ -383,6 +380,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEquals(expected_gl_entries[i][1], gle.debit)
|
||||
self.assertEquals(expected_gl_entries[i][2], gle.credit)
|
||||
|
||||
|
||||
|
||||
# cancel
|
||||
si.cancel()
|
||||
gle = webnotes.conn.sql("""select * from `tabGL Entry`
|
||||
@@ -390,12 +389,11 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
self.assertFalse(gle)
|
||||
|
||||
self.assertFalse(get_stock_and_account_difference([si.doclist[1].warehouse]))
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
|
||||
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
|
||||
webnotes.conn.set_default("company", old_default_company)
|
||||
|
||||
def atest_sales_invoice_gl_entry_with_aii_no_item_code(self):
|
||||
def test_sales_invoice_gl_entry_with_aii_no_item_code(self):
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
|
||||
|
||||
si_copy = webnotes.copy_doclist(test_records[1])
|
||||
@@ -422,7 +420,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 0)
|
||||
|
||||
def atest_sales_invoice_gl_entry_with_aii_non_stock_item(self):
|
||||
def test_sales_invoice_gl_entry_with_aii_non_stock_item(self):
|
||||
webnotes.defaults.set_global_default("auto_accounting_for_stock", 1)
|
||||
|
||||
si_copy = webnotes.copy_doclist(test_records[1])
|
||||
@@ -641,7 +639,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
return new_si
|
||||
|
||||
# if yearly, test 3 repetitions, else test 13 repetitions
|
||||
count = no_of_months == 12 and 3 or 13
|
||||
count = 3 if no_of_months == 12 else 13
|
||||
for i in xrange(count):
|
||||
base_si = _test(i)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-06-04 11:02:19",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-07-25 16:32:10",
|
||||
"modified": "2013-08-29 16:58:56",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -416,17 +416,6 @@
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "buying_amount",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Buying Amount",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"doctype": "DocField",
|
||||
|
||||
Reference in New Issue
Block a user