feat: Accrural Entry for Gratuity beafore Payment

This commit is contained in:
Anurag Mishra 2020-11-02 18:35:03 +05:30
parent 78fdd5d9b4
commit b88af3a3f7
4 changed files with 78 additions and 4 deletions

View File

@ -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

View File

@ -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") {

View File

@ -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",

View File

@ -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: