validation for stock and nonstock items in purchase cycle
This commit is contained in:
parent
794c098e55
commit
205f7ce620
@ -72,7 +72,38 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
["Stock Received But Not Billed - _TC", 750.0, 0],
|
["Stock Received But Not Billed - _TC", 750.0, 0],
|
||||||
["_Test Account Shipping Charges - _TC", 100.0, 0],
|
["_Test Account Shipping Charges - _TC", 100.0, 0],
|
||||||
["_Test Account VAT - _TC", 120.0, 0],
|
["_Test Account VAT - _TC", 120.0, 0],
|
||||||
["Expenses Included In Valuation - _TC", 0, 250.0]
|
["Expenses Included In Valuation - _TC", 0, 250.0],
|
||||||
|
])
|
||||||
|
|
||||||
|
for i, gle in enumerate(gl_entries):
|
||||||
|
self.assertEquals(expected_values[i][0], gle.account)
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
pi = webnotes.bean(copy=test_records[1])
|
||||||
|
pi.doclist[1].item_code = "_Test Non Stock Item"
|
||||||
|
pi.doclist[1].expense_head = "_Test Account Cost for Goods Sold - _TC"
|
||||||
|
pi.doclist.pop(2)
|
||||||
|
pi.doclist.pop(3)
|
||||||
|
pi.run_method("calculate_taxes_and_totals")
|
||||||
|
pi.insert()
|
||||||
|
pi.submit()
|
||||||
|
|
||||||
|
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||||
|
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
|
||||||
|
order by account asc""", pi.doc.name, as_dict=1)
|
||||||
|
self.assertTrue(gl_entries)
|
||||||
|
|
||||||
|
expected_values = sorted([
|
||||||
|
["_Test Supplier - _TC", 0, 620],
|
||||||
|
["_Test Account Cost for Goods Sold - _TC", 500.0, 0],
|
||||||
|
["_Test Account VAT - _TC", 120.0, 0],
|
||||||
])
|
])
|
||||||
|
|
||||||
for i, gle in enumerate(gl_entries):
|
for i, gle in enumerate(gl_entries):
|
||||||
@ -106,7 +137,6 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(tax.account_head, expected_values[i][0])
|
self.assertEqual(tax.account_head, expected_values[i][0])
|
||||||
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
||||||
self.assertEqual(tax.total, expected_values[i][2])
|
self.assertEqual(tax.total, expected_values[i][2])
|
||||||
# print tax.account_head, tax.tax_amount, tax.item_wise_tax_detail
|
|
||||||
|
|
||||||
expected_values = [
|
expected_values = [
|
||||||
["_Test Item Home Desktop 100", 90, 59],
|
["_Test Item Home Desktop 100", 90, 59],
|
||||||
@ -142,7 +172,6 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(tax.account_head, expected_values[i][0])
|
self.assertEqual(tax.account_head, expected_values[i][0])
|
||||||
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
||||||
self.assertEqual(tax.total, expected_values[i][2])
|
self.assertEqual(tax.total, expected_values[i][2])
|
||||||
# print tax.account_head, tax.tax_amount, tax.item_wise_tax_detail
|
|
||||||
|
|
||||||
expected_values = [
|
expected_values = [
|
||||||
["_Test FG Item", 90, 7059],
|
["_Test FG Item", 90, 7059],
|
||||||
|
@ -29,6 +29,7 @@ from controllers.stock_controller import StockController
|
|||||||
class BuyingController(StockController):
|
class BuyingController(StockController):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(BuyingController, self).validate()
|
super(BuyingController, self).validate()
|
||||||
|
self.validate_stock_or_nonstock_items()
|
||||||
if self.meta.get_field("currency"):
|
if self.meta.get_field("currency"):
|
||||||
self.company_currency = get_company_currency(self.doc.company)
|
self.company_currency = get_company_currency(self.doc.company)
|
||||||
self.validate_conversion_rate("currency", "conversion_rate")
|
self.validate_conversion_rate("currency", "conversion_rate")
|
||||||
@ -41,7 +42,24 @@ class BuyingController(StockController):
|
|||||||
|
|
||||||
# set total in words
|
# set total in words
|
||||||
self.set_total_in_words()
|
self.set_total_in_words()
|
||||||
|
|
||||||
|
def validate_stock_or_nonstock_items(self):
|
||||||
|
items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
|
||||||
|
if self.stock_items and len(items) > len(self.stock_items):
|
||||||
|
nonstock_items = list(set(items) - set(self.stock_items))
|
||||||
|
webnotes.msgprint(_("Stock and non-stock items can not be entered at the same ") +
|
||||||
|
self.doc.doctype + _(""". You should make separate documents for them.
|
||||||
|
Stock Items: """) + ", ".join(self.stock_items) + _("""
|
||||||
|
Non-stock Items: """) + ", ".join(nonstock_items), raise_exception=1)
|
||||||
|
|
||||||
|
elif items and not self.stock_items:
|
||||||
|
tax_for_valuation = [d.account_head for d in
|
||||||
|
self.doclist.get({"parentfield": "purchase_tax_details"})
|
||||||
|
if d.category in ["Valuation", "Valuation and Total"]]
|
||||||
|
if tax_for_valuation:
|
||||||
|
webnotes.msgprint(_("""Tax Category can not be 'Valuation' or 'Valuation and Total'
|
||||||
|
as all items are non-stock items"""), raise_exception=1)
|
||||||
|
|
||||||
def update_item_details(self):
|
def update_item_details(self):
|
||||||
for item in self.doclist.get({"parentfield": self.fname}):
|
for item in self.doclist.get({"parentfield": self.fname}):
|
||||||
ret = get_item_details({
|
ret = get_item_details({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user