mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
purchase invoice taxes and totals calculations with test cases
This commit is contained in:
@@ -32,7 +32,6 @@ class DocType(BuyingController):
|
||||
self.tname = 'Purchase Invoice Item'
|
||||
self.fname = 'entries'
|
||||
|
||||
|
||||
# ************************** Trigger Functions ****************************
|
||||
|
||||
# Credit To
|
||||
|
||||
@@ -19,154 +19,41 @@ from __future__ import unicode_literals
|
||||
import unittest
|
||||
import webnotes
|
||||
import webnotes.model
|
||||
from webnotes.utils import nowdate
|
||||
|
||||
from stock.doctype.purchase_receipt import test_purchase_receipt
|
||||
|
||||
company = webnotes.conn.get_default("company")
|
||||
abbr = webnotes.conn.get_value("Company", company, "abbr")
|
||||
|
||||
def load_data():
|
||||
test_purchase_receipt.load_data()
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "Cost for Goods Sold",
|
||||
"parent_account": "Expenses - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "Excise Duty",
|
||||
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "Education Cess",
|
||||
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess",
|
||||
"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "CST",
|
||||
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
webnotes.insert({"doctype": "Account", "account_name": "Discount",
|
||||
"parent_account": "Direct Expenses - %s" % abbr, "company": company,
|
||||
"group_or_ledger": "Ledger"})
|
||||
|
||||
from webnotes.model.doc import Document
|
||||
item = Document("Item", "Home Desktop 100")
|
||||
|
||||
# excise duty
|
||||
item_tax = item.addchild("item_tax", "Item Tax")
|
||||
item_tax.tax_type = "Excise Duty - %s" % abbr
|
||||
item_tax.tax_rate = 10
|
||||
item_tax.save()
|
||||
|
||||
import json
|
||||
purchase_invoice_doclist = [
|
||||
# parent
|
||||
{
|
||||
"doctype": "Purchase Invoice",
|
||||
"credit_to": "East Wind Inc. - %s" % abbr,
|
||||
"supplier_name": "East Wind Inc.",
|
||||
"naming_series": "BILL", "posting_date": nowdate(),
|
||||
"company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"),
|
||||
"currency": webnotes.conn.get_default("currency"), "conversion_rate": 1,
|
||||
'net_total': 1250.00, 'grand_total': 1512.30, 'grand_total_import': 1512.30,
|
||||
},
|
||||
# items
|
||||
{
|
||||
"doctype": "Purchase Invoice Item",
|
||||
"item_code": "Home Desktop 100", "qty": 10, "import_rate": 50, "rate": 50,
|
||||
"amount": 500, "import_amount": 500, "parentfield": "entries",
|
||||
"uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}),
|
||||
"expense_head": "Cost for Goods Sold - %s" % abbr,
|
||||
"cost_center": "Default Cost Center - %s" % abbr
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Invoice Item",
|
||||
"item_code": "Home Desktop 200", "qty": 5, "import_rate": 150, "rate": 150,
|
||||
"amount": 750, "import_amount": 750, "parentfield": "entries", "uom": "Nos",
|
||||
"expense_head": "Cost for Goods Sold - %s" % abbr,
|
||||
"cost_center": "Default Cost Center - %s" % abbr
|
||||
},
|
||||
# taxes
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "Actual",
|
||||
"account_head": "Shipping Charges - %s" % abbr, "rate": 100, "tax_amount": 100,
|
||||
"category": "Valuation and Total", "parentfield": "purchase_tax_details",
|
||||
"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
|
||||
"account_head": "Customs Duty - %s" % abbr, "rate": 10, "tax_amount": 125.00,
|
||||
"category": "Valuation", "parentfield": "purchase_tax_details",
|
||||
"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
|
||||
"account_head": "Excise Duty - %s" % abbr, "rate": 12, "tax_amount": 140.00,
|
||||
"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Amount",
|
||||
"account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 3, "tax_amount": 2.80,
|
||||
"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Amount",
|
||||
"account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 3,
|
||||
"tax_amount": 1.4, "category": "Total", "parentfield": "purchase_tax_details",
|
||||
"add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Total",
|
||||
"account_head": "CST - %s" % abbr, "rate": 2, "row_id": 5, "tax_amount": 29.88,
|
||||
"category": "Total", "parentfield": "purchase_tax_details",
|
||||
"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
|
||||
"account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "tax_amount": 156.25,
|
||||
"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
|
||||
},
|
||||
{
|
||||
"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Total",
|
||||
"account_head": "Discount - %s" % abbr, "rate": 10, "row_id": 7, "tax_amount": 168.03,
|
||||
"category": "Total", "parentfield": "purchase_tax_details",
|
||||
"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Deduct"
|
||||
},
|
||||
]
|
||||
|
||||
class TestPurchaseInvoice(unittest.TestCase):
|
||||
def setUp(self):
|
||||
webnotes.conn.begin()
|
||||
load_data()
|
||||
# webnotes.conn.set_value("Global Defaults", None, "automatic_inventory_accounting", 1)
|
||||
self.load_test_data()
|
||||
# webnotes.conn.set_value("Global Defaults", None,
|
||||
# "automatic_inventory_accounting", 1)
|
||||
|
||||
def tearDown(self):
|
||||
webnotes.conn.rollback()
|
||||
|
||||
def load_test_data(self):
|
||||
from webnotes.test_runner import make_test_records
|
||||
webnotes.test_objects = {}
|
||||
make_test_records("Cost Center", verbose=0)
|
||||
make_test_records("Item", verbose=0)
|
||||
make_test_records("Purchase Invoice", verbose=0)
|
||||
|
||||
def atest_gl_entries(self):
|
||||
wrapper = webnotes.model_wrapper(purchase_invoice_doclist).insert()
|
||||
def test_gl_entries(self):
|
||||
wrapper = webnotes.model_wrapper(self.get_test_doclist()).insert()
|
||||
wrapper.submit()
|
||||
wrapper.load_from_db()
|
||||
dl = wrapper.doclist
|
||||
|
||||
expected_gl_entries = {
|
||||
"East Wind Inc. - %s" % abbr : [0, 1512.30],
|
||||
"Cost for Goods Sold - %s" % abbr : [1250, 0],
|
||||
"Shipping Charges - %s" % abbr : [100, 0],
|
||||
"Excise Duty - %s" % abbr : [140, 0],
|
||||
"Education Cess - %s" % abbr : [2.8, 0],
|
||||
"S&H Education Cess - %s" % abbr : [1.4, 0],
|
||||
"CST - %s" % abbr : [29.88, 0],
|
||||
"VAT - Test - %s" % abbr : [156.25, 0],
|
||||
"Discount - %s" % abbr : [0, 168.03],
|
||||
"_Test Supplier - _TC": [0, 1512.30],
|
||||
"_Test Account Cost for Goods Sold - _TC": [1250, 0],
|
||||
"_Test Account Shipping Charges - _TC": [100, 0],
|
||||
"_Test Account Excise Duty - _TC": [140, 0],
|
||||
"_Test Account Education Cess - _TC": [2.8, 0],
|
||||
"_Test Account S&H Education Cess - _TC": [1.4, 0],
|
||||
"_Test Account CST - _TC": [29.88, 0],
|
||||
"_Test Account VAT - _TC": [156.25, 0],
|
||||
"_Test Account Discount - _TC": [0, 168.03],
|
||||
}
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit from `tabGL Entry`
|
||||
where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl[0].name, as_dict=1)
|
||||
@@ -174,7 +61,39 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
|
||||
|
||||
def test_purchase_invoice_calculation(self):
|
||||
test_doclist = [
|
||||
wrapper = webnotes.model_wrapper(self.get_test_doclist()).insert()
|
||||
wrapper.load_from_db()
|
||||
|
||||
self.assertEqual(wrapper.doclist[0].net_total, 1250)
|
||||
|
||||
# tax amounts
|
||||
expected_values = [
|
||||
["_Test Account Shipping Charges - _TC", 100, 1350],
|
||||
["_Test Account Customs Duty - _TC", 125, 1350],
|
||||
["_Test Account Excise Duty - _TC", 140, 1490],
|
||||
["_Test Account Education Cess - _TC", 2.8, 1492.8],
|
||||
["_Test Account S&H Education Cess - _TC", 1.4, 1494.2],
|
||||
["_Test Account CST - _TC", 29.88, 1524.08],
|
||||
["_Test Account VAT - _TC", 156.25, 1680.33],
|
||||
["_Test Account Discount - _TC", 168.03, 1512.30],
|
||||
]
|
||||
|
||||
for i, tax in enumerate(wrapper.doclist.get({"parentfield": "purchase_tax_details"})):
|
||||
self.assertEqual(tax.account_head, expected_values[i][0])
|
||||
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
||||
self.assertEqual(tax.total, expected_values[i][2])
|
||||
# print tax.account_head, tax.tax_amount, tax.item_wise_tax_detail
|
||||
|
||||
expected_values = [
|
||||
["_Test Item Home Desktop 100", 90],
|
||||
["_Test Item Home Desktop 200", 135]
|
||||
]
|
||||
for i, item in enumerate(wrapper.doclist.get({"parentfield": "entries"})):
|
||||
self.assertEqual(item.item_code, expected_values[i][0])
|
||||
self.assertEqual(item.item_tax_amount, expected_values[i][1])
|
||||
|
||||
def get_test_doclist(self):
|
||||
return [
|
||||
# parent
|
||||
{
|
||||
"doctype": "Purchase Invoice",
|
||||
@@ -183,7 +102,7 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
"credit_to": "_Test Supplier - _TC",
|
||||
"bill_no": "NA",
|
||||
"posting_date": "2013-02-03",
|
||||
"fiscal_year": "_Test Fiscal Year",
|
||||
"fiscal_year": "_Test Fiscal Year 2013",
|
||||
"company": "_Test Company",
|
||||
"currency": "INR",
|
||||
"conversion_rate": 1,
|
||||
@@ -199,7 +118,7 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
"import_rate": 50,
|
||||
"import_amount": 500,
|
||||
"rate": 50,
|
||||
"amount": 50,
|
||||
"amount": 500,
|
||||
"uom": "_Test UOM",
|
||||
"item_tax_rate": json.dumps({"_Test Account Excise Duty - _TC": 10}),
|
||||
"expense_head": "_Test Account Cost for Goods Sold - _TC",
|
||||
@@ -313,37 +232,4 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
"rate": 10,
|
||||
"row_id": 7
|
||||
},
|
||||
]
|
||||
|
||||
wrapper = webnotes.model_wrapper(test_doclist).insert()
|
||||
wrapper.load_from_db()
|
||||
|
||||
# tax amounts
|
||||
expected_values = [
|
||||
["_Test Account Shipping Charges - _TC", 100, 1350],
|
||||
["_Test Account Customs Duty - _TC", 125, 1350],
|
||||
["_Test Account Excise Duty - _TC", 140, 1490],
|
||||
["_Test Account Education Cess - _TC", 2.8, 1492.8],
|
||||
["_Test Account S&H Education Cess - _TC", 1.4, 1494.2],
|
||||
["_Test Account CST - _TC", 29.88, 1524.08],
|
||||
["_Test Account VAT - _TC", 156.25, 1680.33],
|
||||
["_Test Account Discount - _TC", 168.03, 1512.30],
|
||||
]
|
||||
|
||||
for i, tax in enumerate(wrapper.doclist.get({"parentfield": "purchase_tax_details"})):
|
||||
self.assertEqual(tax.account_head, expected_values[i][0])
|
||||
self.assertEqual(tax.tax_amount, expected_values[i][1])
|
||||
self.assertEqual(tax.total, expected_values[i][2])
|
||||
|
||||
expected_values = [
|
||||
["_Test Item Home Desktop 100", 90],
|
||||
["_Test Item Home Desktop 200", 135]
|
||||
]
|
||||
for i, item in enumerate(wrapper.doclist.get({"parentfield": "entries"})):
|
||||
self.assertEqual(item.item_code, expected_values[i][0])
|
||||
self.assertEqual(item.item_tax_amount, expected_values[i][1])
|
||||
|
||||
# self.assertEqual(dl[0].net_total, 1250)
|
||||
|
||||
def tearDown(self):
|
||||
webnotes.conn.rollback()
|
||||
]
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-01-28 10:05:58",
|
||||
"creation": "2013-01-29 20:53:00",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-01-29 16:28:04",
|
||||
"modified": "2013-02-08 14:06:17",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -268,6 +268,20 @@
|
||||
"read_only": 1,
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "item_tax_amount",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Item Tax Amount",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"print_width": "150px",
|
||||
"read_only": 1,
|
||||
"search_index": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"doctype": "DocField",
|
||||
|
||||
Reference in New Issue
Block a user