From b88af3a3f79e4cfd3d8db321b34c48ae276f5087 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Mon, 2 Nov 2020 18:35:03 +0530 Subject: [PATCH] feat: Accrural Entry for Gratuity beafore Payment --- .../doctype/payment_entry/payment_entry.py | 2 +- erpnext/payroll/doctype/gratuity/gratuity.js | 10 ++++ .../payroll/doctype/gratuity/gratuity.json | 20 +++++++- erpnext/payroll/doctype/gratuity/gratuity.py | 50 ++++++++++++++++++- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index df49667ed2..123db7ee9c 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1182,7 +1182,7 @@ def set_party_account(dt, dn, doc, party_type): elif dt == "Expense Claim": party_account = doc.payable_account elif dt == "Gratuity": - party_account = doc.expense_account + party_account = doc.payable_account else: party_account = get_party_account(party_type, doc.get(party_type.lower()), doc.company) return party_account diff --git a/erpnext/payroll/doctype/gratuity/gratuity.js b/erpnext/payroll/doctype/gratuity/gratuity.js index dfdf08bdea..9118ccc99d 100644 --- a/erpnext/payroll/doctype/gratuity/gratuity.js +++ b/erpnext/payroll/doctype/gratuity/gratuity.js @@ -19,6 +19,16 @@ frappe.ui.form.on('Gratuity', { } }; }); + + frm.set_query("payable_account", function() { + return { + filters: { + "root_type": "Liability", + "is_group": 0, + "company": frm.doc.company + } + }; + }); }, refresh: function(frm){ if(frm.doc.docstatus === 1 && frm.doc.pay_via_salary_slip === 0 && frm.doc.status === "Unpaid") { diff --git a/erpnext/payroll/doctype/gratuity/gratuity.json b/erpnext/payroll/doctype/gratuity/gratuity.json index b81ae588ea..5cffd7eebf 100644 --- a/erpnext/payroll/doctype/gratuity/gratuity.json +++ b/erpnext/payroll/doctype/gratuity/gratuity.json @@ -19,8 +19,10 @@ "pay_via_salary_slip", "payroll_date", "salary_component", + "payable_account", "expense_account", "mode_of_payment", + "cost_center", "column_break_15", "current_work_experience", "amount", @@ -173,12 +175,28 @@ "fieldtype": "Currency", "label": "Paid Amount", "read_only": 1 + }, + { + "depends_on": "eval: doc.pay_via_salary_slip == 0", + "fieldname": "payable_account", + "fieldtype": "Link", + "label": "Payable Account", + "mandatory_depends_on": "eval: doc.pay_via_salary_slip == 0", + "options": "Account" + }, + { + "depends_on": "eval: doc.pay_via_salary_slip == 0", + "fieldname": "cost_center", + "fieldtype": "Link", + "label": "Cost Center", + "mandatory_depends_on": "eval: doc.pay_via_salary_slip == 0", + "options": "Cost Center" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-10-27 14:04:41.886934", + "modified": "2020-11-02 18:21:11.971488", "modified_by": "Administrator", "module": "Payroll", "name": "Gratuity", diff --git a/erpnext/payroll/doctype/gratuity/gratuity.py b/erpnext/payroll/doctype/gratuity/gratuity.py index db353e9d71..b09419116d 100644 --- a/erpnext/payroll/doctype/gratuity/gratuity.py +++ b/erpnext/payroll/doctype/gratuity/gratuity.py @@ -7,9 +7,11 @@ import frappe from frappe import _, bold from frappe.model.document import Document from frappe.utils import flt, get_datetime, get_link_to_form +from erpnext.accounts.general_ledger import make_gl_entries +from erpnext.controllers.accounts_controller import AccountsController from math import floor -class Gratuity(Document): +class Gratuity(AccountsController): def validate(self): data = calculate_work_experience_and_amount(self.employee, self.gratuity_rule) self.current_work_experience = data["current_work_experience"] @@ -18,7 +20,51 @@ class Gratuity(Document): self.status = "Unpaid" def on_submit(self): - self.create_additional_salary() + if self.pay_via_salary_slip: + self.create_additional_salary() + else: + self.create_gl_entries() + + def on_cancel(self): + self.ignore_linked_doctypes = ['GL Entry'] + self.create_gl_entries(cancel=True) + + def create_gl_entries(self, cancel=False): + gl_entries = self.get_gl_entries() + make_gl_entries(gl_entries, cancel) + + def get_gl_entries(self): + gl_entry = [] + # payable entry + if self.amount: + gl_entry.append( + self.get_gl_dict({ + "account": self.payable_account, + "credit": self.amount, + "credit_in_account_currency": self.amount, + "against": self.expense_account, + "party_type": "Employee", + "party": self.employee, + "against_voucher_type": self.doctype, + "against_voucher": self.name, + "cost_center": self.cost_center + }, item=self) + ) + + # expense entries + gl_entry.append( + self.get_gl_dict({ + "account": self.expense_account, + "debit": self.amount, + "debit_in_account_currency": self.amount, + "against": self.employee, + "cost_center": self.cost_center + }, item=self) + ) + else: + frappe.throw(_("Total Amount can not be zero")) + + return gl_entry def create_additional_salary(self): if self.pay_via_salary_slip: