Payroll fixes (#14758)

* Ignore calculating tds if amount/formula is mentioned in salary structure

* [fix] Paid amount in Journal Entry from Payroll Entry

* fix codacy
This commit is contained in:
Nabin Hait 2018-07-01 16:43:34 +05:30 committed by GitHub
parent b1a756cc9f
commit e3daaa63f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 2769 additions and 2678 deletions

File diff suppressed because it is too large Load Diff

View File

@ -251,7 +251,7 @@ let make_bank_entry = function (frm) {
); );
}, },
freeze: true, freeze: true,
freeze_message: __("Creating Bank Entries......") freeze_message: __("Creating Payment Entries......")
}); });
} else { } else {
frappe.msgprint(__("Company, Payment Account, From Date and To Date is mandatory")); frappe.msgprint(__("Company, Payment Account, From Date and To Date is mandatory"));

View File

@ -342,13 +342,17 @@ class PayrollEntry(Document):
for salary_slip_name in salary_slip_name_list: for salary_slip_name in salary_slip_name_list:
salary_slip = frappe.get_doc("Salary Slip", salary_slip_name[0]) salary_slip = frappe.get_doc("Salary Slip", salary_slip_name[0])
for sal_detail in salary_slip.earnings: for sal_detail in salary_slip.earnings:
is_flexible_benefit, only_tax_impact, creat_separate_je = frappe.db.get_value("Salary Component", \ is_flexible_benefit, only_tax_impact, creat_separate_je, statistical_component = frappe.db.get_value("Salary Component", sal_detail.salary_component,
sal_detail.salary_component, ['is_flexible_benefit', 'only_tax_impact', 'create_separate_payment_entry_against_benefit_claim']) ['is_flexible_benefit', 'only_tax_impact', 'create_separate_payment_entry_against_benefit_claim', 'statistical_component'])
if only_tax_impact != 1: if only_tax_impact != 1 and statistical_component != 1:
if is_flexible_benefit == 1 and creat_separate_je == 1: if is_flexible_benefit == 1 and creat_separate_je == 1:
self.create_journal_entry(sal_detail.amount, sal_detail.salary_component) self.create_journal_entry(sal_detail.amount, sal_detail.salary_component)
else: else:
salary_slip_total += sal_detail.amount salary_slip_total += sal_detail.amount
for sal_detail in salary_slip.deductions:
statistical_component = frappe.db.get_value("Salary Component", sal_detail.salary_component, 'statistical_component')
if statistical_component != 1:
salary_slip_total -= sal_detail.amount
if salary_slip_total > 0: if salary_slip_total > 0:
self.create_journal_entry(salary_slip_total, "salary") self.create_journal_entry(salary_slip_total, "salary")
@ -383,7 +387,6 @@ class PayrollEntry(Document):
ss_list = self.get_sal_slip_list(ss_status=1) ss_list = self.get_sal_slip_list(ss_status=1)
for ss in ss_list: for ss in ss_list:
ss_obj = frappe.get_doc("Salary Slip",ss[0]) ss_obj = frappe.get_doc("Salary Slip",ss[0])
frappe.db.set_value("Salary Slip", ss_obj.name, "status", "Paid")
frappe.db.set_value("Salary Slip", ss_obj.name, "journal_entry", jv_name) frappe.db.set_value("Salary Slip", ss_obj.name, "journal_entry", jv_name)
def set_start_end_dates(self): def set_start_end_dates(self):

View File

@ -42,7 +42,7 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"translatable": 0, "translatable": 0,
"unique": 0 "unique": 1
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
@ -703,7 +703,7 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "eval:doc.is_payable == 1 && doc.statistical_component != 1", "depends_on": "eval:doc.statistical_component != 1",
"fieldname": "section_break_5", "fieldname": "section_break_5",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -1003,7 +1003,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-06-29 13:59:12.958648", "modified": "2018-06-29 17:44:14.491265",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Component", "name": "Salary Component",
@ -1057,4 +1057,4 @@
"sort_order": "DESC", "sort_order": "DESC",
"track_changes": 0, "track_changes": 0,
"track_seen": 0 "track_seen": 0
} }

