def load_data(): test_purchase_receipt.load_data() webnotes.insert({"doctype": "Account", "account_name": "Excise Duty", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Education Cess", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess", "parent_account": "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()
def create_custom_field(fld): fld.update({ "doctype": "Custom Field", "dt": "Stock Entry", "print_hide": 1, "permlevel": 0 }) from webnotes.model.doclist import DocList webnotes.insert(DocList([fld]))
def load_data(): test_purchase_receipt.load_data() webnotes.insert({ "doctype": "Account", "account_name": "Excise Duty", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "Education Cess", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "S&H Education Cess", "parent_account": "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()
def insert_test_data(self): # create default warehouse if not webnotes.conn.exists("Warehouse", "Default Warehouse"): webnotes.insert({"doctype": "Warehouse", "warehouse_name": "Default Warehouse", "warehouse_type": "Stores"}) # create UOM: Nos. if not webnotes.conn.exists("UOM", "Nos"): webnotes.insert({"doctype": "UOM", "uom_name": "Nos"}) # create item groups and items insert_test_data("Item Group", sort_fn=lambda ig: (ig[0].get('parent_item_group'), ig[0].get('name'))) insert_test_data("Item")
def run_purchase_receipt_test(self, purchase_receipt, debit_account, credit_account, stock_value): from webnotes.model.doclist import DocList dl = webnotes.insert(DocList(purchase_receipt)) from controllers.tax_controller import TaxController tax_controller = TaxController(dl.doc, dl.doclist) tax_controller.item_table_field = "purchase_receipt_details" tax_controller.calculate_taxes_and_totals() dl.doc = tax_controller.doc dl.doclist = tax_controller.doclist dl.submit() dl.load_from_db() gle = webnotes.conn.sql( """select account, ifnull(debit, 0), ifnull(credit, 0) from `tabGL Entry` where voucher_no = %s""", dl.doclist[0].name) gle_map = dict(((entry[0], entry) for entry in gle)) self.assertEquals(gle_map[debit_account], (debit_account, stock_value, 0.0)) self.assertEquals(gle_map[credit_account], (credit_account, 0.0, stock_value))
def atest_gl_entries(self): from webnotes.model.doclist import DocList controller = webnotes.insert(DocList(purchase_invoice_doclist)) from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.submit() controller.load_from_db() dl = controller.doclist expected_values = { "East Wind Inc. - %s" % abbr : [0, 1512.30], "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], "Stock Received But Not Billed - %s" % abbr : [1475, 0], "Expenses Included In Valuation - %s" % abbr : [0, 225] } 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) for d in gl_entries: self.assertEqual(d["debit"], expected_values.get(d['account'])[0]) self.assertEqual(d["credit"], expected_values.get(d['account'])[1])
def test_bom(self): gc_wrapper = webnotes.insert(DocList(base_bom_grandchild)) gc_wrapper.submit() bom_child = copy.deepcopy(base_bom_child) bom_child[2]["bom_no"] = gc_wrapper.doc.name child_wrapper = webnotes.insert(DocList(bom_child)) child_wrapper.submit() bom_fg = copy.deepcopy(base_bom_fg) bom_fg[4]["bom_no"] = child_wrapper.doc.name fg_wrapper = webnotes.insert(DocList(bom_fg)) fg_wrapper.load_from_db() self.check_bom_cost(fg_wrapper) self.check_flat_bom(fg_wrapper, child_wrapper, gc_wrapper)
def insert_accounts(): for d in webnotes.conn.sql("""select name, abbr from tabCompany""", as_dict=1): acc_list = [ make_account_dict('Stock Assets', 'Current Assets', d, 'Group'), make_account_dict('Stock In Hand', 'Stock Assets', d, 'Ledger'), make_account_dict('Stock Delivered But Not Billed', 'Stock Assets', d, 'Ledger'), make_account_dict('Stock Liabilities', 'Current Liabilities', d, 'Group'), make_account_dict('Stock Received But Not Billed', 'Stock Liabilities', d, 'Ledger'), make_account_dict('Stock Expenses', 'Direct Expenses', d, 'Group'), make_account_dict('Stock Variance', 'Stock Expenses', d, 'Ledger'), make_account_dict('Expenses Included In Valuation', 'Stock Expenses', d, 'Ledger'), ] for acc in acc_list: acc_name = "%s - %s" % (acc['account_name'], d['abbr']) if not webnotes.conn.exists('Account', acc_name): webnotes.insert(acc)
def insert_test_data(self): # create default warehouse if not webnotes.conn.exists("Warehouse", "Default Warehouse"): webnotes.insert({ "doctype": "Warehouse", "warehouse_name": "Default Warehouse", "warehouse_type": "Stores" }) # create UOM: Nos. if not webnotes.conn.exists("UOM", "Nos"): webnotes.insert({"doctype": "UOM", "uom_name": "Nos"}) # create item groups and items insert_test_data("Item Group", sort_fn=lambda ig: (ig[0].get('parent_item_group'), ig[0].get('name'))) insert_test_data("Item")
def test_purchase_invoice_having_zero_amount_items(self): from webnotes.model.doclist import DocList sample_purchase_invoice_doclist = [] + purchase_invoice_doclist # set rate and amount as 0 sample_purchase_invoice_doclist[1]["import_rate"] = 0 sample_purchase_invoice_doclist[2]["import_rate"] = 0 controller = webnotes.insert(DocList(sample_purchase_invoice_doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 0) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 100], ["Customs Duty - %s" % abbr, 0, 100], ["Excise Duty - %s" % abbr, 0, 100], ["Education Cess - %s" % abbr, 0, 100], ["S&H Education Cess - %s" % abbr, 0, 100], ["CST - %s" % abbr, 2, 102], ["VAT - Test - %s" % abbr, 0, 102], ["Discount - %s" % abbr, -10.2, 91.8], ] for i, tax in enumerate(dl.get({"parentfield": "purchase_tax_details"})): # print tax.account_head, tax.tax_amount, tax.total 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]) # test item tax amount expected_values = [ ["Home Desktop 100", 0], ["Home Desktop 200", 0] ] for i, item in enumerate(dl.get({"parentfield": "purchase_invoice_items"})): self.assertEqual(item.item_code, expected_values[i][0]) self.assertEqual(item.item_tax_amount, expected_values[i][1])
def run_purchase_receipt_test(self, purchase_receipt, debit_account, credit_account, stock_value): from webnotes.model.doclist import DocList dl = webnotes.insert(DocList(purchase_receipt)) dl.submit() dl.load_from_db() gle = webnotes.conn.sql("""select account, ifnull(debit, 0), ifnull(credit, 0) from `tabGL Entry` where voucher_no = %s""", dl.doclist[0].name) gle_map = dict(((entry[0], entry) for entry in gle)) self.assertEquals(gle_map[debit_account], (debit_account, stock_value, 0.0)) self.assertEquals(gle_map[credit_account], (credit_account, 0.0, stock_value))
def test_purchase_invoice_having_zero_amount_items(self): from webnotes.model.doclist import DocList sample_purchase_invoice_doclist = [] + purchase_invoice_doclist # set rate and amount as 0 sample_purchase_invoice_doclist[1]["import_rate"] = 0 sample_purchase_invoice_doclist[2]["import_rate"] = 0 controller = webnotes.insert(DocList(sample_purchase_invoice_doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 0) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 100], ["Customs Duty - %s" % abbr, 0, 100], ["Excise Duty - %s" % abbr, 0, 100], ["Education Cess - %s" % abbr, 0, 100], ["S&H Education Cess - %s" % abbr, 0, 100], ["CST - %s" % abbr, 2, 102], ["VAT - Test - %s" % abbr, 0, 102], ["Discount - %s" % abbr, -10.2, 91.8], ] for i, tax in enumerate(dl.get({"parentfield": "purchase_tax_details"})): # print tax.account_head, tax.tax_amount, tax.total 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]) # test item tax amount expected_values = [["Home Desktop 100", 0], ["Home Desktop 200", 0]] for i, item in enumerate( dl.get({"parentfield": "purchase_invoice_items"})): self.assertEqual(item.item_code, expected_values[i][0]) self.assertEqual(item.item_tax_amount, expected_values[i][1])
def insert_accounts(): for d in webnotes.conn.sql("""select name, abbr from tabCompany""", as_dict=1): acc_list = [ make_account_dict('Stock Assets', 'Current Assets', d, 'Group'), make_account_dict('Stock In Hand', 'Stock Assets', d, 'Ledger'), make_account_dict('Stock Delivered But Not Billed', 'Stock Assets', d, 'Ledger'), make_account_dict('Stock Liabilities', 'Current Liabilities', d, 'Group'), make_account_dict('Stock Received But Not Billed', 'Stock Liabilities', d, 'Ledger'), make_account_dict('Stock Expenses', 'Direct Expenses', d, 'Group'), make_account_dict('Stock Variance', 'Stock Expenses', d, 'Ledger'), make_account_dict('Expenses Included In Valuation', 'Stock Expenses', d, 'Ledger'), ] for acc in acc_list: acc_name = "%s - %s" % (acc['account_name'], d['abbr']) if not webnotes.conn.exists('Account', acc_name): webnotes.insert(acc) else: print "Account %s already exists" % acc_name
def run_purchase_receipt_test(self, purchase_receipt, debit_account, credit_account, stock_value): from webnotes.model.doclist import DocList dl = webnotes.insert(DocList(purchase_receipt)) dl.submit() dl.load_from_db() gle = webnotes.conn.sql( """select account, ifnull(debit, 0), ifnull(credit, 0) from `tabGL Entry` where voucher_no = %s""", dl.doclist[0].name) gle_map = dict(((entry[0], entry) for entry in gle)) self.assertEquals(gle_map[debit_account], (debit_account, stock_value, 0.0)) self.assertEquals(gle_map[credit_account], (credit_account, 0.0, stock_value))
def test_purchase_invoice(self): from webnotes.model.doclist import DocList controller = webnotes.insert(DocList(purchase_invoice_doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 1250) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 1350], ["Customs Duty - %s" % abbr, 125, 1350], ["Excise Duty - %s" % abbr, 140, 1490], ["Education Cess - %s" % abbr, 2.8, 1492.8], ["S&H Education Cess - %s" % abbr, 1.4, 1494.2], ["CST - %s" % abbr, 29.88, 1524.08], ["VAT - Test - %s" % abbr, 156.25, 1680.33], ["Discount - %s" % abbr, -168.03, 1512.30], ] for i, tax in enumerate(dl.get({"parentfield": "purchase_tax_details"})): # print tax.account_head, tax.tax_amount, tax.total 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]) # test item tax amount expected_values = [ ["Home Desktop 100", 90], ["Home Desktop 200", 135] ] for i, item in enumerate(dl.get({"parentfield": "purchase_invoice_items"})): self.assertEqual(item.item_code, expected_values[i][0]) self.assertEqual(item.item_tax_amount, expected_values[i][1])
def test_purchase_invoice(self): from webnotes.model.doclist import DocList controller = webnotes.insert(DocList(purchase_invoice_doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 1250) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 1350], ["Customs Duty - %s" % abbr, 125, 1350], ["Excise Duty - %s" % abbr, 140, 1490], ["Education Cess - %s" % abbr, 2.8, 1492.8], ["S&H Education Cess - %s" % abbr, 1.4, 1494.2], ["CST - %s" % abbr, 29.88, 1524.08], ["VAT - Test - %s" % abbr, 156.25, 1680.33], ["Discount - %s" % abbr, -168.03, 1512.30], ] for i, tax in enumerate(dl.get({"parentfield": "purchase_tax_details"})): # print tax.account_head, tax.tax_amount, tax.total 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]) # test item tax amount expected_values = [["Home Desktop 100", 90], ["Home Desktop 200", 135]] for i, item in enumerate( dl.get({"parentfield": "purchase_invoice_items"})): self.assertEqual(item.item_code, expected_values[i][0]) self.assertEqual(item.item_tax_amount, expected_values[i][1])
def run_purchase_receipt_test(self, purchase_receipt, debit_account, credit_account, stock_value): dl = webnotes.insert(DocList(purchase_receipt)) from controllers.tax_controller import TaxController tax_controller = TaxController(dl.doc, dl.doclist) tax_controller.item_table_field = "purchase_receipt_details" tax_controller.calculate_taxes_and_totals() dl.doc = tax_controller.doc dl.doclist = tax_controller.doclist dl.submit() dl.load_from_db() gle = webnotes.conn.sql("""select account, ifnull(debit, 0), ifnull(credit, 0) from `tabGL Entry` where voucher_no = %s""", dl.doclist[0].name) gle_map = dict(((entry[0], entry) for entry in gle)) self.assertEquals(gle_map[debit_account], (debit_account, stock_value, 0.0)) self.assertEquals(gle_map[credit_account], (credit_account, 0.0, stock_value))
def atest_gl_entries(self): from webnotes.model.doclist import DocList controller = webnotes.insert(DocList(purchase_invoice_doclist)) from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.submit() controller.load_from_db() dl = controller.doclist expected_values = { "East Wind Inc. - %s" % abbr: [0, 1512.30], "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], "Stock Received But Not Billed - %s" % abbr: [1475, 0], "Expenses Included In Valuation - %s" % abbr: [0, 225] } 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) for d in gl_entries: self.assertEqual(d["debit"], expected_values.get(d['account'])[0]) self.assertEqual(d["credit"], expected_values.get(d['account'])[1])
def test_sales_invoice(self): doclist = [] + [d.copy() for d in sales_invoice_doclist] controller = webnotes.insert(DocList(doclist)) controller.submit() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 1250) # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", # "ref_rate": 50, # "adj_rate": 0, # "export_amount": 500, # "base_ref_rate": 50, "basic_rate": 50, "amount": 500 }, { "item_code": "Home Desktop 200", # "ref_rate": 150, # "adj_rate": 0, # "export_amount": 750, # "base_ref_rate": 150, "basic_rate": 150, "amount": 750 }, ] for i, item in enumerate(dl.get({"parentfield": "entries"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 1350], ["Customs Duty - %s" % abbr, 125, 1475], ["Excise Duty - %s" % abbr, 140, 1615], ["Education Cess - %s" % abbr, 2.8, 1617.8], ["S&H Education Cess - %s" % abbr, 1.4, 1619.2], ["CST - %s" % abbr, 32.38, 1651.58], ["VAT - Test - %s" % abbr, 156.25, 1807.83], ["adj_rate - %s" % abbr, -180.78, 1627.05], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total 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_gl_entries = { "West Wind Inc. - %s" % abbr : [1627.05, 0.0], "_Test Account Sales - %s" % abbr: [0.0, 1250.00], "Shipping Charges - %s" % abbr: [0.0, 100], "Customs Duty - %s" % abbr: [0, 125.0], "Excise Duty - %s" % abbr: [0, 140], "Education Cess - %s" % abbr: [0, 2.8], "S&H Education Cess - %s" % abbr: [0, 1.4], "CST - %s" % abbr: [0, 32.38], "VAT - Test - %s" % abbr: [0, 156.25], "adj_rate - %s" % abbr: [180.78, 0], } gl_entries = webnotes.conn.sql("""select account, debit, credit from `tabGL Entry` where voucher_type = %s and voucher_no = %s""", (controller.doc.doctype, controller.doc.name), as_dict=1) for gle in gl_entries: self.assertEqual([gle.debit, gle.credit], expected_gl_entries[gle.account])
def load_data(): insert_accounts() # create default warehouse if not webnotes.conn.exists("Warehouse", "Default Warehouse"): webnotes.insert({"doctype": "Warehouse", "warehouse_name": "Default Warehouse", "warehouse_type": "Stores"}) # create UOM: Nos. if not webnotes.conn.exists("UOM", "Nos"): webnotes.insert({"doctype": "UOM", "uom_name": "Nos"}) from webnotes.tests import insert_test_data # create item groups and items insert_test_data("Item Group", sort_fn=lambda ig: (ig[0].get('parent_item_group'), ig[0].get('name'))) insert_test_data("Item") # create supplier type webnotes.insert({"doctype": "Supplier Type", "supplier_type": "Manufacturing"}) # create supplier webnotes.insert({"doctype": "Supplier", "supplier_name": "East Wind Inc.", "supplier_type": "Manufacturing", "company": company}) # create default cost center if not exists if not webnotes.conn.exists("Cost Center", "Default Cost Center - %s" % abbr): webnotes.insert({"doctype": "Cost Center", "group_or_ledger": "Ledger", "cost_center_name": "Default Cost Center", "parent_cost_center": "Root - %s" % abbr, "company_name": company}) # create account heads for taxes webnotes.insert({"doctype": "Account", "account_name": "Shipping Charges", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Customs Duty", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "_Test Tax Assets", "parent_account": "Current Assets - %s" % abbr, "company": company, "group_or_ledger": "Group"}) webnotes.insert({"doctype": "Account", "account_name": "VAT - Test", "parent_account": "_Test Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"})
def test_sales_invoice(self): from webnotes.model.doclist import DocList doclist = [] + [d.copy() for d in sales_invoice_doclist] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 1250) # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 50, "adj_rate": 0, "export_amount": 500, "base_ref_rate": 50, "basic_rate": 50, "amount": 500, }, { "item_code": "Home Desktop 200", "ref_rate": 150, "adj_rate": 0, "export_amount": 750, "base_ref_rate": 150, "basic_rate": 150, "amount": 750, }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 1350], ["Customs Duty - %s" % abbr, 125, 1475], ["Excise Duty - %s" % abbr, 140, 1615], ["Education Cess - %s" % abbr, 2.8, 1617.8], ["S&H Education Cess - %s" % abbr, 1.4, 1619.2], ["CST - %s" % abbr, 32.38, 1651.58], ["VAT - Test - %s" % abbr, 156.25, 1807.83], ["adj_rate - %s" % abbr, -180.78, 1627.05], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total 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])
def test_sales_invoice_with_inclusive_tax(self): doclist = [ # parent { "doctype": "Sales Invoice", "debit_to": "West Wind Inc. - %s" % abbr, "customer_name": "West Wind Inc.", "naming_series": "INV", "posting_date": nowdate(), "company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"), "currency": webnotes.conn.get_default("currency"), "price_list_currency": webnotes.conn.get_default("currency"), "conversion_rate": 1.0, "plc_conversion_rate": 1.0, "grand_total_export": 0, }, # items { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 100", "qty": 10, "export_rate": 62.503, "parentfield": "sales_invoice_items", "uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}), }, { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 200", "qty": 5, "export_rate": 190.6608, "parentfield": "sales_invoice_items", "uom": "Nos", }, # taxes { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Excise Duty - %s" % abbr, "rate": 12, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "CST - %s" % abbr, "rate": 2, "row_id": 3, "parentfield": "other_charges", "included_in_print_rate": 1, "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Customs Duty - %s" % abbr, "rate": 10, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "Actual", "account_head": "Shipping Charges - %s" % abbr, "rate": 100, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "adj_rate - %s" % abbr, "rate": -10, "row_id": 7, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, ] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 62.503, "adj_rate": 0, "export_amount": 625.03, "base_ref_rate": 50, "basic_rate": 50, "amount": 500, }, { "item_code": "Home Desktop 200", "ref_rate": 190.6608, "adj_rate": 0, "export_amount": 953.3, "base_ref_rate": 150, "basic_rate": 150, "amount": 750, }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Excise Duty - %s" % abbr, 140, 1390, 0, 1578.33], ["Education Cess - %s" % abbr, 2.8, 1392.8, 0, 1578.33], ["S&H Education Cess - %s" % abbr, 1.4, 1394.2, 0, 1578.33], ["CST - %s" % abbr, 27.88, 1422.08, 0, 1578.33], ["VAT - Test - %s" % abbr, 156.25, 1578.33, 0, 1578.33], ["Customs Duty - %s" % abbr, 125, 1703.33, 125, 1703.33], ["Shipping Charges - %s" % abbr, 100, 1803.33, 100, 1803.33], ["adj_rate - %s" % abbr, -180.33, 1623, -180.33, 1623], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total, tax.tax_amount_print, \ # tax.total_print 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]) # self.assertEqual(tax.tax_amount_print, expected_values[i][3]) self.assertEqual(tax.total_print, expected_values[i][4]) # test net total self.assertEqual(dl[0].net_total, 1250) self.assertEqual(dl[0].net_total_print, 1578.33) # # test grand total self.assertEqual(dl[0].grand_total, 1623) self.assertEqual(dl[0].grand_total_export, 1623)
def test_usd_sales_invoice_with_inclusive_tax(self): # print # print "-"*80 # print "test_usd_sales_invoice_with_inclusive_tax" # print "-"*80 # Note: below values were obtained through manual calculation and verified by test doclist = [ # parent { "doctype": "Sales Invoice", "debit_to": "West Wind Inc. - %s" % abbr, "customer_name": "West Wind Inc.", "naming_series": "INV", "posting_date": nowdate(), "company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"), "currency": "USD", "price_list_currency": "USD", "conversion_rate": 50.0, "plc_conversion_rate": 50.0, "grand_total_export": 0 }, # items { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 100", "qty": 10, "export_rate": 50, "adj_rate": 10, "parentfield": "sales_invoice_items", "uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}) }, { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 200", "qty": 5, "export_rate": 150, "adj_rate": 20, "parentfield": "sales_invoice_items", "uom": "Nos" }, # taxes { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Excise Duty - %s" % abbr, "rate": 12, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "CST - %s" % abbr, "rate": 2, "row_id": 3, "parentfield": "other_charges", "included_in_print_rate": 1, "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Customs Duty - %s" % abbr, "rate": 10, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "Actual", "account_head": "Shipping Charges - %s" % abbr, "rate": 100, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "adj_rate - %s" % abbr, "rate": -10, "row_id": 7, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, ] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 55.5556, "adj_rate": 10, "export_amount": 500, "base_ref_rate": 2222.1156, "basic_rate": 1999.904, "amount": 19999.04 }, { "item_code": "Home Desktop 200", "ref_rate": 187.5, "adj_rate": 20, "export_amount": 750, "base_ref_rate": 7375.664, "basic_rate": 5900.5312, "amount": 29502.66 }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Excise Duty - %s" % abbr, 5540.22, 55041.92, 0, 1250], ["Education Cess - %s" % abbr, 110.81, 55152.73, 0, 1250], ["S&H Education Cess - %s" % abbr, 55.4, 55208.13, 0, 1250], ["CST - %s" % abbr, 1104.16, 56312.29, 0, 1250], ["VAT - Test - %s" % abbr, 6187.71, 62500, 0, 1250], ["Customs Duty - %s" % abbr, 4950.17, 67450.17, 99.01, 1349.01], ["Shipping Charges - %s" % abbr, 5000, 72450.17, 100, 1449.01], ["adj_rate - %s" % abbr, -7245.01, 65205.16, -144.9, 1304.11], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total, tax.tax_amount_print, \ # tax.total_print 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]) # self.assertEqual(tax.tax_amount_print, expected_values[i][3]) self.assertEqual(tax.total_print, expected_values[i][4]) # test net total self.assertEqual(dl[0].net_total, 49501.7) self.assertEqual(dl[0].net_total_print, 1250) # # test grand total self.assertEqual(dl[0].grand_total, 65205.16) self.assertEqual(dl[0].grand_total_export, 1304.11)
def load_data(): test_purchase_receipt.load_data() # create customer group webnotes.insert({ "doctype": "Customer Group", "customer_group_name": "Default Customer Group", "parent_customer_group": "All Customer Groups", "is_group": "No" }) # create customer webnotes.insert({ "doctype": "Customer", "customer_name": "West Wind Inc.", "customer_type": "Company", "territory": "Default", "customer_group": "Default Customer Group", "company": company, "credit_days": 0, "credit_limit": 0 }) webnotes.insert({ "doctype": "Account", "account_name": "Excise Duty", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "Education Cess", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "S&H Education Cess", "parent_account": "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": "adj_rate", "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()
def test_sales_invoice_with_inclusive_tax(self): doclist = [ # parent { "doctype": "Sales Invoice", "debit_to": "West Wind Inc. - %s" % abbr, "customer_name": "West Wind Inc.", "naming_series": "INV", "posting_date": nowdate(), "company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"), "currency": webnotes.conn.get_default("currency"), "price_list_currency": webnotes.conn.get_default("currency"), "conversion_rate": 1.0, "plc_conversion_rate": 1.0, "grand_total_export": 0 }, # items { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 100", "qty": 10, "export_rate": 62.503, "parentfield": "sales_invoice_items", "uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}) }, { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 200", "qty": 5, "export_rate": 190.6608, "parentfield": "sales_invoice_items", "uom": "Nos" }, # taxes { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Excise Duty - %s" % abbr, "rate": 12, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "CST - %s" % abbr, "rate": 2, "row_id": 3, "parentfield": "other_charges", "included_in_print_rate": 1, "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "parentfield": "other_charges", "included_in_print_rate": 1 }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Customs Duty - %s" % abbr, "rate": 10, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "Actual", "account_head": "Shipping Charges - %s" % abbr, "rate": 100, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "adj_rate - %s" % abbr, "rate": -10, "row_id": 7, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr }, ] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 62.503, "adj_rate": 0, "export_amount": 625.03, "base_ref_rate": 50, "basic_rate": 50, "amount": 500 }, { "item_code": "Home Desktop 200", "ref_rate": 190.6608, "adj_rate": 0, "export_amount": 953.3, "base_ref_rate": 150, "basic_rate": 150, "amount": 750 }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Excise Duty - %s" % abbr, 140, 1390, 0, 1578.33], ["Education Cess - %s" % abbr, 2.8, 1392.8, 0, 1578.33], ["S&H Education Cess - %s" % abbr, 1.4, 1394.2, 0, 1578.33], ["CST - %s" % abbr, 27.88, 1422.08, 0, 1578.33], ["VAT - Test - %s" % abbr, 156.25, 1578.33, 0, 1578.33], ["Customs Duty - %s" % abbr, 125, 1703.33, 125, 1703.33], ["Shipping Charges - %s" % abbr, 100, 1803.33, 100, 1803.33], ["adj_rate - %s" % abbr, -180.33, 1623, -180.33, 1623], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total, tax.tax_amount_print, \ # tax.total_print 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]) # self.assertEqual(tax.tax_amount_print, expected_values[i][3]) self.assertEqual(tax.total_print, expected_values[i][4]) # test net total self.assertEqual(dl[0].net_total, 1250) self.assertEqual(dl[0].net_total_print, 1578.33) # # test grand total self.assertEqual(dl[0].grand_total, 1623) self.assertEqual(dl[0].grand_total_export, 1623)
def test_sales_invoice(self): from webnotes.model.doclist import DocList doclist = [] + [d.copy() for d in sales_invoice_doclist] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test net total self.assertEqual(dl[0].net_total, 1250) # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 50, "adj_rate": 0, "export_amount": 500, "base_ref_rate": 50, "basic_rate": 50, "amount": 500 }, { "item_code": "Home Desktop 200", "ref_rate": 150, "adj_rate": 0, "export_amount": 750, "base_ref_rate": 150, "basic_rate": 150, "amount": 750 }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Shipping Charges - %s" % abbr, 100, 1350], ["Customs Duty - %s" % abbr, 125, 1475], ["Excise Duty - %s" % abbr, 140, 1615], ["Education Cess - %s" % abbr, 2.8, 1617.8], ["S&H Education Cess - %s" % abbr, 1.4, 1619.2], ["CST - %s" % abbr, 32.38, 1651.58], ["VAT - Test - %s" % abbr, 156.25, 1807.83], ["adj_rate - %s" % abbr, -180.78, 1627.05], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total 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])
def load_data(): insert_accounts() # create default warehouse if not webnotes.conn.exists("Warehouse", "Default Warehouse"): webnotes.insert({ "doctype": "Warehouse", "warehouse_name": "Default Warehouse", "warehouse_type": "Stores" }) # create UOM: Nos. if not webnotes.conn.exists("UOM", "Nos"): webnotes.insert({"doctype": "UOM", "uom_name": "Nos"}) from webnotes.tests import insert_test_data # create item groups and items insert_test_data("Item Group", sort_fn=lambda ig: (ig[0].get('parent_item_group'), ig[0].get('name'))) insert_test_data("Item") # create supplier type webnotes.insert({ "doctype": "Supplier Type", "supplier_type": "Manufacturing" }) # create supplier webnotes.insert({ "doctype": "Supplier", "supplier_name": "East Wind Inc.", "supplier_type": "Manufacturing", "company": company }) # create default cost center if not exists if not webnotes.conn.exists("Cost Center", "Default Cost Center - %s" % abbr): dl = webnotes.insert({ "doctype": "Cost Center", "group_or_ledger": "Ledger", "cost_center_name": "Default Cost Center", "parent_cost_center": "Root - %s" % abbr, "company_name": company, "company_abbr": abbr }) # create account heads for taxes webnotes.insert({ "doctype": "Account", "account_name": "Shipping Charges", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "Customs Duty", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) webnotes.insert({ "doctype": "Account", "account_name": "Tax Assets", "parent_account": "Current Assets - %s" % abbr, "company": company, "group_or_ledger": "Group" }) webnotes.insert({ "doctype": "Account", "account_name": "VAT - Test", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger" }) # create BOM webnotes.insert([{ "doctype": "BOM", "item": "Nebula 7", "quantity": 1, "is_active": "Yes", "is_default": 1, "uom": "Nos" }, { "doctype": "BOM Operation", "operation_no": 1, "parentfield": "bom_operations", "opn_description": "Development" }, { "doctype": "BOM Item", "item_code": "Android Jack D", "operation_no": 1, "qty": 5, "rate": 20, "amount": 100, "stock_uom": "Nos", "parentfield": "bom_materials" }])
def test_usd_sales_invoice_with_inclusive_tax(self): # print # print "-"*80 # print "test_usd_sales_invoice_with_inclusive_tax" # print "-"*80 # Note: below values were obtained through manual calculation and verified by test doclist = [ # parent { "doctype": "Sales Invoice", "debit_to": "West Wind Inc. - %s" % abbr, "customer_name": "West Wind Inc.", "naming_series": "INV", "posting_date": nowdate(), "company": company, "fiscal_year": webnotes.conn.get_default("fiscal_year"), "currency": "USD", "price_list_currency": "USD", "conversion_rate": 50.0, "plc_conversion_rate": 50.0, "grand_total_export": 0, }, # items { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 100", "qty": 10, "export_rate": 50, "adj_rate": 10, "parentfield": "sales_invoice_items", "uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}), }, { "doctype": "Sales Invoice Item", "warehouse": "Default Warehouse", "item_code": "Home Desktop 200", "qty": 5, "export_rate": 150, "adj_rate": 20, "parentfield": "sales_invoice_items", "uom": "Nos", }, # taxes { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Excise Duty - %s" % abbr, "rate": 12, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Amount", "account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 1, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "CST - %s" % abbr, "rate": 2, "row_id": 3, "parentfield": "other_charges", "included_in_print_rate": 1, "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "parentfield": "other_charges", "included_in_print_rate": 1, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Net Total", "account_head": "Customs Duty - %s" % abbr, "rate": 10, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "Actual", "account_head": "Shipping Charges - %s" % abbr, "rate": 100, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, { "doctype": "Sales Taxes and Charges", "charge_type": "On Previous Row Total", "account_head": "adj_rate - %s" % abbr, "rate": -10, "row_id": 7, "parentfield": "other_charges", "cost_center_other_charges": "Default Cost Center - %s" % abbr, }, ] controller = webnotes.insert(DocList(doclist)) controller.load_from_db() from controllers.tax_controller import TaxController tax_controller = TaxController(controller.doc, controller.doclist) tax_controller.item_table_field = "entries" tax_controller.calculate_taxes_and_totals() controller.doc = tax_controller.doc controller.doclist = tax_controller.doclist controller.save() controller.load_from_db() dl = controller.doclist # test item values calculation expected_values = [ { "item_code": "Home Desktop 100", "ref_rate": 55.5556, "adj_rate": 10, "export_amount": 500, "base_ref_rate": 2222.1156, "basic_rate": 1999.904, "amount": 19999.04, }, { "item_code": "Home Desktop 200", "ref_rate": 187.5, "adj_rate": 20, "export_amount": 750, "base_ref_rate": 7375.664, "basic_rate": 5900.5312, "amount": 29502.66, }, ] for i, item in enumerate(dl.get({"parentfield": "sales_invoice_items"})): for key, val in expected_values[i].items(): self.assertEqual(item.fields.get(key), val) # test tax amounts and totals expected_values = [ ["Excise Duty - %s" % abbr, 5540.22, 55041.92, 0, 1250], ["Education Cess - %s" % abbr, 110.81, 55152.73, 0, 1250], ["S&H Education Cess - %s" % abbr, 55.4, 55208.13, 0, 1250], ["CST - %s" % abbr, 1104.16, 56312.29, 0, 1250], ["VAT - Test - %s" % abbr, 6187.71, 62500, 0, 1250], ["Customs Duty - %s" % abbr, 4950.17, 67450.17, 99.01, 1349.01], ["Shipping Charges - %s" % abbr, 5000, 72450.17, 100, 1449.01], ["adj_rate - %s" % abbr, -7245.01, 65205.16, -144.9, 1304.11], ] for i, tax in enumerate(dl.get({"parentfield": "other_charges"})): # print tax.account_head, tax.tax_amount, tax.total, tax.tax_amount_print, \ # tax.total_print 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]) # self.assertEqual(tax.tax_amount_print, expected_values[i][3]) self.assertEqual(tax.total_print, expected_values[i][4]) # test net total self.assertEqual(dl[0].net_total, 49501.7) self.assertEqual(dl[0].net_total_print, 1250) # # test grand total self.assertEqual(dl[0].grand_total, 65205.16) self.assertEqual(dl[0].grand_total_export, 1304.11)
def load_data(): test_purchase_receipt.load_data() # create customer group webnotes.insert({"doctype": "Customer Group", "customer_group_name": "_Test Customer Group", "parent_customer_group": "All Customer Groups", "is_group": "No"}) # create customer webnotes.insert({"doctype": "Customer", "customer_name": "West Wind Inc.", "customer_type": "Company", "territory": "Default", "customer_group": "_Test Customer Group", "company": company, "credit_days": 50, "credit_limit": 0}) webnotes.insert({"doctype": "Account", "account_name": "_Test Account Sales", "parent_account": "Income - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Excise Duty", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Education Cess", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess", "parent_account": "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": "adj_rate", "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()
def load_data(): insert_accounts() # create default warehouse if not webnotes.conn.exists("Warehouse", "Default Warehouse"): webnotes.insert({"doctype": "Warehouse", "warehouse_name": "Default Warehouse", "warehouse_type": "Stores"}) # create UOM: Nos. if not webnotes.conn.exists("UOM", "Nos"): webnotes.insert({"doctype": "UOM", "uom_name": "Nos"}) from webnotes.tests import insert_test_data # create item groups and items insert_test_data("Item Group", sort_fn=lambda ig: (ig[0].get('parent_item_group'), ig[0].get('name'))) insert_test_data("Item") # create supplier type webnotes.insert({"doctype": "Supplier Type", "supplier_type": "Manufacturing"}) # create supplier webnotes.insert({"doctype": "Supplier", "supplier_name": "East Wind Inc.", "supplier_type": "Manufacturing", "company": company}) # create default cost center if not exists if not webnotes.conn.exists("Cost Center", "Default Cost Center - %s" % abbr): dl = webnotes.insert({"doctype": "Cost Center", "group_or_ledger": "Ledger", "cost_center_name": "Default Cost Center", "parent_cost_center": "Root - %s" % abbr, "company_name": company, "company_abbr": abbr}) # create account heads for taxes webnotes.insert({"doctype": "Account", "account_name": "Shipping Charges", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Customs Duty", "parent_account": "Stock Expenses - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) webnotes.insert({"doctype": "Account", "account_name": "Tax Assets", "parent_account": "Current Assets - %s" % abbr, "company": company, "group_or_ledger": "Group"}) webnotes.insert({"doctype": "Account", "account_name": "VAT - Test", "parent_account": "Tax Assets - %s" % abbr, "company": company, "group_or_ledger": "Ledger"}) # create BOM webnotes.insert([ {"doctype": "BOM", "item": "Nebula 7", "quantity": 1, "is_active": "Yes", "is_default": 1, "uom": "Nos"}, {"doctype": "BOM Operation", "operation_no": 1, "parentfield": "bom_operations", "opn_description": "Development"}, {"doctype": "BOM Item", "item_code": "Android Jack D", "operation_no": 1, "qty": 5, "rate": 20, "amount": 100, "stock_uom": "Nos", "parentfield": "bom_materials"} ])