From 372f91c923a2d09a582ad13a64ab3e6d794ad682 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 18 Dec 2021 16:03:16 -0500 Subject: [PATCH 1/6] fix: fetch correct selling price. --- erpnext/utilities/product.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py index 2054feb4ff5..1cae8d9dd3a 100644 --- a/erpnext/utilities/product.py +++ b/erpnext/utilities/product.py @@ -69,6 +69,8 @@ def qty_from_all_warehouses(batch_info): return qty def get_price(item_code, price_list, customer_group, company, qty=1): + from erpnext.e_commerce.shopping_cart.cart import get_party + template_item_code = frappe.db.get_value("Item", item_code, "variant_of") if price_list: @@ -80,7 +82,8 @@ def get_price(item_code, price_list, customer_group, company, qty=1): filters={"price_list": price_list, "item_code": template_item_code}) if price: - pricing_rule = get_pricing_rule_for_item(frappe._dict({ + party = get_party() + pricing_rule_dict = frappe._dict({ "item_code": item_code, "qty": qty, "stock_qty": qty, @@ -91,7 +94,12 @@ def get_price(item_code, price_list, customer_group, company, qty=1): "conversion_rate": 1, "for_shopping_cart": True, "currency": frappe.db.get_value("Price List", price_list, "currency") - })) + }) + + if party and party.doctype == "Customer": + pricing_rule_dict.update({"customer": party.name}) + + pricing_rule = get_pricing_rule_for_item(pricing_rule_dict) price_obj = price[0] if pricing_rule: From 7eafc9ffe8dbf6707bc21b154b2f4810b2e06964 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 22 Dec 2021 13:11:02 -0500 Subject: [PATCH 2/6] test: e-commerce customer pricing rule --- .../doctype/website_item/test_website_item.py | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/test_website_item.py b/erpnext/e_commerce/doctype/website_item/test_website_item.py index 31f40c49b79..5340299da67 100644 --- a/erpnext/e_commerce/doctype/website_item/test_website_item.py +++ b/erpnext/e_commerce/doctype/website_item/test_website_item.py @@ -46,12 +46,15 @@ class TestWebsiteItem(unittest.TestCase): ] }) elif self._testMethodName in WEBITEM_PRICE_TESTS: + create_user_if_not_exists("test_contact_customer@example.com", "_Test Contact For _Test Customer") create_regular_web_item() make_web_item_price(item_code="Test Mobile Phone") make_web_pricing_rule( title="Test Pricing Rule for Test Mobile Phone", item_code="Test Mobile Phone", - selling=1) + selling=1, + applicable_for="Customer", + customer="test_contact_customer@example.com") def test_index_creation(self): "Check if index is getting created in db." @@ -188,6 +191,9 @@ class TestWebsiteItem(unittest.TestCase): # price and pricing rule added via setUp + # login as customer with pricing rule + frappe.set_user("test_contact_customer@example.com") + # check if price and slashed price is fetched correctly frappe.local.shopping_cart_settings = None data = get_product_info_for_website(item_code, skip_quotation_creation=True) @@ -200,10 +206,12 @@ class TestWebsiteItem(unittest.TestCase): self.assertEqual(price_object.get("formatted_price"), "₹ 900.00") self.assertEqual(price_object.get("formatted_discount_percent"), "10%") - # disable show price + # switch to admin and disable show price + frappe.set_user("Administrator") setup_e_commerce_settings({"show_price": 0}) - # price should not be fetched + # price should not be fetched for logged in user. + frappe.set_user("test_contact_customer@example.com") frappe.local.shopping_cart_settings = None data = get_product_info_for_website(item_code, skip_quotation_creation=True) self.assertFalse(bool(data.product_info["price"])) @@ -491,4 +499,19 @@ def make_web_pricing_rule(**kwargs): else: pricing_rule = frappe.get_doc("Pricing Rule", {"title": title}) - return pricing_rule \ No newline at end of file + return pricing_rule + + +def create_user_if_not_exists(email, first_name = None): + if frappe.db.exists("User", email): + return + + frappe.get_doc({ + "doctype": "User", + "user_type": "Website User", + "email": email, + "send_welcome_email": 0, + "first_name": first_name or email.split("@")[0] + }).insert(ignore_permissions=True) + +test_dependencies = ["Price List", "Item Price", "Customer", "Contact", "Item"] From bcc436e63e2a2139839c06d26c1f78f8f7eee73d Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 22 Dec 2021 20:20:57 -0500 Subject: [PATCH 3/6] fix(test): e-commerce fetch logged-in user item price. --- .../doctype/website_item/test_website_item.py | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/test_website_item.py b/erpnext/e_commerce/doctype/website_item/test_website_item.py index 5340299da67..a4c85ec3469 100644 --- a/erpnext/e_commerce/doctype/website_item/test_website_item.py +++ b/erpnext/e_commerce/doctype/website_item/test_website_item.py @@ -46,15 +46,26 @@ class TestWebsiteItem(unittest.TestCase): ] }) elif self._testMethodName in WEBITEM_PRICE_TESTS: - create_user_if_not_exists("test_contact_customer@example.com", "_Test Contact For _Test Customer") + create_user_and_customer_if_not_exists("test_contact_customer@example.com", "_Test Contact For _Test Customer") create_regular_web_item() make_web_item_price(item_code="Test Mobile Phone") + + # Note: When testing web item pricing rule logged-in user pricing rule must differ from guest pricing rule or test will falsely pass. + # This is because make_web_pricing_rule creates a pricing rule "selling": 1, without specifying "applicable_for". Therefor, + # when testing for logged-in user the test will get the previous pricing rule because "selling" is still true. + # + # I've attempted to mitigate this by setting applicable_for=Customer, and customer=Guest however, this only results in PermissionError failing the test. make_web_pricing_rule( title="Test Pricing Rule for Test Mobile Phone", item_code="Test Mobile Phone", + selling=1) + make_web_pricing_rule( + title="Test Pricing Rule for Test Mobile Phone (Customer)", + item_code="Test Mobile Phone", selling=1, + discount_percentage="25", applicable_for="Customer", - customer="test_contact_customer@example.com") + customer="_Test Customer") def test_index_creation(self): "Check if index is getting created in db." @@ -200,11 +211,11 @@ class TestWebsiteItem(unittest.TestCase): self.assertTrue(bool(data.product_info["price"])) price_object = data.product_info["price"] - self.assertEqual(price_object.get("discount_percent"), 10) - self.assertEqual(price_object.get("price_list_rate"), 900) + self.assertEqual(price_object.get("discount_percent"), 25) + self.assertEqual(price_object.get("price_list_rate"), 750) self.assertEqual(price_object.get("formatted_mrp"), "₹ 1,000.00") - self.assertEqual(price_object.get("formatted_price"), "₹ 900.00") - self.assertEqual(price_object.get("formatted_discount_percent"), "10%") + self.assertEqual(price_object.get("formatted_price"), "₹ 750.00") + self.assertEqual(price_object.get("formatted_discount_percent"), "25%") # switch to admin and disable show price frappe.set_user("Administrator") @@ -493,7 +504,9 @@ def make_web_pricing_rule(**kwargs): "discount_percentage": kwargs.get("discount_percentage") or 10, "company": kwargs.get("company") or "_Test Company", "currency": kwargs.get("currency") or "INR", - "for_price_list": kwargs.get("price_list") or "_Test Price List India" + "for_price_list": kwargs.get("price_list") or "_Test Price List India", + "applicable_for": kwargs.get("applicable_for") or "", + "customer": kwargs.get("customer") or "", }) pricing_rule.insert() else: @@ -502,7 +515,7 @@ def make_web_pricing_rule(**kwargs): return pricing_rule -def create_user_if_not_exists(email, first_name = None): +def create_user_and_customer_if_not_exists(email, first_name = None): if frappe.db.exists("User", email): return @@ -514,4 +527,11 @@ def create_user_if_not_exists(email, first_name = None): "first_name": first_name or email.split("@")[0] }).insert(ignore_permissions=True) + contact = frappe.get_last_doc("Contact", filters={"email_id": email}) + link = contact.append('links', {}) + link.link_doctype = "Customer" + link.link_name = "_Test Customer" + link.link_title = "_Test Customer" + contact.save() + test_dependencies = ["Price List", "Item Price", "Customer", "Contact", "Item"] From d0d82bc34a7a8d9359e81f948089b9d390be7f13 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 27 Dec 2021 15:16:58 +0530 Subject: [PATCH 4/6] fix: ignore links while setting default notification templates in Settings (#29042) --- .../patches/v11_0/add_default_dispatch_notification_template.py | 1 + .../v13_0/add_default_interview_notification_templates.py | 1 + 2 files changed, 2 insertions(+) diff --git a/erpnext/patches/v11_0/add_default_dispatch_notification_template.py b/erpnext/patches/v11_0/add_default_dispatch_notification_template.py index 784b0eeafa5..01836ca6a45 100644 --- a/erpnext/patches/v11_0/add_default_dispatch_notification_template.py +++ b/erpnext/patches/v11_0/add_default_dispatch_notification_template.py @@ -23,4 +23,5 @@ def execute(): delivery_settings = frappe.get_doc("Delivery Settings") delivery_settings.dispatch_template = _("Dispatch Notification") + delivery_settings.flags.ignore_links = True delivery_settings.save() diff --git a/erpnext/patches/v13_0/add_default_interview_notification_templates.py b/erpnext/patches/v13_0/add_default_interview_notification_templates.py index 8d9f5cc89b5..fa1b31c34bb 100644 --- a/erpnext/patches/v13_0/add_default_interview_notification_templates.py +++ b/erpnext/patches/v13_0/add_default_interview_notification_templates.py @@ -33,4 +33,5 @@ def execute(): hr_settings = frappe.get_doc('HR Settings') hr_settings.interview_reminder_template = _('Interview Reminder') hr_settings.feedback_reminder_notification_template = _('Interview Feedback Reminder') + hr_settings.flags.ignore_links = True hr_settings.save() From b0bc3994c3c5cc92bacd8e8660b2a69efe10f334 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 27 Dec 2021 17:26:16 +0530 Subject: [PATCH 5/6] fix: flaky HR tests (#29045) * fix(test): Leave Allocation validation against Leave Application after submit (#29005) * fix(test): Leave Allocation validation against Leave Application after submit * chore: clean-up Leave Allocation tests * fix(test): set holiday list for leave allocation test * fix: flaky HR tests (#29017) * fix(test): use root company in Expense Claim tests * fix(test): set Holiday List for Leave Allocation * fix(test): set Holiday List for company --- .../expense_claim/test_expense_claim.py | 24 ++-- .../doctype/expense_claim/test_records.json | 1 - .../leave_allocation/test_leave_allocation.py | 105 +++++++++++------- 3 files changed, 76 insertions(+), 54 deletions(-) delete mode 100644 erpnext/hr/doctype/expense_claim/test_records.json diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index 548cc667ba8..46958b1ec4c 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -10,15 +10,17 @@ from erpnext.accounts.doctype.account.test_account import create_account from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.expense_claim.expense_claim import make_bank_entry -test_records = frappe.get_test_records('Expense Claim') test_dependencies = ['Employee'] -company_name = '_Test Company 4' +company_name = '_Test Company 3' class TestExpenseClaim(unittest.TestCase): + def tearDown(self): + frappe.db.rollback() + def test_total_expense_claim_for_project(self): - frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """) - frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """) + frappe.db.sql("""delete from `tabTask`""") + frappe.db.sql("""delete from `tabProject`""") frappe.db.sql("update `tabExpense Claim` set project = '', task = ''") project = frappe.get_doc({ @@ -37,12 +39,12 @@ class TestExpenseClaim(unittest.TestCase): task_name = task.name payable_account = get_payable_account(company_name) - make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC4", project.name, task_name) + make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC3", project.name, task_name) self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200) self.assertEqual(frappe.db.get_value("Project", project.name, "total_expense_claim"), 200) - expense_claim2 = make_expense_claim(payable_account, 600, 500, company_name, "Travel Expenses - _TC4", project.name, task_name) + expense_claim2 = make_expense_claim(payable_account, 600, 500, company_name, "Travel Expenses - _TC3", project.name, task_name) self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 700) self.assertEqual(frappe.db.get_value("Project", project.name, "total_expense_claim"), 700) @@ -54,7 +56,7 @@ class TestExpenseClaim(unittest.TestCase): def test_expense_claim_status(self): payable_account = get_payable_account(company_name) - expense_claim = make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC4") + expense_claim = make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC3") je_dict = make_bank_entry("Expense Claim", expense_claim.name) je = frappe.get_doc(je_dict) @@ -73,7 +75,7 @@ class TestExpenseClaim(unittest.TestCase): def test_expense_claim_gl_entry(self): payable_account = get_payable_account(company_name) taxes = generate_taxes() - expense_claim = make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC4", + expense_claim = make_expense_claim(payable_account, 300, 200, company_name, "Travel Expenses - _TC3", do_not_submit=True, taxes=taxes) expense_claim.submit() @@ -84,9 +86,9 @@ class TestExpenseClaim(unittest.TestCase): self.assertTrue(gl_entries) expected_values = dict((d[0], d) for d in [ - ['Output Tax CGST - _TC4',18.0, 0.0], + ['Output Tax CGST - _TC3',18.0, 0.0], [payable_account, 0.0, 218.0], - ["Travel Expenses - _TC4", 200.0, 0.0] + ["Travel Expenses - _TC3", 200.0, 0.0] ]) for gle in gl_entries: @@ -102,7 +104,7 @@ class TestExpenseClaim(unittest.TestCase): "payable_account": payable_account, "approval_status": "Rejected", "expenses": - [{ "expense_type": "Travel", "default_account": "Travel Expenses - _TC4", "amount": 300, "sanctioned_amount": 200 }] + [{"expense_type": "Travel", "default_account": "Travel Expenses - _TC3", "amount": 300, "sanctioned_amount": 200}] }) expense_claim.submit() diff --git a/erpnext/hr/doctype/expense_claim/test_records.json b/erpnext/hr/doctype/expense_claim/test_records.json deleted file mode 100644 index fe51488c706..00000000000 --- a/erpnext/hr/doctype/expense_claim/test_records.json +++ /dev/null @@ -1 +0,0 @@ -[] diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py index f6165b3a6f1..1310ca65ecf 100644 --- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py @@ -5,6 +5,7 @@ import frappe from frappe.utils import add_days, add_months, getdate, nowdate import erpnext +from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import process_expired_allocation from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type @@ -14,16 +15,19 @@ class TestLeaveAllocation(unittest.TestCase): def setUpClass(cls): frappe.db.sql("delete from `tabLeave Period`") - def test_overlapping_allocation(self): - frappe.db.sql("delete from `tabLeave Allocation`") + emp_id = make_employee("test_emp_leave_allocation@salary.com") + cls.employee = frappe.get_doc("Employee", emp_id) - employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) + def tearDown(self): + frappe.db.rollback() + + def test_overlapping_allocation(self): leaves = [ { "doctype": "Leave Allocation", "__islocal": 1, - "employee": employee.name, - "employee_name": employee.employee_name, + "employee": self.employee.name, + "employee_name": self.employee.employee_name, "leave_type": "_Test Leave Type", "from_date": getdate("2015-10-01"), "to_date": getdate("2015-10-31"), @@ -33,8 +37,8 @@ class TestLeaveAllocation(unittest.TestCase): { "doctype": "Leave Allocation", "__islocal": 1, - "employee": employee.name, - "employee_name": employee.employee_name, + "employee": self.employee.name, + "employee_name": self.employee.employee_name, "leave_type": "_Test Leave Type", "from_date": getdate("2015-09-01"), "to_date": getdate("2015-11-30"), @@ -46,40 +50,36 @@ class TestLeaveAllocation(unittest.TestCase): self.assertRaises(frappe.ValidationError, frappe.get_doc(leaves[1]).save) def test_invalid_period(self): - employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) - doc = frappe.get_doc({ "doctype": "Leave Allocation", "__islocal": 1, - "employee": employee.name, - "employee_name": employee.employee_name, + "employee": self.employee.name, + "employee_name": self.employee.employee_name, "leave_type": "_Test Leave Type", "from_date": getdate("2015-09-30"), "to_date": getdate("2015-09-1"), "new_leaves_allocated": 5 }) - #invalid period + # invalid period self.assertRaises(frappe.ValidationError, doc.save) def test_allocated_leave_days_over_period(self): - employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) doc = frappe.get_doc({ "doctype": "Leave Allocation", "__islocal": 1, - "employee": employee.name, - "employee_name": employee.employee_name, + "employee": self.employee.name, + "employee_name": self.employee.employee_name, "leave_type": "_Test Leave Type", "from_date": getdate("2015-09-1"), "to_date": getdate("2015-09-30"), "new_leaves_allocated": 35 }) - #allocated leave more than period + + # allocated leave more than period self.assertRaises(frappe.ValidationError, doc.save) def test_carry_forward_calculation(self): - frappe.db.sql("delete from `tabLeave Allocation`") - frappe.db.sql("delete from `tabLeave Ledger Entry`") leave_type = create_leave_type(leave_type_name="_Test_CF_leave", is_carry_forward=1) leave_type.maximum_carry_forwarded_leaves = 10 leave_type.max_leaves_allowed = 30 @@ -87,6 +87,8 @@ class TestLeaveAllocation(unittest.TestCase): # initial leave allocation = 15 leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave", from_date=add_months(nowdate(), -12), to_date=add_months(nowdate(), -1), @@ -96,6 +98,8 @@ class TestLeaveAllocation(unittest.TestCase): # carry forwarded leaves considering maximum_carry_forwarded_leaves # new_leaves = 15, carry_forwarded = 10 leave_allocation_1 = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave", carry_forward=1) leave_allocation_1.submit() @@ -107,6 +111,8 @@ class TestLeaveAllocation(unittest.TestCase): # carry forwarded leaves considering max_leave_allowed # max_leave_allowed = 30, new_leaves = 25, carry_forwarded = 5 leave_allocation_2 = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave", carry_forward=1, new_leaves_allocated=25) @@ -115,8 +121,6 @@ class TestLeaveAllocation(unittest.TestCase): self.assertEqual(leave_allocation_2.unused_leaves, 5) def test_carry_forward_leaves_expiry(self): - frappe.db.sql("delete from `tabLeave Allocation`") - frappe.db.sql("delete from `tabLeave Ledger Entry`") leave_type = create_leave_type( leave_type_name="_Test_CF_leave_expiry", is_carry_forward=1, @@ -125,6 +129,8 @@ class TestLeaveAllocation(unittest.TestCase): # initial leave allocation leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", from_date=add_months(nowdate(), -24), to_date=add_months(nowdate(), -12), @@ -132,6 +138,8 @@ class TestLeaveAllocation(unittest.TestCase): leave_allocation.submit() leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", from_date=add_days(nowdate(), -90), to_date=add_days(nowdate(), 100), @@ -143,6 +151,8 @@ class TestLeaveAllocation(unittest.TestCase): # leave allocation with carry forward of only new leaves allocated leave_allocation_1 = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name, leave_type="_Test_CF_leave_expiry", carry_forward=1, from_date=add_months(nowdate(), 6), @@ -152,9 +162,10 @@ class TestLeaveAllocation(unittest.TestCase): self.assertEqual(leave_allocation_1.unused_leaves, leave_allocation.new_leaves_allocated) def test_creation_of_leave_ledger_entry_on_submit(self): - frappe.db.sql("delete from `tabLeave Allocation`") - - leave_allocation = create_leave_allocation() + leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name + ) leave_allocation.submit() leave_ledger_entry = frappe.get_all('Leave Ledger Entry', fields='*', filters=dict(transaction_name=leave_allocation.name)) @@ -169,10 +180,10 @@ class TestLeaveAllocation(unittest.TestCase): self.assertFalse(frappe.db.exists("Leave Ledger Entry", {'transaction_name':leave_allocation.name})) def test_leave_addition_after_submit(self): - frappe.db.sql("delete from `tabLeave Allocation`") - frappe.db.sql("delete from `tabLeave Ledger Entry`") - - leave_allocation = create_leave_allocation() + leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name + ) leave_allocation.submit() self.assertTrue(leave_allocation.total_leaves_allocated, 15) leave_allocation.new_leaves_allocated = 40 @@ -180,44 +191,55 @@ class TestLeaveAllocation(unittest.TestCase): self.assertTrue(leave_allocation.total_leaves_allocated, 40) def test_leave_subtraction_after_submit(self): - frappe.db.sql("delete from `tabLeave Allocation`") - frappe.db.sql("delete from `tabLeave Ledger Entry`") - leave_allocation = create_leave_allocation() + leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name + ) leave_allocation.submit() self.assertTrue(leave_allocation.total_leaves_allocated, 15) leave_allocation.new_leaves_allocated = 10 leave_allocation.submit() self.assertTrue(leave_allocation.total_leaves_allocated, 10) - def test_against_leave_application_validation_after_submit(self): - frappe.db.sql("delete from `tabLeave Allocation`") - frappe.db.sql("delete from `tabLeave Ledger Entry`") + def test_validation_against_leave_application_after_submit(self): + from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list - leave_allocation = create_leave_allocation() + make_holiday_list() + frappe.db.set_value("Company", self.employee.company, "default_holiday_list", "Salary Slip Test Holiday List") + + leave_allocation = create_leave_allocation( + employee=self.employee.name, + employee_name=self.employee.employee_name + ) leave_allocation.submit() self.assertTrue(leave_allocation.total_leaves_allocated, 15) - employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) + leave_application = frappe.get_doc({ "doctype": 'Leave Application', - "employee": employee.name, + "employee": self.employee.name, "leave_type": "_Test Leave Type", "from_date": add_months(nowdate(), 2), "to_date": add_months(add_days(nowdate(), 10), 2), - "company": erpnext.get_default_company() or "_Test Company", + "company": self.employee.company, "docstatus": 1, "status": "Approved", "leave_approver": 'test@example.com' }) leave_application.submit() - leave_allocation.new_leaves_allocated = 8 - leave_allocation.total_leaves_allocated = 8 + leave_application.reload() + + # allocate less leaves than the ones which are already approved + leave_allocation.new_leaves_allocated = leave_application.total_leave_days - 1 + leave_allocation.total_leaves_allocated = leave_application.total_leave_days - 1 self.assertRaises(frappe.ValidationError, leave_allocation.submit) def create_leave_allocation(**args): args = frappe._dict(args) - employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0]) - leave_allocation = frappe.get_doc({ + emp_id = make_employee("test_emp_leave_allocation@salary.com") + employee = frappe.get_doc("Employee", emp_id) + + return frappe.get_doc({ "doctype": "Leave Allocation", "__islocal": 1, "employee": args.employee or employee.name, @@ -228,6 +250,5 @@ def create_leave_allocation(**args): "carry_forward": args.carry_forward or 0, "to_date": args.to_date or add_months(nowdate(), 12) }) - return leave_allocation test_dependencies = ["Employee", "Leave Type"] From bffe329ade05d302df025ac00251c3e9c4c7dab6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 27 Dec 2021 21:23:50 +0530 Subject: [PATCH 6/6] fix: filter out Claimed employee advances in Expense Claim (#29046) (#29047) (cherry picked from commit 25f4de80b374ed1526d3490e613bb6cfdf4bba39) Co-authored-by: Rucha Mahabal --- erpnext/hr/doctype/expense_claim/expense_claim.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 665556301bb..047945787d7 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -171,7 +171,7 @@ frappe.ui.form.on("Expense Claim", { ['docstatus', '=', 1], ['employee', '=', frm.doc.employee], ['paid_amount', '>', 0], - ['paid_amount', '>', 'claimed_amount'] + ['status', '!=', 'Claimed'] ] }; });