[WIP] Process Payroll Changes

This commit is contained in:
Kanchan Chauhan 2016-08-26 11:11:17 +05:30
parent 1f53aaf093
commit b40c0a917d
21 changed files with 787 additions and 198 deletions

View File

@ -62,12 +62,14 @@ class JournalEntry(AccountsController):
def on_cancel(self): def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
from erpnext.hr.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
unlink_ref_doc_from_payment_entries(self.doctype, self.name) unlink_ref_doc_from_payment_entries(self.doctype, self.name)
unlink_ref_doc_from_salary_slip(self.name)
self.make_gl_entries(1) self.make_gl_entries(1)
self.update_advance_paid() self.update_advance_paid()
self.update_expense_claim() self.update_expense_claim()
def validate_party(self): def validate_party(self):
for d in self.get("accounts"): for d in self.get("accounts"):
account_type = frappe.db.get_value("Account", d.account, "account_type") account_type = frappe.db.get_value("Account", d.account, "account_type")

View File

@ -14,6 +14,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -40,7 +41,8 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.", "columns": 0,
"description": "Default Bank / Cash account will be automatically updated in Salary Journal Entry when this mode is selected.",
"fieldname": "default_account", "fieldname": "default_account",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -74,7 +76,7 @@
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-07-27 17:24:24.956896", "modified": "2016-09-02 07:49:06.567389",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Salary Component Account", "name": "Salary Component Account",

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 216 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

After

Width:  |  Height:  |  Size: 413 KiB

View File

@ -81,6 +81,12 @@ In the “Earnings” and “Deductions” tables, you can calculate the values
* Only Formula * Only Formula
* Only Amount * Only Amount
#### Figure 1.5:Account Details
<img class="screenshot" alt="Salary Structure" src="{{docs_base_url}}/assets/img/human-resources/salary-structure-account.png">
* Select Mode of Payment and Payment Account for the Salary Slips which will be generated using this Salary Structure
Save the Salary Structure. Save the Salary Structure.
In conditions and formulas, In conditions and formulas,
@ -128,8 +134,10 @@ You can also create salary slip for multiple employees using Process Payroll:
In Process Payroll, In Process Payroll,
1. Select the Company for which you want to create the Salary Slips. 1. Select the Company for which you want to create the Salary Slips.
2. Select the Month and the Year for which you want to create the Salary Slips. 2. Check "Salary Slip based on Timesheet" if you want to process timesheet based Salary Slips.
3. Click on “Create Salary Slips”. This will create Salary Slip records for each active Employee for the month selected. If the Salary Slips are created, the system will not create any more Salary Slips. All updates will be shown in the “Activity Log” section. 3. Select the From Date and To Date or Fiscal year and month for which you want to create the Salary Slips.
3. Select the Payment Account.
3. Click on “Create Salary Slips”. This will create Salary Slip records for each active Employee for the time period selected. If the Salary Slips are created, the system will not create any more Salary Slips. All updates will be shown in the “Activity Log” section.
4. Once all Salary Slips are created, you can check if they are created correctly or edit it if you want to deduct Leave Without Pay (LWP). 4. Once all Salary Slips are created, you can check if they are created correctly or edit it if you want to deduct Leave Without Pay (LWP).
5. After checking, you can “Submit” them all together by clicking on “Submit Salary Slips”. 1. If you want them to be automatically emailed to the Employee, make sure to check the “Send Email” box. 5. After checking, you can “Submit” them all together by clicking on “Submit Salary Slips”. 1. If you want them to be automatically emailed to the Employee, make sure to check the “Send Email” box.
@ -144,12 +152,19 @@ there is only one payment entry in the companys books of accounts and anyone
with access to the companys accounts will not have access to the individual with access to the companys accounts will not have access to the individual
salaries. salaries.
The salary payment entry is a Journal Entry entry that debits the total The salary payment entry is a Journal Entry that debits the total of the
salary of all Employees to the Salary Account and credits the companys bank earning type salary component and credits the total of deduction type salary
Account. component of all Employees to the default account set at Salary Component level
for each component.
To generate your salary payment voucher from Process Payroll, click on To generate your salary payment voucher from Process Payroll, click on
“Make Bank Voucher” and a new Journal Entry with the total salaries will be “Make Bank Entry”. It will ask to enter the Bank Transaction Reference Number and date.
Click on "Make" and a new Journal Entry with the total salary components will be
created. created.
#### Figure 3.1: Make Bank Entry
<img class="screenshot" alt="Process Payroll" src="{{docs_base_url}}/assets/img/human-resources/bank-entry.png">
{next} {next}

View File

