fix(regional): minor fixes and test for South Africa VAT report (#26933)

* fix: added test and minor fixes

* fix: sider fixes

* fix: sider

* fix: test fixes

Co-authored-by: Afshan <33727827+AfshanKhan@users.noreply.github.com>
Co-authored-by: Saqib <nextchamp.saqib@gmail.com>
This commit is contained in:
Anuja Pawar 2021-08-26 12:48:43 +05:30 committed by GitHub
parent 642b4c805c
commit baa548a3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 199 additions and 5 deletions

View File

@ -0,0 +1,193 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from unittest import TestCase
from frappe.utils import today
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.regional.report.vat_audit_report.vat_audit_report import execute
class TestVATAuditReport(TestCase):
def setUp(self):
frappe.set_user("Administrator")
make_company("_Test Company SA VAT", "_TCSV")
create_account(account_name="VAT - 0%", account_type="Tax",
parent_account="Duties and Taxes - _TCSV", company="_Test Company SA VAT")
create_account(account_name="VAT - 15%", account_type="Tax",
parent_account="Duties and Taxes - _TCSV", company="_Test Company SA VAT")
set_sa_vat_accounts()
make_item("_Test SA VAT Item")
make_item("_Test SA VAT Zero Rated Item", properties = {"is_zero_rated": 1})
make_customer()
make_supplier()
make_sales_invoices()
create_purchase_invoices()
def tearDown(self):
frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company SA VAT'")
frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company SA VAT'")
def test_vat_audit_report(self):
filters = {
"company": "_Test Company SA VAT",
"from_date": today(),
"to_date": today()
}
columns, data = execute(filters)
total_tax_amount = 0
total_row_tax = 0
for row in data:
keys = row.keys()
# skips total row tax_amount in if.. and skips section header in elif..
if 'voucher_no' in keys:
total_tax_amount = total_tax_amount + row['tax_amount']
elif 'tax_amount' in keys:
total_row_tax = total_row_tax + row['tax_amount']
self.assertEqual(total_tax_amount, total_row_tax)
def make_company(company_name, abbr):
if not frappe.db.exists("Company", company_name):
company = frappe.get_doc({
"doctype": "Company",
"company_name": company_name,
"abbr": abbr,
"default_currency": "ZAR",
"country": "South Africa",
"create_chart_of_accounts_based_on": "Standard Template"
})
company.insert()
else:
company = frappe.get_doc("Company", company_name)
company.create_default_warehouses()
if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": company.name}):
company.create_default_cost_center()
company.save()
return company
def set_sa_vat_accounts():
if not frappe.db.exists("South Africa VAT Settings", "_Test Company SA VAT"):
vat_accounts = frappe.get_all(
"Account",
fields=["name"],
filters = {
"company": "_Test Company SA VAT",
"is_group": 0,
"account_type": "Tax"
}
)
sa_vat_accounts = []
for account in vat_accounts:
sa_vat_accounts.append({
"doctype": "South Africa VAT Account",
"account": account.name
})
frappe.get_doc({
"company": "_Test Company SA VAT",
"vat_accounts": sa_vat_accounts,
"doctype": "South Africa VAT Settings",
}).insert()
def make_customer():
if not frappe.db.exists("Customer", "_Test SA Customer"):
frappe.get_doc({
"doctype": "Customer",
"customer_name": "_Test SA Customer",
"customer_type": "Company",
}).insert()
def make_supplier():
if not frappe.db.exists("Supplier", "_Test SA Supplier"):
frappe.get_doc({
"doctype": "Supplier",
"supplier_name": "_Test SA Supplier",
"supplier_type": "Company",
"supplier_group":"All Supplier Groups"
}).insert()
def make_item(item_code, properties=None):
if not frappe.db.exists("Item", item_code):
item = frappe.get_doc({
"doctype": "Item",
"item_code": item_code,
"item_name": item_code,
"description": item_code,
"item_group": "Products"
})
if properties:
item.update(properties)
item.insert()
def make_sales_invoices():
def make_sales_invoices_wrapper(item, rate, tax_account, tax_rate, tax=True):
si = create_sales_invoice(
company="_Test Company SA VAT",
customer = "_Test SA Customer",
currency = "ZAR",
item=item,
rate=rate,
warehouse = "Finished Goods - _TCSV",
debit_to = "Debtors - _TCSV",
income_account = "Sales - _TCSV",
expense_account = "Cost of Goods Sold - _TCSV",
cost_center = "Main - _TCSV",
do_not_save=1
)
if tax:
si.append("taxes", {
"charge_type": "On Net Total",
"account_head": tax_account,
"cost_center": "Main - _TCSV",
"description": "VAT 15% @ 15.0",
"rate": tax_rate
})
si.submit()
test_item = "_Test SA VAT Item"
test_zero_rated_item = "_Test SA VAT Zero Rated Item"
make_sales_invoices_wrapper(test_item, 100.0, "VAT - 15% - _TCSV", 15.0)
make_sales_invoices_wrapper(test_zero_rated_item, 100.0, "VAT - 0% - _TCSV", 0.0)
def create_purchase_invoices():
pi = make_purchase_invoice(
company = "_Test Company SA VAT",
supplier = "_Test SA Supplier",
supplier_warehouse = "Finished Goods - _TCSV",
warehouse = "Finished Goods - _TCSV",
currency = "ZAR",
cost_center = "Main - _TCSV",
expense_account = "Cost of Goods Sold - _TCSV",
item = "_Test SA VAT Item",
qty = 1,
rate = 100,
uom = "Nos",
do_not_save = 1
)
pi.append("taxes", {
"charge_type": "On Net Total",
"account_head": "VAT - 15% - _TCSV",
"cost_center": "Main - _TCSV",
"description": "VAT 15% @ 15.0",
"rate": 15.0
})
pi.submit()

View File

@ -1,11 +1,11 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
import json
from frappe import _
from frappe.utils import formatdate
from frappe.utils import formatdate, get_link_to_form
def execute(filters=None):
return VATAuditReport(filters).run()
@ -42,7 +42,8 @@ class VATAuditReport(object):
self.sa_vat_accounts = frappe.get_list("South Africa VAT Account",
filters = {"parent": self.filters.company}, pluck="account")
if not self.sa_vat_accounts and not frappe.flags.in_test and not frappe.flags.in_migrate:
frappe.throw(_("Please set VAT Accounts in South Africa VAT Settings"))
link_to_settings = get_link_to_form("South Africa VAT Settings", "", label="South Africa VAT Settings")
frappe.throw(_("Please set VAT Accounts in {0}").format(link_to_settings))
def get_invoice_data(self, doctype):
conditions = self.get_conditions()
@ -69,7 +70,7 @@ class VATAuditReport(object):
items = frappe.db.sql("""
SELECT
item_code, parent, taxable_value, base_net_amount, is_zero_rated
item_code, parent, base_net_amount, is_zero_rated
FROM
`tab%s Item`
WHERE
@ -79,7 +80,7 @@ class VATAuditReport(object):
if d.item_code not in self.invoice_items.get(d.parent, {}):
self.invoice_items.setdefault(d.parent, {}).setdefault(d.item_code, {
'net_amount': 0.0})
self.invoice_items[d.parent][d.item_code]['net_amount'] += d.get('taxable_value', 0) or d.get('base_net_amount', 0)
self.invoice_items[d.parent][d.item_code]['net_amount'] += d.get('base_net_amount', 0)
self.invoice_items[d.parent][d.item_code]['is_zero_rated'] = d.is_zero_rated
def get_items_based_on_tax_rate(self, doctype):