fix: removed expense claim, advance and salary slip updates from PE/JE events
- moved them to HRMS app hooks
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 1451189..0260eae 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -24,7 +24,6 @@
get_stock_and_account_balance,
)
from erpnext.controllers.accounts_controller import AccountsController
-from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
class StockAccountInvalidTransaction(frappe.ValidationError):
@@ -66,7 +65,6 @@
self.set_against_account()
self.create_remarks()
self.set_print_format_fields()
- self.validate_expense_claim()
self.validate_credit_debit_note()
self.validate_empty_accounts_table()
self.set_account_and_party_balance()
@@ -83,21 +81,17 @@
self.check_credit_limit()
self.make_gl_entries()
self.update_advance_paid()
- self.update_expense_claim()
self.update_inter_company_jv()
self.update_invoice_discounting()
self.update_status_for_full_and_final_statement()
def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
- from erpnext.payroll.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
unlink_ref_doc_from_payment_entries(self)
- unlink_ref_doc_from_salary_slip(self.name)
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Payment Ledger Entry")
self.make_gl_entries(1)
self.update_advance_paid()
- self.update_expense_claim()
self.unlink_advance_entry_reference()
self.unlink_asset_reference()
self.unlink_inter_company_jv()
@@ -932,29 +926,6 @@
as_dict=True,
)
- def update_expense_claim(self):
- for d in self.accounts:
- if d.reference_type == "Expense Claim" and d.reference_name:
- doc = frappe.get_doc("Expense Claim", d.reference_name)
- if self.docstatus == 2:
- update_reimbursed_amount(doc, -1 * d.debit)
- else:
- update_reimbursed_amount(doc, d.debit)
-
- def validate_expense_claim(self):
- for d in self.accounts:
- if d.reference_type == "Expense Claim":
- sanctioned_amount, reimbursed_amount = frappe.db.get_value(
- "Expense Claim", d.reference_name, ("total_sanctioned_amount", "total_amount_reimbursed")
- )
- pending_amount = flt(sanctioned_amount) - flt(reimbursed_amount)
- if d.debit > pending_amount:
- frappe.throw(
- _(
- "Row No {0}: Amount cannot be greater than Pending Amount against Expense Claim {1}. Pending Amount is {2}"
- ).format(d.idx, d.reference_name, pending_amount)
- )
-
def validate_credit_debit_note(self):
if self.stock_entry:
if frappe.db.get_value("Stock Entry", self.stock_entry, "docstatus") != 1:
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index a10a810..c9746ab 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -29,7 +29,6 @@
get_supplier_block_status,
validate_taxes_and_charges,
)
-from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
from erpnext.setup.utils import get_exchange_rate
@@ -88,7 +87,6 @@
if self.difference_amount:
frappe.throw(_("Difference Amount must be zero"))
self.make_gl_entries()
- self.update_expense_claim()
self.update_outstanding_amounts()
self.update_advance_paid()
self.update_payment_schedule()
@@ -97,7 +95,6 @@
def on_cancel(self):
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Payment Ledger Entry")
self.make_gl_entries(cancel=1)
- self.update_expense_claim()
self.update_outstanding_amounts()
self.update_advance_paid()
self.delink_advance_entry_references()
@@ -985,16 +982,6 @@
):
frappe.get_doc(d.reference_doctype, d.reference_name).set_total_advance_paid()
- def update_expense_claim(self):
- if self.payment_type in ("Pay") and self.party:
- for d in self.get("references"):
- if d.reference_doctype == "Expense Claim" and d.reference_name:
- doc = frappe.get_doc("Expense Claim", d.reference_name)
- if self.docstatus == 2:
- update_reimbursed_amount(doc, -1 * d.allocated_amount)
- else:
- update_reimbursed_amount(doc, d.allocated_amount)
-
def on_recurring(self, reference_doc, auto_repeat_doc):
self.reference_no = reference_doc.name
self.reference_date = nowdate()
diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
index a8211c8..6fabd68 100644
--- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
@@ -18,7 +18,6 @@
create_sales_invoice,
create_sales_invoice_against_cost_center,
)
-from erpnext.hr.doctype.expense_claim.test_expense_claim import make_expense_claim
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
test_dependencies = ["Item"]
@@ -293,31 +292,6 @@
self.assertEqual(flt(outstanding_amount), 250)
self.assertEqual(status, "Unpaid")
- def test_payment_entry_against_ec(self):
-
- payable = frappe.get_cached_value("Company", "_Test Company", "default_payable_account")
- ec = make_expense_claim(payable, 300, 300, "_Test Company", "Travel Expenses - _TC")
- pe = get_payment_entry(
- "Expense Claim", ec.name, bank_account="_Test Bank USD - _TC", bank_amount=300
- )
- pe.reference_no = "1"
- pe.reference_date = "2016-01-01"
- pe.source_exchange_rate = 1
- pe.paid_to = payable
- pe.insert()
- pe.submit()
-
- expected_gle = dict(
- (d[0], d) for d in [[payable, 300, 0, ec.name], ["_Test Bank USD - _TC", 0, 300, None]]
- )
-
- self.validate_gl_entries(pe.name, expected_gle)
-
- outstanding_amount = flt(
- frappe.db.get_value("Expense Claim", ec.name, "total_sanctioned_amount")
- ) - flt(frappe.db.get_value("Expense Claim", ec.name, "total_amount_reimbursed"))
- self.assertEqual(outstanding_amount, 0)
-
def test_payment_entry_against_si_usd_to_inr(self):
si = create_sales_invoice(
customer="_Test Customer USD",