@ -1,6 +1,62 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.ui.form.on("Process Payroll", {
refresh: function(frm) {
frm.disable_save();
frm.trigger("toggle_fields");
frm.trigger("set_month_dates");
},
month: function(frm) {
frm.trigger("set_month_dates");
},
fiscal_year: function(frm) {
frm.trigger("set_month_dates");
},
salary_slip_based_on_timesheet: function(frm) {
frm.trigger("toggle_fields")
},
toggle_fields: function(frm) {
frm.toggle_display(['from_date','to_date'],
cint(frm.doc.salary_slip_based_on_timesheet)==1);
frm.toggle_display(['fiscal_year', 'month'],
cint(frm.doc.salary_slip_based_on_timesheet)==0);
},
set_month_dates: function(frm) {
if (!frm.doc.salary_slip_based_on_timesheet){
frappe.call({
method:'erpnext.hr.doctype.process_payroll.process_payroll.get_month_details',
args:{
year: frm.doc.fiscal_year,
month: frm.doc.month
},
callback: function(r){
if (r.message){
frm.set_value('from_date', r.message.month_start_date);
frm.set_value('to_date', r.message.month_end_date);
}
}
})
}
}
})
cur_frm.cscript.onload = function(doc,cdt,cdn){
if(!doc.month) {
var today=new Date();
month = (today.getMonth()+01).toString();
if(month.length>1) doc.month = month;
else doc.month = '0'+month;
}
if(!doc.fiscal_year) doc.fiscal_year = sys_defaults['fiscal_year'];
refresh_many(['month', 'fiscal_year']);
}
cur_frm.cscript.display_activity_log = function(msg) { cur_frm.cscript.display_activity_log = function(msg) {
if(!cur_frm.ss_html) if(!cur_frm.ss_html)
cur_frm.ss_html = $a(cur_frm.fields_dict['activity_log'].wrapper,'div'); cur_frm.ss_html = $a(cur_frm.fields_dict['activity_log'].wrapper,'div');
@ -26,7 +82,7 @@ cur_frm.cscript.create_salary_slip = function(doc, cdt, cdn) {
cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) { cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) {
cur_frm.cscript.display_activity_log(""); cur_frm.cscript.display_activity_log("");
frappe.confirm(__("Do you really want to Submit all Salary Slip for month {0} and year {1}", [doc.month, doc.fiscal_year]), function() { frappe.confirm(__("Do you really want to Submit all Salary Slip for Account {0} from {1} to {2}", [doc.payment_account, doc.from_date, doc.to_date]), function() {
// clear all in locals // clear all in locals
if(locals["Salary Slip"]) { if(locals["Salary Slip"]) {
$.each(locals["Salary Slip"], function(name, d) { $.each(locals["Salary Slip"], function(name, d) {
@ -44,22 +100,45 @@ cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) {
} }
cur_frm.cscript.make_bank_entry = function(doc,cdt,cdn){ cur_frm.cscript.make_bank_entry = function(doc,cdt,cdn){
if(doc.company && doc.month && doc.fiscal_year){ if(doc.company && doc.from_date && doc.to_date){
cur_frm.cscript.make_jv(doc, cdt, cdn); return cur_frm.cscript.reference_entry(doc,cdt,cdn);
} else { } else {
msgprint(__("Company, Month and Fiscal Year is mandatory")); msgprint(__("Company, From Date and To Date is mandatory"));
} }
} }
cur_frm.cscript.make_jv = function(doc, dt, dn) { cur_frm.cscript.reference_entry = function(doc,cdt,cdn){
return $c_obj(doc, 'make_journal_entry', '', function(r) { var dialog = new frappe.ui.Dialog({
var doc = frappe.model.sync(r.message)[0]; title: __("Bank Transaction Reference"),
frappe.set_route("Form", doc.doctype, doc.name); fields: [
{
"label": __("Reference Number"),
"fieldname": "reference_number",
"fieldtype": "Data",
"reqd": 1
},
{
"label": __("Reference Date"),
"fieldname": "reference_date",
"fieldtype": "Date",
"reqd": 1,
"default": get_today()
}
]
}); });
} dialog.set_primary_action(__("Make"), function() {
args = dialog.get_values();
frappe.ui.form.on("Process Payroll", { if(!args) return;
refresh: function(frm) { dialog.hide();
frm.disable_save(); return frappe.call({
doc: cur_frm.doc,
method: "make_journal_entry",
args: {"reference_number": args.reference_number, "reference_date":args.reference_date},
callback: function(r) {
if (r.message)
cur_frm.cscript.display_activity_log(r.message);
} }
}) });
});
dialog.show();
}

View File

@ -8,11 +8,13 @@
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"document_type": "Other", "document_type": "Other",
"editable_grid": 0,
"fields": [ "fields": [
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "section_break0", "fieldname": "section_break0",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -37,6 +39,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break0", "fieldname": "column_break0",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -61,6 +64,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -86,253 +90,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "branch", "columns": 0,
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Branch",
"length": 0,
"no_copy": 0,
"options": "Branch",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break1",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "department",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Department",
"length": 0,
"no_copy": 0,
"options": "Department",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "designation",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Designation",
"length": 0,
"no_copy": 0,
"options": "Designation",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "section_break_8",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "salary_slip_based_on_timesheet",
"fieldtype": "Check",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Salary Slip Based on Timesheet",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "select_payroll_year_and_month",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Select Payroll Year and Month",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "fiscal_year",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Fiscal Year",
"length": 0,
"no_copy": 0,
"options": "Fiscal Year",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_11",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "month",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Month",
"length": 0,
"no_copy": 0,
"options": "\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"default": "Today", "default": "Today",
"fieldname": "posting_date", "fieldname": "posting_date",
"fieldtype": "Date", "fieldtype": "Date",
@ -359,6 +117,316 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break1",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "branch",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Branch",
"length": 0,
"no_copy": 0,
"options": "Branch",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "department",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Department",
"length": 0,
"no_copy": 0,
"options": "Department",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "designation",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Designation",
"length": 0,
"no_copy": 0,
"options": "Designation",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "section_break_8",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "salary_slip_based_on_timesheet",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Salary Slip Based on Timesheet",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "select_payroll_period",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Select Payroll Period",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "from_date",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "From",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "fiscal_year",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Fiscal Year",
"length": 0,
"no_copy": 0,
"options": "Fiscal Year",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_11",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "to_date",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "To",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "month",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Month",
"length": 0,
"no_copy": 0,
"options": "\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "process_payroll", "fieldname": "process_payroll",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -384,6 +452,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break2", "fieldname": "column_break2",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -408,6 +477,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"description": "Creates salary slip for above mentioned criteria.", "description": "Creates salary slip for above mentioned criteria.",
"fieldname": "create_salary_slip", "fieldname": "create_salary_slip",
"fieldtype": "Button", "fieldtype": "Button",
@ -433,6 +503,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break3", "fieldname": "column_break3",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -457,6 +528,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"description": "Submit all salary slips for the above selected criteria", "description": "Submit all salary slips for the above selected criteria",
"fieldname": "submit_salary_slip", "fieldname": "submit_salary_slip",
"fieldtype": "Button", "fieldtype": "Button",
@ -482,16 +554,19 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "column_break4", "columns": 0,
"fieldtype": "Column Break", "fieldname": "account",
"fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Account",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"precision": "",
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
@ -499,13 +574,42 @@
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0, "unique": 0
"width": "25%"
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"description": "Select Payment Account to make Bank Entry",
"fieldname": "payment_account",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Account",
"length": 0,
"no_copy": 0,
"options": "Account",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "payment_account",
"description": "Create Bank Entry for the total salary paid for the above selected criteria", "description": "Create Bank Entry for the total salary paid for the above selected criteria",
"fieldname": "make_bank_entry", "fieldname": "make_bank_entry",
"fieldtype": "Button", "fieldtype": "Button",
@ -531,6 +635,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "section_break2", "fieldname": "section_break2",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -554,6 +659,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "activity_log", "fieldname": "activity_log",
"fieldtype": "HTML", "fieldtype": "HTML",
"hidden": 0, "hidden": 0,
@ -586,7 +692,7 @@
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-09-19 15:12:54.090381", "modified": "2016-09-28 05:43:26.472928",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Process Payroll", "name": "Process Payroll",

View File

@ -5,12 +5,13 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cint, flt, nowdate from frappe.utils import cint, flt, nowdate
from frappe import _ from frappe import _
import collections
from collections import defaultdict
from frappe.model.document import Document from frappe.model.document import Document
class ProcessPayroll(Document): class ProcessPayroll(Document):
def get_emp_list(self): def get_emp_list(self):
""" """
Returns list of active employees based on selected criteria Returns list of active employees based on selected criteria
@ -21,8 +22,9 @@ class ProcessPayroll(Document):
sal_struct = frappe.db.sql(""" sal_struct = frappe.db.sql("""
select name from `tabSalary Structure` select name from `tabSalary Structure`
where docstatus != 2 and where docstatus != 2 and payment_account = '%(payment_account)s' and
ifnull(salary_slip_based_on_timesheet,0) = 0""") ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s"""%
{"payment_account": self.payment_account, "salary_slip_based_on_timesheet":self.salary_slip_based_on_timesheet})
if sal_struct: if sal_struct:
cond += "and t2.parent IN %(sal_struct)s " cond += "and t2.parent IN %(sal_struct)s "
@ -48,16 +50,15 @@ class ProcessPayroll(Document):
def get_joining_releiving_condition(self): def get_joining_releiving_condition(self):
m = get_month_details(self.fiscal_year, self.month)
cond = """ cond = """
and ifnull(t1.date_of_joining, '0000-00-00') <= '%(month_end_date)s' and ifnull(t1.date_of_joining, '0000-00-00') <= '%(from_date)s'
and ifnull(t1.relieving_date, '2199-12-31') >= '%(month_start_date)s' and ifnull(t1.relieving_date, '2199-12-31') >= '%(to_date)s'
""" % m """ % {"from_date": self.from_date, "to_date": self.to_date}
return cond return cond
def check_mandatory(self): def check_mandatory(self):
for f in ['company', 'month', 'fiscal_year']: for f in ['company', 'from_date', 'to_date']:
if not self.get(f): if not self.get(f):
frappe.throw(_("Please set {0}").format(f)) frappe.throw(_("Please set {0}").format(f))
@ -65,27 +66,37 @@ class ProcessPayroll(Document):
""" """
Creates salary slip for selected employees if already not created Creates salary slip for selected employees if already not created
""" """
self.check_permission('write') self.check_permission('write')
emp_list = self.get_emp_list() emp_list = self.get_emp_list()
ss_list = [] ss_list = []
if emp_list:
for emp in emp_list: for emp in emp_list:
if not frappe.db.sql("""select name from `tabSalary Slip` if not frappe.db.sql("""select name from `tabSalary Slip`
where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s where docstatus!= 2 and employee = %s and start_date >= %s and end_date <= %s and company = %s
""", (emp[0], self.month, self.fiscal_year, self.company)): """, (emp[0], self.from_date, self.to_date, self.company)):
if self.salary_slip_based_on_timesheet:
ss = frappe.get_doc({ ss = frappe.get_doc({
"doctype": "Salary Slip", "doctype": "Salary Slip",
"salary_slip_based_on_timesheet": 0, "salary_slip_based_on_timesheet": self.salary_slip_based_on_timesheet,
"fiscal_year": self.fiscal_year, "start_date": self.from_date,
"end_date": self.to_date,
"employee": emp[0], "employee": emp[0],
"month": self.month,
"company": self.company, "company": self.company,
"posting_date": self.posting_date, "posting_date": self.posting_date
})
else:
ss = frappe.get_doc({
"doctype": "Salary Slip",
"salary_slip_based_on_timesheet": self.salary_slip_based_on_timesheet,
"fiscal_year": self.fiscal_year,
"month": self.month,
"employee": emp[0],
"company": self.company,
"posting_date": self.posting_date
}) })
ss.insert() ss.insert()
ss_list.append(ss.name) ss_list.append(ss.name)
return self.create_log(ss_list) return self.create_log(ss_list)
@ -97,16 +108,17 @@ class ProcessPayroll(Document):
return log return log
def get_sal_slip_list(self): def get_sal_slip_list(self, ss_status, as_dict=False):
""" """
Returns list of salary slips based on selected criteria Returns list of salary slips based on selected criteria
which are not submitted
""" """
cond = self.get_filter_condition() cond = self.get_filter_condition()
ss_list = frappe.db.sql(""" ss_list = frappe.db.sql("""
select t1.name from `tabSalary Slip` t1 select t1.name, t1.salary_structure from `tabSalary Slip` t1
where t1.docstatus = 0 and month = %s and fiscal_year = %s %s where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s
""" % ('%s', '%s', cond), (self.month, self.fiscal_year)) and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s %s
""" % ('%s', '%s', '%s','%s', cond), (ss_status, self.from_date, self.to_date, self.salary_slip_based_on_timesheet), as_dict=as_dict)
return ss_list return ss_list
@ -116,16 +128,17 @@ class ProcessPayroll(Document):
""" """
self.check_permission('write') self.check_permission('write')
ss_list = self.get_sal_slip_list() ss_list = self.get_sal_slip_list(ss_status=0)
not_submitted_ss = [] not_submitted_ss = []
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])
if ss_obj.net_pay<0:
not_submitted_ss.append(ss[0])
else:
try: try:
ss_obj.submit() ss_obj.submit()
except Exception,e: except Exception,e:
not_submitted_ss.append(ss[0]) not_submitted_ss.append(ss[0])
frappe.msgprint(e)
continue
return self.create_submit_log(ss_list, not_submitted_ss) return self.create_submit_log(ss_list, not_submitted_ss)
@ -148,6 +161,7 @@ class ProcessPayroll(Document):
<b>Not Submitted Salary Slips: </b>\ <b>Not Submitted Salary Slips: </b>\
<br><br> %s <br><br> \ <br><br> %s <br><br> \
Reason: <br>\ Reason: <br>\
May be net pay is less than 0 <br>
May be company email id specified in employee master is not valid. <br> \ May be company email id specified in employee master is not valid. <br> \
Please mention correct email id in employee master or if you don't want to \ Please mention correct email id in employee master or if you don't want to \
send mail, uncheck 'Send Email' checkbox. <br>\ send mail, uncheck 'Send Email' checkbox. <br>\
@ -166,38 +180,105 @@ class ProcessPayroll(Document):
cond = self.get_filter_condition() cond = self.get_filter_condition()
tot = frappe.db.sql(""" tot = frappe.db.sql("""
select sum(rounded_total) from `tabSalary Slip` t1 select sum(rounded_total) from `tabSalary Slip` t1
where t1.docstatus = 1 and month = %s and fiscal_year = %s %s where t1.docstatus = 1 and start_date >= %s and end_date <= %s %s
""" % ('%s', '%s', cond), (self.month, self.fiscal_year)) """ % ('%s', '%s', cond), (self.from_date, self.to_date))
return flt(tot[0][0]) return flt(tot[0][0])
def get_salary_component_account(self, salary_component):
account = frappe.db.get_value("Salary Component Account",
{"parent": salary_component, "company": self.company}, "default_account")
def make_journal_entry(self, salary_account = None): if not account:
frappe.throw(_("Please set default account in Salary Component {0}")
.format(salary_component))
return account
def get_salary_components(self, component_type):
salary_slips = self.get_sal_slip_list(ss_status = 1, as_dict = True)
if salary_slips:
salary_components = frappe.db.sql("""select salary_component, amount, parentfield
from `tabSalary Detail` where parentfield = '%s' and parent in (%s)""" %
(component_type, ', '.join(['%s']*len(salary_slips))), tuple([d.name for d in salary_slips]), as_dict=True)
return salary_components
def get_salary_component_total(self, component_type = None):
salary_components = self.get_salary_components(component_type)
if salary_components:
component_dict = {}
for item in salary_components:
component_dict[item['salary_component']] = component_dict.get(item['salary_component'], 0) + item['amount']
account_details = self.get_account(component_dict = component_dict)
return account_details
def get_account(self, component_dict = None):
account_dict = {}
for s, a in component_dict.items():
account = self.get_salary_component_account(s)
account_dict[account] = account_dict.get(account, 0) + a
return account_dict
def make_journal_entry(self, reference_number = None, reference_date = None):
self.check_permission('write') self.check_permission('write')
earnings = self.get_salary_component_total(component_type = "earnings")
deductions = self.get_salary_component_total(component_type = "deductions")
jv_name = ""
amount = self.get_total_salary() if earnings or deductions:
default_bank_account = frappe.db.get_value("Company", self.company,
"default_bank_account")
journal_entry = frappe.new_doc('Journal Entry') journal_entry = frappe.new_doc('Journal Entry')
journal_entry.voucher_type = 'Bank Entry' journal_entry.voucher_type = 'Bank Entry'
journal_entry.user_remark = _('Payment of salary for the month {0} and year {1}').format(self.month, journal_entry.user_remark = _('Payment of salary from {0} to {1}').format(self.from_date,
self.fiscal_year) self.to_date)
journal_entry.fiscal_year = self.fiscal_year
journal_entry.company = self.company journal_entry.company = self.company
journal_entry.posting_date = nowdate() journal_entry.posting_date = nowdate()
journal_entry.set("accounts", [
{
"account": salary_account,
"debit_in_account_currency": amount
},
{
"account": default_bank_account,
"credit_in_account_currency": amount
},
])
return journal_entry.as_dict() account_amt_list = []
adjustment_amt = 0
for acc, amt in earnings.items():
adjustment_amt = adjustment_amt+amt
account_amt_list.append({
"account": acc,
"debit_in_account_currency": amt
})
for acc, amt in deductions.items():
adjustment_amt = adjustment_amt-amt
account_amt_list.append({
"account": acc,
"credit_in_account_currency": amt
})
account_amt_list.append({
"account": self.payment_account,
"credit_in_account_currency": adjustment_amt
})
journal_entry.set("accounts", account_amt_list)
journal_entry.cheque_no = reference_number
journal_entry.cheque_date = reference_date
journal_entry.save()
try:
journal_entry.submit()
jv_name = journal_entry.name
self.update_salary_slip_status(jv_name = jv_name)
except Exception, e:
frappe.msgprint(e)
return self.create_jv_log(jv_name)
def create_jv_log(self, jv_name):
log = "<p>" + _("No submitted Salary Slip found") + "</p>"
if jv_name:
log = "<b>" + _("Journal Entry Submitted") + "</b>\
%s" % '<br>''<a href="#Form/Journal Entry/{0}">{0}</a>'.format(jv_name)
return log
def update_salary_slip_status(self, jv_name = None):
ss_list = self.get_sal_slip_list(ss_status=1)
for ss in ss_list:
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.whitelist() @frappe.whitelist()
def get_month_details(year, month): def get_month_details(year, month):

View File

@ -0,0 +1,27 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import unittest
import frappe
import erpnext
from frappe.utils import flt, add_months, cint, nowdate, getdate, add_days, random_string
from frappe.utils.make_random import get_random
class TestProcessPayroll(unittest.TestCase):
def test_process_payroll(self):
month = "11"
fiscal_year = "_Test Fiscal Year 2016"
payment_account = frappe.get_all("Account")[0].name
if not frappe.db.get_value("Salary Slip", {"fiscal_year": fiscal_year, "month": month}):
process_payroll = frappe.get_doc("Process Payroll", "Process Payroll")
process_payroll.company = erpnext.get_default_company()
process_payroll.month = month
process_payroll.fiscal_year = fiscal_year
process_payroll.from_date = "2016-11-01"
process_payroll.to_date = "2016-11-30"
process_payroll.payment_account = payment_account
process_payroll.create_sal_slip()
process_payroll.submit_salary_slip()
if process_payroll.get_sal_slip_list(ss_status = 1):
r = process_payroll.make_journal_entry(reference_number=random_string(10),reference_date=nowdate())

View File

@ -65,6 +65,33 @@
"unique": 0, "unique": 0,
"width": "120px" "width": "120px"
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "type",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Type",
"length": 0,
"no_copy": 0,
"options": "Earning\nDeduction",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -91,6 +118,31 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "section_break_5",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -117,33 +169,6 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "type",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Type",
"length": 0,
"no_copy": 0,
"options": "Earning\nDeduction",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"hide_heading": 0, "hide_heading": 0,
@ -157,7 +182,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-08-29 05:33:22.495594", "modified": "2016-08-31 08:08:47.359578",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Component", "name": "Salary Component",

View File

@ -15,6 +15,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break0", "fieldname": "column_break0",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -40,6 +41,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "posting_date", "fieldname": "posting_date",
"fieldtype": "Date", "fieldtype": "Date",
"hidden": 0, "hidden": 0,
@ -47,7 +49,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "posting Date", "label": "Posting Date",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -65,6 +67,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "employee", "fieldname": "employee",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -92,6 +95,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "employee_name", "fieldname": "employee_name",
"fieldtype": "Read Only", "fieldtype": "Read Only",
"hidden": 0, "hidden": 0,
@ -119,6 +123,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "department", "fieldname": "department",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -146,6 +151,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "designation", "fieldname": "designation",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -173,6 +179,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "branch", "fieldname": "branch",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -200,6 +207,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break1", "fieldname": "column_break1",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -225,6 +233,60 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "status",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Status",
"length": 0,
"no_copy": 0,
"options": "Draft\nSubmitted\nPaid\nCancelled",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "journal_entry",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Journal Entry",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -250,6 +312,7 @@
"allow_on_submit": 1, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "letter_head", "fieldname": "letter_head",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -275,6 +338,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "section_break_10", "fieldname": "section_break_10",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -299,6 +363,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "salary_slip_based_on_timesheet", "fieldname": "salary_slip_based_on_timesheet",
"fieldtype": "Check", "fieldtype": "Check",
@ -326,6 +391,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "fiscal_year", "fieldname": "fiscal_year",
"fieldtype": "Link", "fieldtype": "Link",
@ -354,6 +420,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "month", "fieldname": "month",
"fieldtype": "Select", "fieldtype": "Select",
@ -383,6 +450,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "start_date", "fieldname": "start_date",
"fieldtype": "Date", "fieldtype": "Date",
"hidden": 0, "hidden": 0,
@ -408,6 +476,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"default": "Today", "default": "Today",
"depends_on": "", "depends_on": "",
"fieldname": "end_date", "fieldname": "end_date",
@ -435,6 +504,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break_15", "fieldname": "column_break_15",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -459,6 +529,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "salary_structure", "fieldname": "salary_structure",
"fieldtype": "Link", "fieldtype": "Link",
@ -486,6 +557,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "total_days_in_month", "fieldname": "total_days_in_month",
"fieldtype": "Float", "fieldtype": "Float",
@ -513,6 +585,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "leave_without_pay", "fieldname": "leave_without_pay",
"fieldtype": "Float", "fieldtype": "Float",
@ -540,6 +613,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "payment_days", "fieldname": "payment_days",
"fieldtype": "Float", "fieldtype": "Float",
@ -567,6 +641,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "hourly_wages", "fieldname": "hourly_wages",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -593,6 +668,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "timesheets", "fieldname": "timesheets",
"fieldtype": "Table", "fieldtype": "Table",
@ -620,6 +696,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break_20", "fieldname": "column_break_20",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -644,6 +721,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "total_working_hours", "fieldname": "total_working_hours",
"fieldtype": "Float", "fieldtype": "Float",
"hidden": 0, "hidden": 0,
@ -669,6 +747,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "hour_rate", "fieldname": "hour_rate",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -694,6 +773,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"depends_on": "", "depends_on": "",
"fieldname": "section_break_26", "fieldname": "section_break_26",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -720,6 +800,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "bank_name", "fieldname": "bank_name",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
@ -746,6 +827,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "bank_account_no", "fieldname": "bank_account_no",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
@ -772,6 +854,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break_01", "fieldname": "column_break_01",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -796,6 +879,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "amended_from", "fieldname": "amended_from",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
@ -823,6 +907,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "earning_deduction", "fieldname": "earning_deduction",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -848,6 +933,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "earning", "fieldname": "earning",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -874,6 +960,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "earnings", "fieldname": "earnings",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0, "hidden": 0,
@ -901,6 +988,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "deduction", "fieldname": "deduction",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -927,6 +1015,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "deductions", "fieldname": "deductions",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0, "hidden": 0,
@ -954,6 +1043,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "totals", "fieldname": "totals",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -979,6 +1069,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "arrear_amount", "fieldname": "arrear_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -1006,6 +1097,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "leave_encashment_amount", "fieldname": "leave_encashment_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -1033,6 +1125,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "gross_pay", "fieldname": "gross_pay",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -1060,6 +1153,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "column_break_25", "fieldname": "column_break_25",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"hidden": 0, "hidden": 0,
@ -1083,6 +1177,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "total_deduction", "fieldname": "total_deduction",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -1110,6 +1205,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"description": "Gross Pay + Arrear Amount +Encashment Amount - Total Deduction", "description": "Gross Pay + Arrear Amount +Encashment Amount - Total Deduction",
"fieldname": "net_pay", "fieldname": "net_pay",
"fieldtype": "Currency", "fieldtype": "Currency",
@ -1138,6 +1234,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 1, "bold": 1,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"fieldname": "rounded_total", "fieldname": "rounded_total",
"fieldtype": "Currency", "fieldtype": "Currency",
"hidden": 0, "hidden": 0,
@ -1163,6 +1260,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0,
"description": "Net Pay (in words) will be visible once you save the Salary Slip.", "description": "Net Pay (in words) will be visible once you save the Salary Slip.",
"fieldname": "total_in_words", "fieldname": "total_in_words",
"fieldtype": "Data", "fieldtype": "Data",
@ -1198,7 +1296,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-09-19 15:15:06.809508", "modified": "2016-09-25 04:29:14.432800",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Slip", "name": "Salary Slip",

View File

@ -20,6 +20,7 @@ class SalarySlip(TransactionBase):
self.name = make_autoname('Sal Slip/' +self.employee + '/.#####') self.name = make_autoname('Sal Slip/' +self.employee + '/.#####')
def validate(self): def validate(self):
self.status = self.get_status()
self.validate_dates() self.validate_dates()
self.check_existing() self.check_existing()
self.set_month_dates() self.set_month_dates()
@ -324,6 +325,7 @@ class SalarySlip(TransactionBase):
self.set(total_field, self.get(total_field) + flt(d.amount)) self.set(total_field, self.get(total_field) + flt(d.amount))
def calculate_net_pay(self): def calculate_net_pay(self):
if self.salary_structure:
self.calculate_component_amounts() self.calculate_component_amounts()
disable_rounded_total = cint(frappe.db.get_value("Global Defaults", None, "disable_rounded_total")) disable_rounded_total = cint(frappe.db.get_value("Global Defaults", None, "disable_rounded_total"))
@ -339,11 +341,16 @@ class SalarySlip(TransactionBase):
self.precision("net_pay") if disable_rounded_total else 0) self.precision("net_pay") if disable_rounded_total else 0)
def on_submit(self): def on_submit(self):
if self.net_pay < 0:
frappe.throw(_("Net Pay cannot be less than 0"))
else:
self.set_status()
self.update_status(self.name) self.update_status(self.name)
if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")): if(frappe.db.get_single_value("HR Settings", "email_salary_slip_to_employee")):
self.email_salary_slip() self.email_salary_slip()
def on_cancel(self): def on_cancel(self):
self.set_status()
self.update_status() self.update_status()
def email_salary_slip(self): def email_salary_slip(self):
@ -364,3 +371,29 @@ class SalarySlip(TransactionBase):
timesheet.flags.ignore_validate_update_after_submit = True timesheet.flags.ignore_validate_update_after_submit = True
timesheet.set_status() timesheet.set_status()
timesheet.save() timesheet.save()
def set_status(self, status=None):
'''Get and update status'''
if not status:
status = self.get_status()
self.db_set("status", status)
def get_status(self):
if self.docstatus == 0:
status = "Draft"
elif self.docstatus == 1:
status = "Submitted"
if self.journal_entry:
status = "Paid"
elif self.docstatus == 2:
status = "Cancelled"
return status
def unlink_ref_doc_from_salary_slip(ref_no):
linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip`
where journal_entry=%s and docstatus < 2""", (ref_no))
if linked_ss:
for ss in linked_ss:
ss_doc = frappe.get_doc("Salary Slip", ss)
frappe.db.set_value("Salary Slip", ss_doc.name, "status", "Submitted")
frappe.db.set_value("Salary Slip", ss_doc.name, "journal_entry", "")

View File

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import unittest import unittest
import frappe import frappe
import erpnext import erpnext
from frappe.utils.make_random import get_random
from frappe.utils import today, now_datetime, getdate, cstr, add_years, nowdate from frappe.utils import today, now_datetime, getdate, cstr, add_years, nowdate
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
@ -202,7 +203,8 @@ def make_salary_structure(sal_struct):
"from_date": nowdate(), "from_date": nowdate(),
"employees": get_employee_details(), "employees": get_employee_details(),
"earnings": get_earnings_component(), "earnings": get_earnings_component(),
"deductions": get_deductions_component() "deductions": get_deductions_component(),
"payment_account": get_random("Account")
}).insert() }).insert()
return sal_struct return sal_struct

View File

@ -1,5 +1,6 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
{% include "erpnext/public/js/controllers/accounts.js" %}
cur_frm.add_fetch('employee', 'company', 'company'); cur_frm.add_fetch('employee', 'company', 'company');
cur_frm.add_fetch('company', 'default_letter_head', 'letter_head'); cur_frm.add_fetch('company', 'default_letter_head', 'letter_head');

View File

@ -687,6 +687,111 @@
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "account",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Account",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "mode_of_payment",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Mode of Payment",
"length": 0,
"no_copy": 0,
"options": "Mode of Payment",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_28",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "payment_account",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Account",
"length": 0,
"no_copy": 0,
"options": "Account",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"hide_heading": 0, "hide_heading": 0,
@ -700,7 +805,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-08-23 12:49:41.258649", "modified": "2016-09-06 05:40:18.311581",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Structure", "name": "Salary Structure",

View File

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest import unittest
import erpnext import erpnext
from frappe.utils.make_random import get_random
from frappe.utils import nowdate, add_days, add_years from frappe.utils import nowdate, add_days, add_years
from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
# test_records = frappe.get_test_records('Salary Structure') # test_records = frappe.get_test_records('Salary Structure')
@ -85,11 +86,11 @@ class TestSalaryStructure(unittest.TestCase):
if not sal_slip: if not sal_slip:
sal_slip = make_salary_slip_from_salary_structure(employee=frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"})) sal_slip = make_salary_slip_from_salary_structure(employee=frappe.get_value("Employee", {"employee_name":"test_employee@salary.com"}))
self.assertEquals(sal_slip.get("salary_structure"), 'Salary Structure Sample') self.assertEquals(sal_slip.get("salary_structure"), 'Salary Structure Sample')
self.assertEquals(sal_slip.get("earnings")[0].amount, 0) self.assertEquals(sal_slip.get("earnings")[0].amount, 5000)
self.assertEquals(sal_slip.get("deductions")[0].amount, 0) self.assertEquals(sal_slip.get("deductions")[0].amount, 5000)
self.assertEquals(sal_slip.get("deductions")[1].amount, 0) self.assertEquals(sal_slip.get("deductions")[1].amount, 2500)
self.assertEquals(sal_slip.get("total_deduction"), 0) self.assertEquals(sal_slip.get("total_deduction"), 7500)
self.assertEquals(sal_slip.get("net_pay"), 0) self.assertEquals(sal_slip.get("net_pay"), 7500)
def make_salary_slip_from_salary_structure(employee): def make_salary_slip_from_salary_structure(employee):
@ -111,7 +112,8 @@ def make_salary_structure(sal_struct):
"from_date": nowdate(), "from_date": nowdate(),
"employees": get_employee_details(), "employees": get_employee_details(),
"earnings": get_earnings_component(), "earnings": get_earnings_component(),
"deductions": get_deductions_component() "deductions": get_deductions_component(),
"payment_account": frappe.get_all("Account")[0].name
}).insert() }).insert()
return sal_struct return sal_struct
@ -123,7 +125,7 @@ def get_employee_details():
"idx": 1 "idx": 1
}, },
{"employee": frappe.get_value("Employee", {"employee_name":"test_employee_2@salary.com"}, "name"), {"employee": frappe.get_value("Employee", {"employee_name":"test_employee_2@salary.com"}, "name"),
"base": 2100, "base": 15000,
"variable": 100, "variable": 100,
"idx": 2 "idx": 2
} }
@ -148,7 +150,7 @@ def get_earnings_component():
{ {
"salary_component": 'HRA', "salary_component": 'HRA',
"abbr":'H', "abbr":'H',
"amount": 3000, "amount": 10000,
"idx": 3 "idx": 3
}, },
{ {
@ -172,6 +174,7 @@ def get_deductions_component():
{ {
"salary_component": 'TDS', "salary_component": 'TDS',
"abbr":'T', "abbr":'T',
"condition": 'employment_type!="Intern"',
"formula": 'base*.5', "formula": 'base*.5',
"idx": 2 "idx": 2
}, },

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import frappe import frappe
import unittest import unittest
import datetime import datetime
from frappe.utils.make_random import get_random
from frappe.utils import now_datetime, nowdate from frappe.utils import now_datetime, nowdate
from erpnext.projects.doctype.timesheet.timesheet import OverlapError from erpnext.projects.doctype.timesheet.timesheet import OverlapError
from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
@ -78,7 +79,8 @@ def make_salary_structure(employee):
salary_structure.from_date = nowdate() salary_structure.from_date = nowdate()
salary_structure.salary_component = "Basic" salary_structure.salary_component = "Basic"
salary_structure.hour_rate = 50.0 salary_structure.hour_rate = 50.0
salary_structure.company= "_Test Company" salary_structure.company = "_Test Company"
salary_structure.payment_account = get_random("Account")
salary_structure.set('employees', []) salary_structure.set('employees', [])
salary_structure.set('earnings', []) salary_structure.set('earnings', [])

View File

@ -81,6 +81,14 @@ frappe.ui.form.on('Payment Entry', {
} }
}) })
frappe.ui.form.on('Salary Structure', {
mode_of_payment: function(frm) {
get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){
frm.set_value("payment_account", account);
})
}
})
get_payment_mode_account = function(frm, mode_of_payment, callback){ get_payment_mode_account = function(frm, mode_of_payment, callback){
return frappe.call({ return frappe.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account", method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",