* minor improv in fetching account

* pass name field while creating tds doc

* create tds fixture after creating tds account

* Inpatient Record - Test - Fix

* fix batch query
This commit is contained in:
Ranjith Kurungadam 2018-07-24 11:07:28 +05:30 committed by Nabin Hait
parent 4037915b3c
commit e51c175aca
3 changed files with 39 additions and 21 deletions

View File

@ -31,6 +31,7 @@ class TestInpatientRecord(unittest.TestCase):
self.assertEqual(0, frappe.db.get_value("Healthcare Service Unit", service_unit, "occupied"))
def test_validate_overlap_admission(self):
frappe.db.sql("""delete from `tabInpatient Record`""")
patient = get_patient()
ip_record = create_inpatient(patient)
@ -42,6 +43,7 @@ class TestInpatientRecord(unittest.TestCase):
admit_patient(ip_record, service_unit, now_datetime())
ip_record_new = create_inpatient(patient)
self.assertRaises(frappe.ValidationError, ip_record_new.save)
frappe.db.sql("""delete from `tabInpatient Record`""")
def create_inpatient(patient):
patient_obj = frappe.get_doc('Patient', patient)
@ -77,6 +79,18 @@ def get_healthcare_service_unit():
service_unit.service_unit_type = get_service_unit_type()
service_unit.inpatient_occupancy = 1
service_unit.occupied = 0
service_unit.is_group = 0
service_unit_parent_name = frappe.db.exists({
"doctype": "Healthcare Service Unit",
"healthcare_service_unit_name": "All Healthcare Service Units",
"is_group": 1
})
if not service_unit_parent_name:
parent_service_unit = frappe.new_doc("Healthcare Service Unit")
parent_service_unit.healthcare_service_unit_name = "All Healthcare Service Units"
parent_service_unit.is_group = 1
parent_service_unit.save(ignore_permissions = True)
service_unit.parent_healthcare_service_unit = "All Healthcare Service Units"
service_unit.save(ignore_permissions = True)
return service_unit.name
return service_unit

View File

@ -248,8 +248,7 @@ def make_fixtures(company=None):
company = company.name if company else frappe.db.get_value("Global Defaults", None, "default_company")
set_salary_components(docs)
# set_tds_account(docs, company)
# set_tax_withholding_category(docs, company)
set_tds_account(docs, company)
for d in docs:
try:
@ -259,6 +258,9 @@ def make_fixtures(company=None):
except frappe.NameError:
pass
# create tds fixtures
set_tax_withholding_category(company)
def set_salary_components(docs):
docs.extend([
{'doctype': 'Salary Component', 'salary_component': 'Professional Tax', 'description': 'Professional Tax', 'type': 'Deduction'},
@ -269,31 +271,33 @@ def set_salary_components(docs):
{'doctype': 'Salary Component', 'salary_component': 'Leave Encashment', 'description': 'Leave Encashment', 'type': 'Earning'}
])
def set_tax_withholding_category(docs, company):
def set_tax_withholding_category(company):
accounts = []
tds_account = frappe.db.get_value("Account", filters={"account_type": "Payable",
"account_name": "TDS", "company": company})
abbr = frappe.get_value("Company", company, "abbr")
tds_account = frappe.get_value("Account", 'TDS Payable - {0}'.format(abbr), 'name')
if company and tds_account:
accounts = [
{
'company': company,
'account': tds_account
}
]
accounts = [dict(company=company, account=tds_account)]
docs.extend([
{
'doctype': 'Tax Withholding Category', '__newname': 'TDS',
'percent_of_tax_withheld': 10,'threshold': 150000, 'book_on_invoice': 1,
'withhold_cumulative_tax_amount': 0, 'accounts': accounts
}
])
tds = frappe.get_doc({
'doctype': 'Tax Withholding Category', 'name': 'TDS',
'percent_of_tax_withheld': 10,'threshold': 150000, 'book_on_invoice': 1,
'withhold_cumulative_tax_amount': 0, 'accounts': accounts
})
try:
tds.flags.ignore_permissions = True
tds.insert()
except frappe.DuplicateEntryError:
tds = frappe.get_doc("Tax Withholding Category", tds.get("name"))
tds.append("accounts", accounts[0])
tds.save()
def set_tds_account(docs, company):
abbr = frappe.get_value("Company", company, "abbr")
docs.extend([
{
'doctype': 'Account', 'account_name': 'TDS', 'account_type': 'Tax',
'parent_account': 'Duties and Taxes', 'company': company
"doctype": "Account", "account_name": "TDS Payable", "account_type": "Tax",
"parent_account": "Duties and Taxes - {0}".format(abbr), "company": company
}
])

View File

@ -252,7 +252,7 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False):
def get_batches(item_code, warehouse, qty=1, throw=False):
batches = frappe.db.sql(
'select batch_id, sum(actual_qty) as qty from `tabBatch` join `tabStock Ledger Entry` ignore index (item_code, warehouse) '
'on `(tabBatch`.batch_id = `tabStock Ledger Entry`.batch_no )'
'on (`tabBatch`.batch_id = `tabStock Ledger Entry`.batch_no )'
'where `tabStock Ledger Entry`.item_code = %s and `tabStock Ledger Entry`.warehouse = %s '
'and (`tabBatch`.expiry_date >= CURDATE() or `tabBatch`.expiry_date IS NULL)'
'group by batch_id '