Skip to content

Commit

Permalink
Merge pull request #26 from ruchamahabal/port-fixes
Browse files Browse the repository at this point in the history
fix: Salary Slip & Expense Claim fixes
  • Loading branch information
ruchamahabal authored Jul 29, 2022
2 parents 5e67388 + b6f845a commit 9e6280e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/helper/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sed -i 's/schedule:/# schedule:/g' Procfile
sed -i 's/socketio:/# socketio:/g' Procfile
sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile

bench get-app payments
bench get-app https://github.com/frappe/erpnext --branch develop
bench setup requirements --dev

Expand Down
9 changes: 4 additions & 5 deletions hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ def validate_advances(self):

if self.total_advance_amount:
precision = self.precision("total_advance_amount")
if flt(self.total_advance_amount, precision) > flt(self.total_claimed_amount, precision):
frappe.throw(_("Total advance amount cannot be greater than total claimed amount"))
amount_with_taxes = flt(self.total_sanctioned_amount, precision) + flt(
self.total_taxes_and_charges, precision
)

if self.total_sanctioned_amount and flt(self.total_advance_amount, precision) > flt(
self.total_sanctioned_amount, precision
):
if flt(self.total_advance_amount, precision) > amount_with_taxes:
frappe.throw(_("Total advance amount cannot be greater than total sanctioned amount"))

def validate_sanctioned_amount(self):
Expand Down
41 changes: 38 additions & 3 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,40 @@ def test_expense_claim_against_fully_paid_advances(self):
self.assertEqual(claim.grand_total, 0)
self.assertEqual(claim.status, "Paid")

def test_advance_amount_allocation_against_claim_with_taxes(self):
from hrms.hr.doctype.employee_advance.test_employee_advance import (
get_advances_for_claim,
make_employee_advance,
make_payment_entry,
)

frappe.db.delete("Employee Advance")

payable_account = get_payable_account("_Test Company")
taxes = generate_taxes("_Test Company")
claim = make_expense_claim(
payable_account,
700,
700,
"_Test Company",
"Travel Expenses - _TC",
do_not_submit=True,
taxes=taxes,
)
claim.save()

advance = make_employee_advance(claim.employee)
pe = make_payment_entry(advance)
pe.submit()

# claim for already paid out advances
claim = get_advances_for_claim(claim, advance.name, 763)
claim.save()
claim.submit()

self.assertEqual(claim.grand_total, 0)
self.assertEqual(claim.status, "Paid")

def test_expense_claim_partially_paid_via_advance(self):
from hrms.hr.doctype.employee_advance.test_employee_advance import (
get_advances_for_claim,
Expand Down Expand Up @@ -322,12 +356,13 @@ def get_payable_account(company):
return frappe.get_cached_value("Company", company, "default_payable_account")


def generate_taxes():
def generate_taxes(company=None):
company = company or company_name
parent_account = frappe.db.get_value(
"Account", {"company": company_name, "is_group": 1, "account_type": "Tax"}, "name"
"Account", filters={"account_name": "Duties and Taxes", "company": company}
)
account = create_account(
company=company_name,
company=company,
account_name="Output Tax CGST",
account_type="Tax",
parent_account=parent_account,
Expand Down
13 changes: 12 additions & 1 deletion hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,20 @@ def calculate_component_amounts(self, component_type):

def add_structure_components(self, component_type):
data = self.get_data_for_eval()
timesheet_component = frappe.db.get_value(
"Salary Structure", self.salary_structure, "salary_component"
)

for struct_row in self._salary_structure_doc.get(component_type):
if self.salary_slip_based_on_timesheet and struct_row.salary_component == timesheet_component:
continue

amount = self.eval_condition_and_formula(struct_row, data)
if amount is not None and struct_row.statistical_component == 0:
if (
amount
or (struct_row.amount_based_on_formula and amount is not None)
and struct_row.statistical_component == 0
):
self.update_component_row(struct_row, amount, component_type, data=data)

def get_data_for_eval(self):
Expand Down
16 changes: 16 additions & 0 deletions hrms/payroll/doctype/salary_structure/salary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def validate(self):
self.validate_max_benefits_with_flexi()
self.validate_component_based_on_tax_slab()
self.validate_payment_days_based_dependent_component()
self.validate_timesheet_component()

def set_missing_values(self):
overwritten_fields = [
Expand Down Expand Up @@ -89,6 +90,21 @@ def get_component_abbreviations(self):

return abbr

def validate_timesheet_component(self):
if not self.salary_slip_based_on_timesheet:
return

for component in self.earnings:
if component.salary_component == self.salary_component:
frappe.msgprint(
_(
"Row #{0}: Timesheet amount will overwrite the Earning component amount for the Salary Component {1}"
).format(self.idx, frappe.bold(self.salary_component)),
title=_("Warning"),
indicator="orange",
)
break

def strip_condition_and_formula_fields(self):
# remove whitespaces from condition and formula fields
for row in self.earnings:
Expand Down

0 comments on commit 9e6280e

Please sign in to comment.