Merge pull request #14436 from shreyashah115/fix-trav

Travis again
This commit is contained in:
Manas Solanki 2018-06-11 17:45:11 +05:30 committed by GitHub
commit e832aa4fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 86 deletions

View File

@ -3,7 +3,6 @@ dist: trusty
python: python:
- "2.7" - "2.7"
- "3.6"
services: services:
- mysql - mysql
@ -53,5 +52,3 @@ jobs:
- bench --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz --mariadb-root-password travis - bench --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz --mariadb-root-password travis
- bench migrate - bench migrate
env: Patch Testing env: Patch Testing
allow_failures:
- python: "3.6"

View File

@ -24,6 +24,8 @@ class Asset(AccountsController):
self.make_depreciation_schedule() self.make_depreciation_schedule()
self.set_accumulated_depreciation() self.set_accumulated_depreciation()
get_depreciation_accounts(self) get_depreciation_accounts(self)
else:
self.finance_books = []
if self.get("schedules"): if self.get("schedules"):
self.validate_expected_value_after_useful_life() self.validate_expected_value_after_useful_life()

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest import unittest
from frappe.utils import cstr, nowdate, getdate, flt, add_days from frappe.utils import cstr, nowdate, getdate, flt
from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries, scrap_asset, restore_asset from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries, scrap_asset, restore_asset
from erpnext.assets.doctype.asset.asset import make_sales_invoice, make_purchase_invoice from erpnext.assets.doctype.asset.asset import make_sales_invoice, make_purchase_invoice
@ -25,7 +25,6 @@ class TestAsset(unittest.TestCase):
pi.supplier = "_Test Supplier" pi.supplier = "_Test Supplier"
pi.insert() pi.insert()
pi.submit() pi.submit()
asset.load_from_db() asset.load_from_db()
self.assertEqual(asset.supplier, "_Test Supplier") self.assertEqual(asset.supplier, "_Test Supplier")
self.assertEqual(asset.purchase_date, getdate("2015-01-01")) self.assertEqual(asset.purchase_date, getdate("2015-01-01"))
@ -39,7 +38,6 @@ class TestAsset(unittest.TestCase):
gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry` gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no = %s where voucher_type='Purchase Invoice' and voucher_no = %s
order by account""", pi.name) order by account""", pi.name)
self.assertEqual(gle, expected_gle) self.assertEqual(gle, expected_gle)
pi.cancel() pi.cancel()
@ -54,20 +52,21 @@ class TestAsset(unittest.TestCase):
def test_schedule_for_straight_line_method(self): def test_schedule_for_straight_line_method(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"next_depreciation_date": "2020-12-31", "next_depreciation_date": "2020-12-31",
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": add_days(nowdate(), 5) "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
self.assertEqual(asset.status, "Draft") self.assertEqual(asset.status, "Draft")
expected_schedules = [ expected_schedules = [
["2018-06-11", 490.20, 490.20], ["2020-06-06", 163.93, 163.93],
["2019-04-11", 49673.20, 50163.40], ["2021-04-06", 49836.07, 50000.0],
["2020-02-11", 39836.60, 90000.00] ["2022-02-06", 40000.0, 90000.00]
] ]
schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
@ -78,6 +77,7 @@ class TestAsset(unittest.TestCase):
def test_schedule_for_straight_line_method_for_existing_asset(self): def test_schedule_for_straight_line_method_for_existing_asset(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.is_existing_asset = 1 asset.is_existing_asset = 1
asset.calculate_depreciation = 1
asset.number_of_depreciations_booked = 1 asset.number_of_depreciations_booked = 1
asset.opening_accumulated_depreciation = 40000 asset.opening_accumulated_depreciation = 40000
asset.append("finance_books", { asset.append("finance_books", {
@ -86,14 +86,14 @@ class TestAsset(unittest.TestCase):
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": add_days(nowdate(), 5) "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
self.assertEqual(asset.status, "Draft") self.assertEqual(asset.status, "Draft")
asset.save() asset.save()
expected_schedules = [ expected_schedules = [
["2018-06-11", 588.24, 40588.24], ["2020-06-06", 197.37, 40197.37],
["2019-04-11", 49411.76, 90000.00] ["2021-04-06", 49802.63, 90000.00]
] ]
schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount]
for d in asset.get("schedules")] for d in asset.get("schedules")]
@ -102,22 +102,23 @@ class TestAsset(unittest.TestCase):
def test_schedule_for_double_declining_method(self): def test_schedule_for_double_declining_method(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"next_depreciation_date": "2020-12-31", "next_depreciation_date": "2020-12-31",
"depreciation_method": "Double Declining Balance", "depreciation_method": "Double Declining Balance",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": add_days(nowdate(), 5) "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
self.assertEqual(asset.status, "Draft") self.assertEqual(asset.status, "Draft")
asset.save() asset.save()
expected_schedules = [ expected_schedules = [
["2018-06-11", 66667.0, 66667.0], ["2020-06-06", 66667.0, 66667.0],
["2019-04-11", 22222.0, 88889.0], ["2021-04-06", 22222.0, 88889.0],
["2020-02-11", 1111.0, 90000.0] ["2022-02-06", 1111.0, 90000.0]
] ]
schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
@ -127,6 +128,7 @@ class TestAsset(unittest.TestCase):
def test_schedule_for_double_declining_method_for_existing_asset(self): def test_schedule_for_double_declining_method_for_existing_asset(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.is_existing_asset = 1 asset.is_existing_asset = 1
asset.number_of_depreciations_booked = 1 asset.number_of_depreciations_booked = 1
asset.opening_accumulated_depreciation = 50000 asset.opening_accumulated_depreciation = 50000
@ -136,7 +138,7 @@ class TestAsset(unittest.TestCase):
"depreciation_method": "Double Declining Balance", "depreciation_method": "Double Declining Balance",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": add_days(nowdate(), 5) "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
self.assertEqual(asset.status, "Draft") self.assertEqual(asset.status, "Draft")
@ -145,8 +147,8 @@ class TestAsset(unittest.TestCase):
asset.save() asset.save()
expected_schedules = [ expected_schedules = [
["2018-06-11", 33333.0, 83333.0], ["2020-06-06", 33333.0, 83333.0],
["2019-04-11", 6667.0, 90000.0] ["2021-04-06", 6667.0, 90000.0]
] ]
schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
@ -157,6 +159,7 @@ class TestAsset(unittest.TestCase):
def test_schedule_for_prorated_straight_line_method(self): def test_schedule_for_prorated_straight_line_method(self):
set_prorated_depreciation_schedule() set_prorated_depreciation_schedule()
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.is_existing_asset = 0 asset.is_existing_asset = 0
asset.available_for_use_date = "2020-01-30" asset.available_for_use_date = "2020-01-30"
asset.append("finance_books", { asset.append("finance_books", {
@ -186,6 +189,7 @@ class TestAsset(unittest.TestCase):
def test_depreciation(self): def test_depreciation(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.available_for_use_date = "2020-01-30" asset.available_for_use_date = "2020-01-30"
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
@ -220,6 +224,7 @@ class TestAsset(unittest.TestCase):
def test_depreciation_entry_cancellation(self): def test_depreciation_entry_cancellation(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
@ -242,15 +247,15 @@ class TestAsset(unittest.TestCase):
depr_entry = asset.get("schedules")[0].journal_entry depr_entry = asset.get("schedules")[0].journal_entry
self.assertFalse(depr_entry) self.assertFalse(depr_entry)
def test_scrap_asset(self): def test_scrap_asset(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": "2020-12-31" "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
asset.submit() asset.submit()
@ -280,6 +285,7 @@ class TestAsset(unittest.TestCase):
def test_asset_sale(self): def test_asset_sale(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
@ -320,13 +326,13 @@ class TestAsset(unittest.TestCase):
def test_asset_expected_value_after_useful_life(self): def test_asset_expected_value_after_useful_life(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
asset.depreciation_method = "Straight Line" asset.calculate_depreciation = 1
asset.append("finance_books", { asset.append("finance_books", {
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"depreciation_method": "Straight Line", "depreciation_method": "Straight Line",
"total_number_of_depreciations": 3, "total_number_of_depreciations": 3,
"frequency_of_depreciation": 10, "frequency_of_depreciation": 10,
"depreciation_start_date": "2020-12-31" "depreciation_start_date": "2020-06-06"
}) })
asset.insert() asset.insert()
accumulated_depreciation_after_full_schedule = \ accumulated_depreciation_after_full_schedule = \
@ -339,7 +345,6 @@ class TestAsset(unittest.TestCase):
def tearDown(self): def tearDown(self):
asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"}) asset = frappe.get_doc("Asset", {"asset_name": "Macbook Pro 1"})
if asset.docstatus == 1 and asset.status not in ("Scrapped", "Sold", "Draft", "Cancelled"): if asset.docstatus == 1 and asset.status not in ("Scrapped", "Sold", "Draft", "Cancelled"):
asset.cancel() asset.cancel()
@ -367,11 +372,11 @@ def create_asset():
"item_code": "Macbook Pro", "item_code": "Macbook Pro",
"company": "_Test Company", "company": "_Test Company",
"purchase_date": "2015-01-01", "purchase_date": "2015-01-01",
"calculate_depreciation": 1, "calculate_depreciation": 0,
"gross_purchase_amount": 100000, "gross_purchase_amount": 100000,
"expected_value_after_useful_life": 10000, "expected_value_after_useful_life": 10000,
"warehouse": "_Test Warehouse - _TC", "warehouse": "_Test Warehouse - _TC",
"available_for_use_date": add_days(nowdate(),3), "available_for_use_date": "2020-06-06",
"location": "Test Location", "location": "Test Location",
"asset_owner": "Company" "asset_owner": "Company"
}) })

View File

@ -15,6 +15,7 @@
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -47,6 +48,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -79,6 +81,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -112,6 +115,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -142,6 +146,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -175,6 +180,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -208,6 +214,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -238,6 +245,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -270,6 +278,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -303,6 +312,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -336,6 +346,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -369,6 +380,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -399,6 +411,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -432,6 +445,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -463,6 +477,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -495,6 +510,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -525,11 +541,12 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fetch_from": "task.has_certificate", "fetch_from": "task.certificate_required",
"fieldname": "has_certificate", "fieldname": "has_certificate",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 0, "hidden": 0,
@ -558,6 +575,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -590,6 +608,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -620,6 +639,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -653,6 +673,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -683,6 +704,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -714,6 +736,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@ -755,7 +778,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-05-25 22:43:39.866477", "modified": "2018-06-09 23:45:55.492528",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Maintenance Log", "name": "Asset Maintenance Log",

View File

@ -216,7 +216,7 @@ def get_supplier(shopify_item):
"doctype": "Supplier", "doctype": "Supplier",
"supplier_name": shopify_item.get("vendor"), "supplier_name": shopify_item.get("vendor"),
"shopify_supplier_id": shopify_item.get("vendor").lower(), "shopify_supplier_id": shopify_item.get("vendor").lower(),
"supplier_type": get_supplier_type() "supplier_group": get_supplier_group()
}).insert() }).insert()
return supplier.name return supplier.name
else: else:
@ -224,15 +224,15 @@ def get_supplier(shopify_item):
else: else:
return "" return ""
def get_supplier_type(): def get_supplier_group():
supplier_type = frappe.db.get_value("Supplier Type", _("Shopify Supplier")) supplier_group = frappe.db.get_value("Supplier Group", _("Shopify Supplier"))
if not supplier_type: if not supplier_group:
supplier_type = frappe.get_doc({ supplier_group = frappe.get_doc({
"doctype": "Supplier Type", "doctype": "Supplier Group",
"supplier_type": _("Shopify Supplier") "supplier_group_name": _("Shopify Supplier")
}).insert() }).insert()
return supplier_type.name return supplier_group.name
return supplier_type return supplier_group
def get_item_details(shopify_item): def get_item_details(shopify_item):
item_details = {} item_details = {}

View File

@ -8,7 +8,7 @@ import unittest
from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee
class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
def setup(self): def setUp(self):
make_employee("employee@taxexepmtion.com") make_employee("employee@taxexepmtion.com")
make_employee("employee1@taxexepmtion.com") make_employee("employee1@taxexepmtion.com")
create_payroll_period() create_payroll_period()
@ -19,7 +19,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
declaration = frappe.get_doc({ declaration = frappe.get_doc({
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"payroll_period": "Test Payroll Period", "payroll_period": "_Test Payroll Period",
"declarations": [dict(exemption_sub_category = "_Test Sub Category", "declarations": [dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category", exemption_category = "_Test Category",
amount = 150000)] amount = 150000)]
@ -27,7 +27,7 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
self.assertRaises(frappe.ValidationError, declaration.save) self.assertRaises(frappe.ValidationError, declaration.save)
declaration = frappe.get_doc({ declaration = frappe.get_doc({
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"payroll_period": "Test Payroll Period", "payroll_period": "_Test Payroll Period",
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"declarations": [dict(exemption_sub_category = "_Test Sub Category", "declarations": [dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category", exemption_category = "_Test Category",
@ -39,7 +39,8 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
declaration = frappe.get_doc({ declaration = frappe.get_doc({
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"payroll_period": "Test Payroll Period", "company": "_Test Company",
"payroll_period": "_Test Payroll Period",
"declarations": [dict(exemption_sub_category = "_Test Sub Category", "declarations": [dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category", exemption_category = "_Test Category",
amount = 100000), amount = 100000),
@ -54,7 +55,8 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
declaration = frappe.get_doc({ declaration = frappe.get_doc({
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"payroll_period": "Test Payroll Period", "company": "_Test Company",
"payroll_period": "_Test Payroll Period",
"declarations": [dict(exemption_sub_category = "_Test Sub Category", "declarations": [dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category", exemption_category = "_Test Category",
amount = 100000), amount = 100000),
@ -62,17 +64,18 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase):
exemption_category = "_Test Category", exemption_category = "_Test Category",
amount = 50000), amount = 50000),
] ]
}) }).insert()
self.assertTrue(declaration.submit) self.assertTrue(declaration.submit)
duplicate_declaration = frappe.get_doc({ duplicate_declaration = frappe.get_doc({
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
"payroll_period": "Test Payroll Period", "company": "_Test Company",
"payroll_period": "_Test Payroll Period",
"declarations": [dict(exemption_sub_category = "_Test Sub Category", "declarations": [dict(exemption_sub_category = "_Test Sub Category",
exemption_category = "_Test Category", exemption_category = "_Test Category",
amount = 100000) amount = 100000)
] ]
}) }).insert()
self.assertRaises(frappe.DocstatusTransitionError, duplicate_declaration.submit) self.assertRaises(frappe.DocstatusTransitionError, duplicate_declaration.submit)
duplicate_declaration.employee = frappe.get_value("Employee", {"user_id":"employee1@taxexepmtion.com"}, "name") duplicate_declaration.employee = frappe.get_value("Employee", {"user_id":"employee1@taxexepmtion.com"}, "name")
self.assertTrue(duplicate_declaration.submit) self.assertTrue(duplicate_declaration.submit)
@ -93,20 +96,22 @@ def create_exemption_category():
category = frappe.get_doc({ category = frappe.get_doc({
"doctype": "Employee Tax Exemption Category", "doctype": "Employee Tax Exemption Category",
"name": "_Test Category", "name": "_Test Category",
"deduction_component": "_Test Tax", "deduction_component": "Income Tax",
"max_amount": 100000 "max_amount": 100000
}).insert() }).insert()
if not frappe.db.exists("Employee Tax Exemption Sub Category", "_Test Category"): if not frappe.db.exists("Employee Tax Exemption Sub Category", "_Test Sub Category"):
frappe.get_doc({ frappe.get_doc({
"doctype": "Employee Tax Exemption Sub Category", "doctype": "Employee Tax Exemption Sub Category",
"name": "_Test Sub Category", "name": "_Test Sub Category",
"exemption_category": "_Test Category", "exemption_category": "_Test Category",
"max_amount": 100000 "max_amount": 100000,
"is_active": 1
}).insert() }).insert()
if not frappe.db.exists("Employee Tax Exemption Sub Category", "_Test Category"): if not frappe.db.exists("Employee Tax Exemption Sub Category", "_Test1 Sub Category"):
frappe.get_doc({ frappe.get_doc({
"doctype": "Employee Tax Exemption Sub Category", "doctype": "Employee Tax Exemption Sub Category",
"name": "_Test1 Sub Category", "name": "_Test1 Sub Category",
"exemption_category": "_Test Category", "exemption_category": "_Test Category",
"max_amount": 50000 "max_amount": 50000,
"is_active": 1
}).insert() }).insert()

View File

@ -54,9 +54,12 @@ class TestLeaveApplication(unittest.TestCase):
def tearDown(self): def tearDown(self):
frappe.set_user("Administrator") frappe.set_user("Administrator")
def _clear_roles(self):
frappe.db.sql("""delete from `tabHas Role` where parent in
("test@example.com", "test1@example.com", "test2@example.com")""")
def _clear_applications(self): def _clear_applications(self):
frappe.db.sql("""delete from `tabLeave Application`""") frappe.db.sql("""delete from `tabLeave Application`""")
frappe.db.sql("""delete from `tabDepartment Approver` where parentfield = 'Leave Approver'""")
def get_application(self, doc): def get_application(self, doc):
application = frappe.copy_doc(doc) application = frappe.copy_doc(doc)
@ -65,6 +68,10 @@ class TestLeaveApplication(unittest.TestCase):
return application return application
def test_block_list(self): def test_block_list(self):
self._clear_roles()
from frappe.utils.user import add_role
add_role("test@example.com", "HR User")
clear_user_permissions_for_doctype("Employee") clear_user_permissions_for_doctype("Employee")
frappe.db.set_value("Department", "_Test Department - _TC", frappe.db.set_value("Department", "_Test Department - _TC",
@ -86,8 +93,11 @@ class TestLeaveApplication(unittest.TestCase):
self.assertTrue(application.insert()) self.assertTrue(application.insert())
def test_overlap(self): def test_overlap(self):
self._clear_roles()
self._clear_applications() self._clear_applications()
from frappe.utils.user import add_role
add_role("test@example.com", "Employee")
frappe.set_user("test@example.com") frappe.set_user("test@example.com")
make_allocation_record() make_allocation_record()
@ -99,8 +109,11 @@ class TestLeaveApplication(unittest.TestCase):
self.assertRaises(OverlapError, application.insert) self.assertRaises(OverlapError, application.insert)
def test_overlap_with_half_day_1(self): def test_overlap_with_half_day_1(self):
self._clear_roles()
self._clear_applications() self._clear_applications()
from frappe.utils.user import add_role
add_role("test@example.com", "Employee")
frappe.set_user("test@example.com") frappe.set_user("test@example.com")
make_allocation_record() make_allocation_record()
@ -129,8 +142,12 @@ class TestLeaveApplication(unittest.TestCase):
self.assertRaises(OverlapError, application.insert) self.assertRaises(OverlapError, application.insert)
def test_overlap_with_half_day_2(self): def test_overlap_with_half_day_2(self):
self._clear_roles()
self._clear_applications() self._clear_applications()
from frappe.utils.user import add_role
add_role("test@example.com", "Employee")
frappe.set_user("test@example.com") frappe.set_user("test@example.com")
make_allocation_record() make_allocation_record()
@ -147,8 +164,12 @@ class TestLeaveApplication(unittest.TestCase):
self.assertRaises(OverlapError, application.insert) self.assertRaises(OverlapError, application.insert)
def test_overlap_with_half_day_3(self): def test_overlap_with_half_day_3(self):
self._clear_roles()
self._clear_applications() self._clear_applications()
from frappe.utils.user import add_role
add_role("test@example.com", "Employee")
frappe.set_user("test@example.com") frappe.set_user("test@example.com")
make_allocation_record() make_allocation_record()
@ -176,7 +197,6 @@ class TestLeaveApplication(unittest.TestCase):
application.half_day_date = "2013-01-05" application.half_day_date = "2013-01-05"
application.insert() application.insert()
def test_optional_leave(self): def test_optional_leave(self):
leave_period = get_leave_period() leave_period = get_leave_period()
today = nowdate() today = nowdate()
@ -228,6 +248,7 @@ class TestLeaveApplication(unittest.TestCase):
# check leave balance is reduced # check leave balance is reduced
self.assertEqual(get_leave_balance_on(employee.name, leave_type, today), 9) self.assertEqual(get_leave_balance_on(employee.name, leave_type, today), 9)
def test_leaves_allowed(self): def test_leaves_allowed(self):
employee = get_employee() employee = get_employee()
leave_period = get_leave_period() leave_period = get_leave_period()
@ -428,4 +449,3 @@ def allocate_leaves(employee, leave_period, leave_type, new_leaves_allocated, el
}).insert() }).insert()
allocate_leave.submit() allocate_leave.submit()