View File

@ -22,6 +22,14 @@ class SalarySlip(TransactionBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SalarySlip, self).__init__(*args, **kwargs) super(SalarySlip, self).__init__(*args, **kwargs)
self.series = 'Sal Slip/{0}/.#####'.format(self.employee) self.series = 'Sal Slip/{0}/.#####'.format(self.employee)
self.whitelisted_globals = {
"int": int,
"float": float,
"long": int,
"round": round,
"date": datetime.date,
"getdate": getdate
}
def autoname(self): def autoname(self):
self.name = make_autoname(self.series) self.name = make_autoname(self.series)
@ -64,7 +72,7 @@ class SalarySlip(TransactionBase):
for key in ('earnings', 'deductions'): for key in ('earnings', 'deductions'):
for struct_row in self._salary_structure_doc.get(key): for struct_row in self._salary_structure_doc.get(key):
amount = self.eval_condition_and_formula(struct_row, data) amount = self.eval_condition_and_formula(struct_row, data)
if amount and struct_row.statistical_component == 0 and struct_row.variable_based_on_taxable_salary != 1: if amount and struct_row.statistical_component == 0:
self.update_component_row(struct_row, amount, key) self.update_component_row(struct_row, amount, key)
if key=="earnings" and struct_row.is_flexible_benefit == 1: if key=="earnings" and struct_row.is_flexible_benefit == 1:
@ -84,7 +92,7 @@ class SalarySlip(TransactionBase):
# Calculate variable_based_on_taxable_salary after all components updated in salary slip # Calculate variable_based_on_taxable_salary after all components updated in salary slip
for struct_row in self._salary_structure_doc.get("deductions"): for struct_row in self._salary_structure_doc.get("deductions"):
if struct_row.variable_based_on_taxable_salary == 1: if struct_row.variable_based_on_taxable_salary == 1 and not struct_row.formula and not struct_row.amount:
tax_row, amount = self.calculate_variable_based_on_taxable_salary(struct_row.salary_component) tax_row, amount = self.calculate_variable_based_on_taxable_salary(struct_row.salary_component)
if tax_row and amount: if tax_row and amount:
self.update_component_row(frappe._dict(tax_row), amount, "deductions") self.update_component_row(frappe._dict(tax_row), amount, "deductions")
@ -143,13 +151,13 @@ class SalarySlip(TransactionBase):
try: try:
condition = d.condition.strip() if d.condition else None condition = d.condition.strip() if d.condition else None
if condition: if condition:
if not frappe.safe_eval(condition, None, data): if not frappe.safe_eval(condition, self.whitelisted_globals, data):
return None return None
amount = d.amount amount = d.amount
if d.amount_based_on_formula: if d.amount_based_on_formula:
formula = d.formula.strip() if d.formula else None formula = d.formula.strip() if d.formula else None
if formula: if formula:
amount = frappe.safe_eval(formula, None, data) amount = frappe.safe_eval(formula, self.whitelisted_globals, data)
if amount: if amount:
data[d.abbr] = amount data[d.abbr] = amount
@ -761,17 +769,10 @@ class SalarySlip(TransactionBase):
return taxable_amount return taxable_amount
def eval_tax_slab_condition(self, condition, data): def eval_tax_slab_condition(self, condition, data):
whitelisted_globals = {
"int": int,
"float": float,
"long": int,
"round": round,
"date": datetime.date
}
try: try:
condition = condition.strip() condition = condition.strip()
if condition: if condition:
return frappe.safe_eval(condition, whitelisted_globals, data) return frappe.safe_eval(condition, self.whitelisted_globals, data)
except NameError as err: except NameError as err:
frappe.throw(_("Name error: {0}".format(err))) frappe.throw(_("Name error: {0}".format(err)))
except SyntaxError as err: except SyntaxError as err: