Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Brahma K 2011-08-25 16:25:28 +05:30
commit f33e6746e5
20 changed files with 2131 additions and 2109 deletions

View File

@ -56,7 +56,9 @@ def get_setup_status():
percent = 20
ret = []
if not webnotes.conn.get_value('Personalize', None, 'header_html'):
header = webnotes.conn.get_value('Control Panel', None, 'client_name') or ''
if header.startswith('<div style="padding:4px; font-size:20px;">'\
+webnotes.conn.get_value('Control Panel', None, 'company_name')):
ret.append('<a href="#!Form/Personalize/Personalize">Upload your company banner</a>')
else:
percent += 20

View File

@ -134,24 +134,28 @@ MemberList.prototype.make_search = function() {
MemberList.prototype.make_list = function() {
var me = this;
this.lst_area = $a(this.list_wrapper, 'div');
this.lst = new Listing('Profiles',1);
this.lst.colwidths = ['100%'];
this.lst.opts.cell_style = {padding:'0px'}
this.lst.get_query = function() {
var c1 = '';
if(me.search_inp.value && me.search_inp.value != 'Search') {
var c1 = repl(' AND (first_name LIKE "%(txt)s" OR last_name LIKE "%(txt)s" OR name LIKE "%(txt)s")', {txt:'%' + me.search_inp.value + '%'});
this.lst = new wn.widgets.Listing({
parent: this.lst_area,
as_dict: 1,
get_query: function() {
var c1 = '';
if(me.search_inp.value && me.search_inp.value != 'Search') {
var c1 = repl(' AND (first_name LIKE "%(txt)s" OR last_name LIKE "%(txt)s" OR name LIKE "%(txt)s")', {txt:'%' + me.search_inp.value + '%'});
}
return repl("SELECT name, \
ifnull(concat_ws(' ', first_name, last_name),'') as full_name, \
gender, file_list, enabled \
FROM tabProfile \
WHERE docstatus != 2 \
AND name not in ('Guest','Administrator') %(cond)s \
ORDER BY name asc",{cond:c1});
},
render_row: function(parent, data) {
me.member_items[data.name] = new MemberItem(parent, data, me);
}
this.query = repl("SELECT distinct ifnull(name,''), ifnull(concat_ws(' ', first_name, last_name),''), \
ifnull(messanger_status,''), ifnull(gender,''), ifnull(file_list,''), 0, enabled, last_login \
from tabProfile where docstatus != 2 AND name not in ('Guest','Administrator') %(cond)s \
ORDER BY name asc",{cond:c1});
}
this.lst.make(this.lst_area);
this.lst.show_cell= function(cell, ri, ci, d) {
me.member_items[d[ri][0]] = new MemberItem(cell, d[ri], me);
}
});
this.lst.run();
}
@ -186,14 +190,14 @@ MemberItem = function(parent, det, mlist) {
var me = this;
this.det = det;
this.wrapper = $a(parent, 'div');
this.enabled = det[6];
this.enabled = det.enabled;
this.tab = make_table(this.wrapper, 1,2,'100%', ['20%', '70%'], {padding:'4px', overflow:'hidden'});
$y(this.tab, {tableLayout:'fixed', borderCollapse:'collapse'})
this.is_online = function() {
for(var i=0;i<pscript.online_users.length;i++) {
if(det[0]==pscript.online_users[i][0]) return true;
if(det.name==pscript.online_users[i][0]) return true;
}
}
@ -210,30 +214,30 @@ MemberItem = function(parent, det, mlist) {
this.set_image = function() {
// image
this.img = $a($td(this.tab,0,0),'img','',{width:'41px'});
set_user_img(this.img, det[0], null,
(det[4] ? det[4].split(NEWLINE)[0].split(',')[1] : ('no_img_' + (det[3]=='Female' ? 'f' : 'm'))));
set_user_img(this.img, det.name, null,
(det.file_list ? det.file_list.split(NEWLINE)[0].split(',')[1] : ('no_img_' + (det.gender=='Female' ? 'f' : 'm'))));
}
// set other details like email id, name etc
this.set_details = function() {
// name
this.fullname = det[1] ? det[1] : det[0];
this.fullname = det.full_name || det.name;
var div = $a($td(this.tab, 0, 1), 'div', '', {fontWeight: 'bold',padding:'2px 0px'});
this.name_link = $a(div,'span','link_type');
this.name_link.innerHTML = crop(this.fullname, 15);
this.name_link.onclick = function() {
mlist.show_profile(me.det[0], me);
mlist.show_profile(me.det.name, me);
}
// "you" tag
if(user==det[0]) {
if(user==det.name) {
var span = $a(div,'span','',{padding:'2px' ,marginLeft:'3px'});
span.innerHTML = '(You)'
}
// email id
var div = $a($td(this.tab, 0, 1), 'div', '', {color: '#777', fontSize:'11px'});
div.innerHTML = det[0];
div.innerHTML = det.name;
// working img
var div = $a($td(this.tab, 0, 1), 'div');
@ -256,7 +260,7 @@ MemberItem = function(parent, det, mlist) {
this.set_details();
// show initial
if(user==det[0]) me.name_link.onclick();
if(user==det.name) me.name_link.onclick();
}
@ -305,6 +309,7 @@ MemberProfile = function(parent, uid, member_item) {
if(has_common(['Administrator','System Manager'],user_roles)) {
var roles_btn = $btn(this.toolbar_area, 'Set Roles', function() { me.show_roles() },{marginRight:'3px'});
var delete_btn = $btn(this.toolbar_area, 'Delete User', function() { me.delete_user(); },{marginRight:'3px'});
var ip_btn = $btn(this.toolbar_area, 'Securty Settings', function() { me.set_security(); },{marginRight:'3px'});
}
}
@ -315,6 +320,74 @@ MemberProfile = function(parent, uid, member_item) {
this.role_object.dialog.show();
}
// show securty settings
this.set_security = function() {
var d = new wn.widgets.Dialog({
title: 'Set User Security',
width: 500,
fields: [
{
label:'IP Address',
description: 'Restrict user login by IP address, partial ips (111.111.111), \
multiple addresses (separated by commas) allowed',
fieldname:'restrict_ip',
fieldtype:'Data'
},
{
label:'Login After',
description: 'User can only login after this hour (0-24)',
fieldtype: 'Int',
fieldname: 'login_after'
},
{
label:'Login Before',
description: 'User can only login before this hour (0-24)',
fieldtype: 'Int',
fieldname: 'login_before'
},
{
label:'New Password',
description: 'Update the current user password',
fieldtype: 'Data',
fieldname: 'new_password'
},
{
label:'Update',
fieldtype:'Button',
fieldname:'update'
}
]
});
d.onshow = function() {
d.set_values({
restrict_ip: me.profile.restrict_ip || '',
login_before: me.profile.login_before || '',
login_after: me.profile.login_after || '',
new_password: ''
})
}
d.fields_dict.update.input.onclick = function() {
var btn = this;
this.set_working();
var args = d.get_values();
args.user = me.profile.name;
$c_page('home', 'my_company', 'update_security', JSON.stringify(args), function(r,rt) {
if(r.exc) {
msgprint(r.exc);
btn.done_working();
return;
}
$.extend(me.profile, d.get_values());
d.hide();
});
}
d.show();
}
// delete user
// create a confirm dialog and call server method
this.delete_user = function() {
@ -534,6 +607,7 @@ MemberConversation = function(parent, uid, fullname) {
this.lst = new wn.widgets.Listing({
parent: this.lst_area,
as_dict: 1,
no_result_message: (user==uid
? 'No messages by anyone yet'
: 'No messages yet. To start a conversation post a new message'),
@ -577,18 +651,18 @@ MemberCoversationComment = function(cell, det, conv) {
this.wrapper = $a(cell, 'div', 'my-company-comment-wrapper');
this.comment = $a(this.wrapper, 'div', 'my-company-comment');
this.user = $a(this.comment, 'span', 'link_type', {fontWeight:'bold'}, pscript.get_fullname(det[1]));
this.user = $a(this.comment, 'span', 'link_type', {fontWeight:'bold'}, pscript.get_fullname(det.owner));
this.user.onclick = function() {
page_body.pages['My Company'].member_list.show_profile(me.det[1]);
page_body.pages['My Company'].member_list.show_profile(me.det.owner);
}
var st = (!det[4] ? {fontWeight: 'bold'} : null);
this.msg = $a(this.comment, 'span', 'social', st, ': ' + det[0]);
var st = (!det.docstatus ? {fontWeight: 'bold'} : null);
this.msg = $a(this.comment, 'span', 'social', st, ': ' + det.creation);
if(det[1]==user) {
if(det.full_name==user) {
$y(this.wrapper, {backgroundColor: '#D9D9F3'});
}
this.timestamp = $a(this.wrapper, 'div', 'my-company-timestamp', '', comment_when(det[3]));
this.timestamp = $a(this.wrapper, 'div', 'my-company-timestamp', '', comment_when(det.creation));
}

View File

@ -129,3 +129,19 @@ def set_read_all_messages(arg=''):
WHERE comment_doctype = 'My Company'
AND comment_docname = %s
""", webnotes.user.name)
def update_security(args=''):
import json
args = json.loads(args)
webnotes.conn.set_value('Profile', args['user'], 'restrict_ip', args.get('restrict_ip'))
webnotes.conn.set_value('Profile', args['user'], 'login_after', args.get('login_after'))
webnotes.conn.set_value('Profile', args['user'], 'login_before', args.get('login_before'))
if 'new_password' in args:
if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
import server_tools.gateway_utils
webnotes.msgprint(server_tools.gateway_utils.change_password('', args['new_password'])['message'])
else:
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s", (args['new_password'], args['user']))
webnotes.msgprint('Settings Updated')

View File

@ -17,7 +17,7 @@ def change_password(arg):
webnotes.msgprint('Old password is not correct', raise_exception=1)
from webnotes.utils import nowdate
webnotes.conn.sql("update tabProfile set password=password(%s), password_last_updated=%s where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
webnotes.conn.sql("update tabProfile set password=password(%s) where name=%s",(arg['new_password'], nowdate(), webnotes.session['user']))
webnotes.msgprint('Password Updated');
def get_user_details(arg=None):

View File

@ -1,603 +1,318 @@
# Module Def, HR
[
# These values are common in all dictionaries
{
'_last_update': None,
'creation': '2011-06-30 15:51:33',
'disabled': 'No',
'creation': '2011-07-01 17:41:43',
'docstatus': 0,
'doctype': u'Module Def',
'doctype_list': None,
'file_list': None,
'idx': None,
'is_hidden': 'No',
'last_updated_date': None,
'modified': '2011-06-30 15:51:33',
'modified': '2011-08-25 13:54:43',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all Module Def Role
{
'doctype': 'Module Def Role',
'name': '__common__',
'parent': 'HR',
'parentfield': 'roles',
'parenttype': 'Module Def'
},
# These values are common for all Module Def Item
{
'doctype': 'Module Def Item',
'name': '__common__',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
},
# These values are common for all Module Def
{
'disabled': 'No',
'doctype': u'Module Def',
'is_hidden': 'No',
'module_desc': 'Human Resource Management - Employee Database, Salaries etc.',
'module_icon': 'HR.gif',
'module_label': 'HR',
'module_name': 'HR',
'module_page': None,
'module_seq': 9,
'name': 'HR',
'owner': 'Administrator',
'parent': None,
'parentfield': None,
'parenttype': None,
'trash_reason': None,
'widget_code': None
'name': '__common__'
},
# Module Def, HR
{
'doctype': u'Module Def',
'name': 'HR'
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Your Employee Database',
'display_name': 'Employee',
'doc_name': 'Employee',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'employee_name\nemployment_type\nstatus\nbranch\ndesignation\ndepartment\ngrade\nreports_to',
'hide': None,
'icon': None,
'idx': 1,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01335',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 1
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Employees Daily Attendance Tracking Form',
'display_name': 'Attendance',
'doc_name': 'Attendance',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'employee\nemployee_name\nstatus\natt_date\nfiscal_year\ncompany',
'hide': None,
'icon': None,
'idx': 2,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01336',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 2
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Upload Attendance data',
'display_name': 'Attendance Control Panel',
'doc_name': 'Attendance Control Panel',
'doc_type': 'Single DocType',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 3,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01337',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 3
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Leave allocation for selected employees at a time',
'display_name': 'Leave Control Panel',
'doc_name': 'Leave Control Panel',
'doc_type': 'Single DocType',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 4,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01338',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 4
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Allocate leave for fiscal year',
'display_name': 'Leave Allocation',
'doc_name': 'Leave Allocation',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'employee\nleave_type\nfiscal_year\ntotal_leaves_allocated\nposting_date',
'hide': None,
'icon': None,
'idx': 5,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01339',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 5
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Apply Leave',
'display_name': 'Leave Application',
'doc_name': 'Leave Application',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'employee\nleave_type\nfiscal_year\nfrom_date\nto_date\ntotal_leave_days',
'hide': None,
'icon': None,
'idx': 6,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01340',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 6
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Submit Employees Expenses',
'display_name': 'Expense Voucher',
'doc_name': 'Expense Voucher',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'status\nemployee\nemployee_name\nposting_date\ntotal_claimed_amount\ntotal_sanctioned_amount\nexp_approver',
'hide': None,
'icon': None,
'idx': 7,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01341',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 7
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Assign Responsibilities to employee and evaluate',
'display_name': 'Appraisal',
'doc_name': 'Appraisal',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'status\nemployee\nemployee_name\nstart_date\nend_date\ntotal_score\nkra_approver',
'hide': None,
'icon': None,
'idx': 8,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01342',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 8
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Generate Salary Structure heads for an employee',
'display_name': 'Salary Structure',
'doc_name': 'Salary Structure',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'employee\nis_active\nfiscal_year\nfrom_date\nctc\ntotal_earning\ntotal_deduction\ntotal',
'hide': None,
'icon': None,
'idx': 9,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01343',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 9
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Generate Salary Slip for an employee',
'display_name': 'Salary Slip',
'doc_name': 'Salary Slip',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'month\nyear\nemployee\nemployee_name\npayment_days\narrear_amount\nencashment_amount\ngross_pay\ntotal_deduction\nnet_pay',
'hide': None,
'icon': None,
'idx': 10,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01344',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 10
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Generate Salary Slip for all employee at a time',
'display_name': 'Salary Slip Control Panel',
'doc_name': 'Salary Slip Control Panel',
'description': 'Generate Salary Slip for multiple employee at a time based on selected criteria',
'display_name': 'Salary Manager',
'doc_name': 'Salary Manager',
'doc_type': 'Single DocType',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 11,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01345',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 11
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': 'Job Applications received for various positions',
'display_name': 'Job Application',
'doc_name': 'Job Application',
'doc_type': 'Forms',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': 'applicant_name\nemail\nposition',
'hide': None,
'icon': None,
'idx': 12,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01346',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 12
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': None,
'display_name': 'Employee Information',
'doc_name': 'Employee',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 13,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01347',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 13
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': None,
'display_name': "Employee's Birthday",
'doc_name': 'Employee',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 14,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01348',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 14
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': None,
'display_name': 'New or left employees for a month',
'doc_name': 'Employee',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 15,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01349',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 15
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': None,
'display_name': 'Monthly Attendance Details',
'doc_name': 'Attendance',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 16,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01350',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 16
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:33',
'description': None,
'display_name': 'Leave Application Details',
'doc_name': 'Leave Application',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 17,
'modified': '2011-06-30 15:51:33',
'modified_by': 'Administrator',
'name': 'MDI01351',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 17
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Leave Allocation Details',
'doc_name': 'Leave Allocation',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 18,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01352',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 18
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Employee Leave Balance Report',
'doc_name': 'Employee',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 19,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01353',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 19
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Salary Structure Details',
'doc_name': 'Salary Structure',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 20,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01354',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 20
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Salary Register',
'doc_name': 'Salary Slip',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 21,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01355',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 21
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Salary Slips',
'doc_name': 'Salary Slip',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 22,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01356',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 22
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Pending Appraisals',
'doc_name': 'Appraisal',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 23,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01357',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 23
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Employee Appraisals',
'doc_name': 'Appraisal',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 24,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01358',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 24
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Pending Expense Vouchers',
'doc_name': 'Expense Voucher',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 25,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01359',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 25
},
# Module Def Item
{
'click_function': None,
'creation': '2011-06-30 15:51:34',
'description': None,
'display_name': 'Expense Vouchers',
'doc_name': 'Expense Voucher',
'doc_type': 'Reports',
'docstatus': 0,
'doctype': 'Module Def Item',
'fields': None,
'hide': None,
'icon': None,
'idx': 26,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDI01360',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'items',
'parenttype': 'Module Def'
'idx': 26
},
# Module Def Role
{
'creation': '2011-06-30 15:51:34',
'docstatus': 0,
'doctype': 'Module Def Role',
'idx': 1,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDR00340',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'roles',
'parenttype': 'Module Def',
'role': 'HR Manager'
},
# Module Def Role
{
'creation': '2011-06-30 15:51:34',
'docstatus': 0,
'doctype': 'Module Def Role',
'idx': 2,
'modified': '2011-06-30 15:51:34',
'modified_by': 'Administrator',
'name': 'MDR00341',
'owner': 'Administrator',
'parent': 'HR',
'parentfield': 'roles',
'parenttype': 'Module Def',
'role': 'HR User'
}
]

View File

@ -0,0 +1,4 @@
from webnotes import ValidationError
class SalarySlipExistsError(ValidationError): pass

View File

@ -0,0 +1,67 @@
var display_activity_log = function(msg) {
if(!pscript.ss_html)
pscript.ss_html = $a(cur_frm.fields_dict['Activity Log'].wrapper,'div','',{border:'1px solid #CCC', backgroundColor:'#CCC'});
pscript.ss_html.innerHTML = '<div style="color:#EEE; background-color:#555;"><b><i>Activity Log:</i><br></b></div>';
pscript.ss_html.innerHTML += '<div style="color:#666; padding: 5px">'+ msg + '</div>';
}
//Create salary slip
//-----------------------
cur_frm.cscript['Create Salary Slip'] = function(doc, cdt, cdn) {
var callback = function(r, rt){
if (r.message)
display_activity_log(r.message);
}
$c('runserverobj', args={'method':'create_sal_slip','docs':compress_doclist(make_doclist (cdt, cdn))},callback);
}
//Submit salary slip
//-----------------------
cur_frm.cscript['Submit Salary Slip'] = function(doc, cdt, cdn) {
var check = confirm("Do you really want to Submit all Salary Slip for month : " + doc.month+" and fiscal year : "+doc.fiscal_year);
if(check){
var callback = function(r, rt){
if (r.message)
display_activity_log(r.message);
}
$c('runserverobj', args={'method':'submit_salary_slip','docs':compress_doclist(make_doclist (cdt, cdn))},callback);
}
}
// Make Bank Voucher
//-----------------------
cur_frm.cscript['Make Bank Voucher'] = function(doc,cdt,cdn){
if(doc.month && doc.fiscal_year){
cur_frm.cscript.make_jv(doc, cdt, cdn);
}
}
// Make JV
//-----------------------
cur_frm.cscript.make_jv = function(doc, dt, dn) {
var call_back = function(r,rt){
var jv = LocalDB.create('Journal Voucher');
jv = locals['Journal Voucher'][jv];
jv.voucher_type = 'Bank Voucher';
jv.user_remark = 'Payment of salary for the month: ' + doc.month + 'and fiscal year: ' + doc.fiscal_year;
jv.fiscal_year = doc.fiscal_year;
jv.company = doc.company;
jv.posting_date = dateutil.obj_to_str(new Date());
// credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.account = r.message['default_bank_account'];
d1.credit = r.message['amount']
// debit to salary account
var d2 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d2.account = r.message['default_salary_account'];
d2.debit = r.message['amount']
loaddoc('Journal Voucher', jv.name);
}
$c_obj(make_doclist(dt,dn),'get_acc_details','',call_back);
}

View File

@ -0,0 +1,164 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self, doc, doclist):
self.doc = doc
self.doclist = doclist
def get_emp_list(self):
"""
Returns list of active employees based on selected criteria
and for which salary structure exists
"""
cond = self.get_filter_condition()
emp_list = sql("""
select t1.name
from `tabEmployee` t1, `tabSalary Structure` t2
where t1.docstatus!=2 and t2.docstatus != 2
and ifnull(t1.status, 'Left') = 'Active' and ifnull(t2.is_active, 'No') = 'Yes'
and t1.name = t2.employee
%s """% cond)
return emp_list
def get_filter_condition(self):
self.check_mandatory()
cond = ''
for f in ['company', 'branch', 'department', 'designation', 'grade', 'employment_type']:
if self.doc.fields.get(f):
cond += " and t1." + f + " = '" + self.doc.fields.get(f) + "'"
return cond
def check_mandatory(self):
for f in ['company', 'month', 'fiscal_year']:
if not self.doc.fields[f]:
msgprint("Please select %s to proceed" % f, raise_exception=1)
def create_sal_slip(self):
"""
Creates salary slip for selected employees if already not created
"""
emp_list = self.get_emp_list()
log = ""
if emp_list:
log = "<table><tr><td>Following Salary Slip has been created: </td></tr><tr><td><u>SAL SLIP ID</u></td><td><u>EMPLOYEE NAME</u></td></tr>"
else:
log = "<table><tr><td>No employee found for the above selected criteria</td></tr>"
for emp in emp_list:
if not sql("""select name from `tabSalary Slip`
where docstatus!= 2 and employee = %s and month = %s and fiscal_year = %s and company = %s
""", (emp[0], self.doc.month, self.doc.fiscal_year, self.doc.company)):
ss = Document('Salary Slip')
ss.fiscal_year = self.doc.fiscal_year
ss.employee = emp[0]
ss.month = self.doc.month
ss.email_check = self.doc.send_email
ss.company = self.doc.company
ss.save(1)
ss_obj = get_obj('Salary Slip', ss.name, with_children=1)
ss_obj.get_emp_and_leave_details()
ss_obj.calculate_net_pay()
ss_obj.validate()
ss_obj.doc.save()
for d in getlist(ss_obj.doclist, 'earning_details'):
d.save()
for d in getlist(ss_obj.doclist, 'deduction_details'):
d.save()
log += '<tr><td>' + ss.name + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
log += '</table>'
return log
def get_sal_slip_list(self):
"""
Returns list of salary slips based on selected criteria
which are not submitted
"""
cond = self.get_filter_condition()
ss_list = sql("""
select t1.name from `tabSalary Slip` t1
where t1.docstatus = 0 and month = '%s' and fiscal_year = '%s' %s
""" % (self.doc.month, self.doc.fiscal_year, cond))
return ss_list
def submit_salary_slip(self):
"""
Submit all salary slips based on selected criteria
"""
ss_list = self.get_sal_slip_list()
log = ""
if ss_list:
log = "<table><tr><td>Following Salary Slip has been submitted: </td></tr><tr><td><u>SAL SLIP ID</u></td><td><u>EMPLOYEE NAME</u></td></tr>"
else:
log = "<table><tr><td>No salary slip found to submit for the above selected criteria</td></tr>"
for ss in ss_list:
ss_obj = get_obj("Salary Slip",ss[0],with_children=1)
set(ss_obj.doc, 'docstatus', 1)
ss_obj.on_submit()
log += '<tr><td>' + ss[0] + '</td><td>' + ss_obj.doc.employee_name + '</td></tr>'
log += '</table>'
return log
def get_total_salary(self):
"""
Get total salary amount from submitted salary slip based on selected criteria
"""
cond = self.get_filter_condition()
tot = sql("""
select sum(rounded_total) from `tabSalary Slip` t1
where t1.docstatus = 1 and month = '%s' and fiscal_year = '%s' %s
""" % (self.doc.month, self.doc.fiscal_year, cond))
return flt(tot[0][0])
def get_acc_details(self):
"""
get default bank account,default salary acount from company
"""
amt = self.get_total_salary()
com = sql("select default_bank_account from `tabCompany` where name = '%s'" % self.doc.company)
if not com[0][0] or not com[0][1]:
msgprint("You can set Default Bank Account in Company master.")
ret = {
'def_bank_acc' : com and com[0][0] or '',
'def_sal_acc' : com and com[0][1] or '',
'amount' : amt
}
return ret

View File

@ -1,42 +1,37 @@
# DocType, Salary Slip Control Panel
# DocType, Salary Manager
[
# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:20',
'creation': '2011-08-11 16:40:04',
'docstatus': 0,
'modified': '2010-12-29 18:02:38',
'modified_by': 'umair@iwebnotes.com',
'modified': '2011-08-25 12:02:57',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1294312182',
'_last_update': '1314179318',
'allow_copy': 1,
'allow_email': 1,
'allow_print': 1,
'colour': 'White:FFF',
'doctype': 'DocType',
'hide_heading': 0,
'hide_toolbar': 0,
'in_create': 0,
'document_type': 'Other',
'issingle': 1,
'module': 'HR',
'name': '__common__',
'read_only': 1,
'section_style': 'Simple',
'server_code_error': ' ',
'show_in_menu': 0,
'use_template': 0,
'version': 113
'show_in_menu': 1,
'version': 29
},
# These values are common for all DocField
{
'doctype': 'DocField',
'name': '__common__',
'parent': 'Salary Slip Control Panel',
'parent': 'Salary Manager',
'parentfield': 'fields',
'parenttype': 'DocType',
'permlevel': 0
@ -47,7 +42,7 @@
'create': 1,
'doctype': 'DocPerm',
'name': '__common__',
'parent': 'Salary Slip Control Panel',
'parent': 'Salary Manager',
'parentfield': 'permissions',
'parenttype': 'DocType',
'permlevel': 0,
@ -55,10 +50,10 @@
'write': 1
},
# DocType, Salary Slip Control Panel
# DocType, Salary Manager
{
'doctype': 'DocType',
'name': 'Salary Slip Control Panel'
'name': 'Salary Manager'
},
# DocPerm
@ -84,22 +79,76 @@
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'Section Break',
'fieldtype': 'HTML',
'idx': 1,
'label': 'Salary Slip Control Panel'
'label': 'Document Description',
'options': '<div class="field_description">You can generate multiple salary slips based on the selected criteria, submit and mail those to the employee directly from here</div>'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'employee_type',
'fieldtype': 'Section Break',
'idx': 2
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 3,
'width': '50%'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'company',
'fieldtype': 'Select',
'idx': 2,
'label': 'Employment Type',
'oldfieldname': 'employee_type',
'oldfieldtype': 'Select',
'options': 'link:Employment Type'
'idx': 4,
'label': 'Company',
'options': 'link:Company',
'reqd': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'branch',
'fieldtype': 'Link',
'idx': 5,
'label': 'Branch',
'options': 'Branch'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'department',
'fieldtype': 'Link',
'idx': 6,
'label': 'Department',
'options': 'Department'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'designation',
'fieldtype': 'Link',
'idx': 7,
'label': 'Designation',
'options': 'Designation'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 8,
'width': '50%'
},
# DocField
@ -107,180 +156,132 @@
'doctype': 'DocField',
'fieldname': 'grade',
'fieldtype': 'Select',
'idx': 3,
'idx': 9,
'label': 'Grade',
'oldfieldname': 'grade',
'oldfieldtype': 'Select',
'options': 'link:Grade'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'branch',
'fieldname': 'employment_type',
'fieldtype': 'Select',
'idx': 4,
'label': 'Branch',
'oldfieldname': 'branch',
'oldfieldtype': 'Select',
'options': 'link:Branch'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'department',
'fieldtype': 'Select',
'idx': 5,
'label': 'Department',
'oldfieldname': 'department',
'oldfieldtype': 'Select',
'options': 'link:Department'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'designation',
'fieldtype': 'Select',
'idx': 6,
'label': 'Designation',
'oldfieldname': 'designation',
'oldfieldtype': 'Select',
'options': 'link:Designation'
'idx': 10,
'label': 'Employment Type',
'options': 'link:Employment Type'
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 7,
'oldfieldtype': 'Column Break'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fiscal_year',
'fieldtype': 'Select',
'idx': 8,
'in_filter': 1,
'label': 'Fiscal Year',
'oldfieldname': 'fiscal_year',
'oldfieldtype': 'Select',
'options': 'link:Fiscal Year'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'month',
'fieldtype': 'Select',
'idx': 9,
'label': 'Month',
'oldfieldname': 'month',
'oldfieldtype': 'Select',
'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'year',
'fieldtype': 'Select',
'idx': 10,
'label': 'Year',
'oldfieldname': 'year',
'oldfieldtype': 'Select',
'options': '\n2009\n2010\n2011\n2012'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'week_off',
'fieldtype': 'Currency',
'idx': 11,
'label': 'Week Off',
'oldfieldname': 'week_off',
'oldfieldtype': 'Currency'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'arrear_amount',
'fieldtype': 'Currency',
'idx': 12,
'label': 'Arrear Amount',
'oldfieldname': 'arrear_amount',
'oldfieldtype': 'Currency'
'label': 'Fiscal Year',
'options': 'link:Fiscal Year',
'reqd': 1
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldname': 'email_check',
'fieldname': 'month',
'fieldtype': 'Select',
'idx': 12,
'label': 'Month',
'options': '\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12',
'reqd': 1
},
# DocField
{
'colour': 'White:FFF',
'description': 'Check if you want to send salary slip in mail to each employee while submitting salary slip',
'doctype': 'DocField',
'fieldname': 'send_email',
'fieldtype': 'Check',
'idx': 13,
'label': 'Email',
'oldfieldname': 'email_check',
'oldfieldtype': 'Check'
'label': 'Send Email'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 14,
'oldfieldtype': 'Section Break'
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 15,
'label': 'Process Payroll',
'oldfieldtype': 'Button',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 16,
'label': 'Salary Slip HTML'
'idx': 14
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 17
'idx': 15,
'width': '50%'
},
# DocField
{
'colour': 'White:FFF',
'description': 'Creates salary slip for above mentioned criteria.',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 18,
'label': 'Submit Salary Slip',
'oldfieldtype': 'Button',
'idx': 16,
'label': 'Create Salary Slip',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 17,
'width': '25%'
},
# DocField
{
'colour': 'White:FFF',
'description': 'Submit all salary slips for the above selected criteria',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 18,
'label': 'Submit Salary Slip',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Column Break',
'idx': 19,
'width': '25%'
},
# DocField
{
'colour': 'White:FFF',
'description': 'Create Bank Voucher for the total salary paid for the above selected criteria',
'doctype': 'DocField',
'fieldtype': 'Button',
'idx': 20,
'label': 'Make Bank Voucher',
'trigger': 'Client'
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'Section Break',
'idx': 21
},
# DocField
{
'doctype': 'DocField',
'fieldtype': 'HTML',
'idx': 22,
'label': 'Activity Log'
}
]

View File

@ -0,0 +1,197 @@
import unittest
import webnotes
from webnotes.model.doc import Document
from webnotes.model.code import get_obj
sql = webnotes.conn.sql
class TestSalarySlip(unittest.TestCase):
def setUp(self):
webnotes.conn.begin()
for rec in [des1, dep1, branch1, grade1, comp1, emp1, emp2]:
rec.save(1)
ss1[0].employee = emp1.name
for s in ss1: s.save(1)
for s in ss1[1:]:
sql("update `tabEarning Detail` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
sql("update `tabDeduction Detail` set parent = '%s' where name = '%s'" % (ss1[0].name, s.name))
ss2[0].employee = emp2.name
for s in ss2: s.save(1)
for s in ss2[1:]:
sql("update `tabEarning Detail` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
sql("update `tabDeduction Detail` set parent = '%s' where name = '%s'" % (ss2[0].name, s.name))
sman.save()
self.sm = get_obj('Salary Manager')
leave.save(1)
self.sm.create_sal_slip()
def test_creation(self):
ssid = sql("""
select name, department
from `tabSalary Slip`
where month = '08' and fiscal_year='2011-2012'""")
self.assertTrue(len(ssid)==1)
self.assertTrue(ssid[0][1] == 'dep1')
def test_lwp_calc(self):
ss = sql("""
select payment_days
from `tabSalary Slip`
where month = '08' and fiscal_year='2011-2012' and employee = '%s'
""" % emp1.name)
self.assertTrue(ss[0][0]==27)
def test_net_pay(self):
ss = webnotes.conn.sql("""
select rounded_total
from `tabSalary Slip`
where month = '08'
and fiscal_year='2011-2012' and employee = '%s'""" % emp1.name)
self.assertTrue(ss[0][0]==67)
def test_submit(self):
self.sm.submit_sal_slip()
ss = webnotes.conn.sql("""
select docstatus
from `tabSalary Slip`
where month = '08'
and fiscal_year='2011-2012' and employee = '%s'""" % emp1.name)
self.assertTrue(ss[0][0]==1)
def tearDown(self):
webnotes.conn.rollback()
#--------------------------------------------
# test data
#--------------------------------------------
des1 = Document(fielddata={
'name':'des1',
'doctype':'Designation',
'designation_name':'des1'
})
dep1 = Document(fielddata={
'name':'dep1',
'doctype':'Department',
'department_name' : 'dep1'
})
branch1 = Document(fielddata={
'name':'branch1',
'doctype':'Branch',
'branch' : 'branch1'
})
comp1 = Document(fielddata={
'name':'comp1',
'doctype':'Company',
'abbr':'c1',
'company_name' : 'comp1'
})
grade1 = Document(fielddata={
'name':'grade1',
'doctype':'Grade',
'grade_name' : 'grade1'
})
emp1 = Document(fielddata={
'doctype':'Employee',
'employee_number':'emp1',
'department':'dep1',
'designation':'des1',
'branch' : 'branch1',
'company':'comp1',
'grade':'grade1',
'naming_series':'EMP/',
'status':'Active',
'docstatus':0
})
emp2 = Document(fielddata={
'doctype':'Employee',
'employee_number':'emp2',
'department':'dep1',
'designation':'des2',
'branch' : 'branch1',
'company':'comp1',
'naming_series':'EMP/',
'grade':'grade1',
'status':'Active',
})
ss1 = [
Document(fielddata={
'doctype':'Salary Structure',
'docstatus':0,
'employee':'emp1',
'is_active':'Yes',
'department': 'dep1',
'designation' : 'des1'
}),
Document(fielddata={
'parenttype':'Salary Structure',
'parentfield':'earning_details',
'doctype':'Earning Detail',
'e_type' : 'Basic',
'depend_on_lwp':1,
'modified_value':100
}),
Document(fielddata={
'parenttype':'Salary Structure',
'parentfield':'earning_details',
'doctype':'Deduction Detail',
'd_type':'TDS',
'd_modified_amt':20
})
]
ss2 = [
Document(fielddata={
'doctype':'Salary Structure',
'is_active':'Yes',
'docstatus':0,
}),
Document(fielddata={
'parenttype':'Salary Structure',
'parentfield':'deduction_details',
'doctype':'Earning Detail',
'e_type' : 'Basic',
'modified_value':100
}),
Document(fielddata={
'parenttype':'Salary Structure',
'parentfield':'deduction_details',
'doctype':'Deduction Detail',
'd_type':'TDS',
'd_modified_amt':20
})
]
sman = Document(fielddata={
'name':'Salary Manager',
'doctype':'Salary Manager',
'company': 'comp1',
'department':'dep1',
'designation':'des1',
'month': '08',
'fiscal_year':'2011-2012'
})
leave = Document(fielddata = {
'doctype':'Leave Application',
'employee':'emp1',
'from_date':'2011-08-12',
'to_date':'2011-08-15',
'total_leave_days':'4',
'leave_type':'Leave Without Pay',
'docstatus':1
})

View File

@ -3,25 +3,25 @@ cur_frm.add_fetch('employee', 'company', 'company');
// On load
// -------------------------------------------------------------------
cur_frm.cscript.onload = function(doc,dt,dn){
if((cint(doc.__islocal) == 1) && !doc.amended_from){
var today=new Date();
month = (today.getMonth()+01).toString();
if(month.length>1) doc.month = month;
else doc.month = '0'+month;
if((cint(doc.__islocal) == 1) && !doc.amended_from){
var today=new Date();
month = (today.getMonth()+01).toString();
if(month.length>1) doc.month = month;
else doc.month = '0'+month;
doc.fiscal_year = sys_defaults['fiscal_year'];
refresh_many(['month', 'fiscal_year']);
cur_frm.cscript.fiscal_year(doc, dt, dn);
}
refresh_many(['month', 'fiscal_year']);
cur_frm.cscript.fiscal_year(doc, dt, dn);
}
}
// Get leave details
//---------------------------------------------------------------------
cur_frm.cscript.fiscal_year = function(doc,dt,dn){
$c_obj(make_doclist(doc.doctype,doc.name), 'get_emp_and_leave_details','',function(r, rt) {
var doc = locals[dt][dn];
cur_frm.refresh();
calculate_all(doc, dt, dn);
});
$c_obj(make_doclist(doc.doctype,doc.name), 'get_emp_and_leave_details','',function(r, rt) {
var doc = locals[dt][dn];
cur_frm.refresh();
calculate_all(doc, dt, dn);
});
}
cur_frm.cscript.month = cur_frm.cscript.employee = cur_frm.cscript.fiscal_year;
@ -29,24 +29,24 @@ cur_frm.cscript.month = cur_frm.cscript.employee = cur_frm.cscript.fiscal_year;
// Calculate total if lwp exists
// ------------------------------------------------------------------------
cur_frm.cscript.leave_without_pay = function(doc,dt,dn){
doc.payment_days = flt(doc.total_days_in_month) - flt(doc.leave_without_pay);
refresh_field('payment_days');
calculate_all(doc, dt, dn);
doc.payment_days = flt(doc.total_days_in_month) - flt(doc.leave_without_pay);
refresh_field('payment_days');
calculate_all(doc, dt, dn);
}
// Calculate all
// ------------------------------------------------------------------------
var calculate_all = function(doc, dt, dn) {
calculate_earning_total(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
// Trigger on earning modified amount and depends on lwp
// ------------------------------------------------------------------------
cur_frm.cscript.e_modified_amount = function(doc,dt,dn){
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
cur_frm.cscript.e_depends_on_lwp = cur_frm.cscript.e_modified_amount;
@ -54,8 +54,8 @@ cur_frm.cscript.e_depends_on_lwp = cur_frm.cscript.e_modified_amount;
// Trigger on earning modified amount and depends on lwp
// ------------------------------------------------------------------------
cur_frm.cscript.d_modified_amount = function(doc,dt,dn){
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_ded_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
cur_frm.cscript.d_depends_on_lwp = cur_frm.cscript.d_modified_amount;
@ -63,50 +63,50 @@ cur_frm.cscript.d_depends_on_lwp = cur_frm.cscript.d_modified_amount;
// Calculate earning total
// ------------------------------------------------------------------------
var calculate_earning_total = function(doc, dt, dn) {
var tbl = getchildren('SS Earning Detail', doc.name, 'earning_details', doc.doctype);
var tbl = getchildren('SS Earning Detail', doc.name, 'earning_details', doc.doctype);
var total_earn = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].e_depends_on_lwp) == 1) {
tbl[i].e_modified_amount = flt(tbl[i].e_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month));
refresh_field('e_modified_amount', tbl[i].name, 'earning_details');
}
total_earn += flt(tbl[i].e_modified_amount);
}
doc.gross_pay = total_earn + flt(doc.arrear_amount) + flt(doc.leave_encashment_amount);
refresh_many(['e_modified_amount', 'gross_pay']);
var total_earn = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].e_depends_on_lwp) == 1) {
tbl[i].e_modified_amount = Math.round(tbl[i].e_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)*100)/100;
refresh_field('e_modified_amount', tbl[i].name, 'earning_details');
}
total_earn += flt(tbl[i].e_modified_amount);
}
doc.gross_pay = total_earn + flt(doc.arrear_amount) + flt(doc.leave_encashment_amount);
refresh_many(['e_modified_amount', 'gross_pay']);
}
// Calculate deduction total
// ------------------------------------------------------------------------
var calculate_ded_total = function(doc, dt, dn) {
var tbl = getchildren('SS Deduction Detail', doc.name, 'deduction_details', doc.doctype);
var tbl = getchildren('SS Deduction Detail', doc.name, 'deduction_details', doc.doctype);
var total_ded = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].d_depends_on_lwp) == 1) {
tbl[i].d_modified_amount = flt(tbl[i].d_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month));
var total_ded = 0;
for(var i = 0; i < tbl.length; i++){
if(cint(tbl[i].d_depends_on_lwp) == 1) {
tbl[i].d_modified_amount = Math.round(tbl[i].d_amount)*(flt(doc.payment_days)/cint(doc.total_days_in_month)*100)/100;
refresh_field('d_modified_amount', tbl[i].name, 'deduction_details');
}
total_ded += flt(tbl[i].d_modified_amount);
}
doc.total_deduction = total_ded;
refresh_field('total_deduction');
}
total_ded += flt(tbl[i].d_modified_amount);
}
doc.total_deduction = total_ded;
refresh_field('total_deduction');
}
// Calculate net payable amount
// ------------------------------------------------------------------------
var calculate_net_pay = function(doc, dt, dn) {
doc.net_pay = flt(doc.gross_pay) - flt(doc.total_deduction);
doc.net_pay = flt(doc.gross_pay) - flt(doc.total_deduction);
doc.rounded_total = Math.round(doc.net_pay);
refresh_many(['net_pay', 'rounded_total']);
refresh_many(['net_pay', 'rounded_total']);
}
// trigger on arrear
// ------------------------------------------------------------------------
cur_frm.cscript.arrear_amount = function(doc,dt,dn){
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
calculate_earning_total(doc, dt, dn);
calculate_net_pay(doc, dt, dn);
}
// trigger on encashed amount
@ -116,5 +116,5 @@ cur_frm.cscript.leave_encashment_amount = cur_frm.cscript.arrear_amount;
// validate
// ------------------------------------------------------------------------
cur_frm.cscript.validate = function(doc, dt, dn) {
calculate_all(doc, dt, dn);
calculate_all(doc, dt, dn);
}

View File

@ -68,7 +68,7 @@ class DocType(TransactionBase):
# Get leave details
#=======================================================
def get_leave_details(self):
m = self.get_month_details()
m = self.get_month_details()
lwp = self.calculate_lwp(m)
self.doc.total_days_in_month = m[3]
self.doc.leave_without_pay = lwp
@ -129,12 +129,45 @@ class DocType(TransactionBase):
self.check_existing()
dcc = TransactionBase().get_company_currency(self.doc.company)
self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total)
def calculate_earning_total(self):
"""
Calculates total earnings considering lwp
"""
self.doc.gross_pay = flt(self.doc.arrear_amount) + flt(self.doc.leave_encashment_amount)
for d in getlist(self.doclist, 'earning_details'):
if cint(d.e_depends_on_lwp) == 1:
d.e_modified_amount = round(flt(d.e_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2)
self.doc.gross_pay += d.e_modified_amount
def calculate_ded_total(self):
"""
Calculates total deduction considering lwp
"""
self.doc.total_deduction = 0
for d in getlist(self.doclist, 'deduction_details'):
if cint(d.d_depends_on_lwp) == 1:
d.d_modified_amount = round(flt(d.d_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2)
self.doc.total_deduction += d.d_modified_amount
def calculate_net_pay(self):
"""
Calculate net payment
"""
self.calculate_earning_total()
self.calculate_ded_total()
self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction)
self.doc.rounded_total = round(self.doc.net_pay)
# ON SUBMIT
#=======================================================
def on_submit(self):
if(self.doc.email_check == 1):
self.send_mail_funct()
# Send mail
#=======================================================
@ -148,8 +181,7 @@ class DocType(TransactionBase):
earn_table = ''
ded_table = ''
if earn_ret:
if earn_ret:
earn_table += "<table cellspacing= '5' cellpadding='5' >"
for e in earn_ret:

View File

@ -1,71 +0,0 @@
cur_frm.cscript.onload = function(doc, cdt, cdn) {
alert("Salary Slip Control Panel is currently under re-development. It will take around a week time.");
hide_field(['Process Payroll', 'Submit Salary Slip', 'Make Bank Voucher']);
}
cur_frm.cscript['Process Payroll'] = function(doc,cdt,cdn){
$c('runserverobj', args={'method':'process_payroll','docs':compress_doclist (make_doclist (doc.doctype,doc.name))},function(r,rt){
if(!pscript.ss_html)
pscript.ss_html = $a(cur_frm.fields_dict['Salary Slip HTML'].wrapper,'span','',{border:'1px solid #CCC', backgroundColor:'#DDD'});
pscript.ss_html.innerHTML = '';
pscript.ss_html.innerHTML = r.message;
});
}
cur_frm.cscript['Submit Salary Slip'] = function(doc,cdt,cdn){
if(doc.month && doc.fiscal_year && doc.year){
var check = confirm("DO you really want to Submit all Salary Slip for month : " + doc.month+" and year : "+doc.year);
if(check){
$c('runserverobj', args={'method':'submit_sal_slip','docs':compress_doclist (make_doclist (doc.doctype,doc.name))},function(r,rt){
if(!pscript.ss_html)
pscript.ss_html = $a(cur_frm.fields_dict['Salary Slip HTML'].wrapper,'span','',{border:'1px solid #CCC', backgroundColor:'#DDD'});
pscript.ss_html.innerHTML = '';
pscript.ss_html.innerHTML = r.message;
});
}
}
else
alert("Please select month, fiscal year and year");
}
// Make JV
// --------
cur_frm.cscript.make_jv = function(doc, dt, dn) {
var call_back = function(r,rt){
var jv = LocalDB.create('Journal Voucher');
jv = locals['Journal Voucher'][jv];
jv.voucher_type = 'Bank Voucher';
jv.remark = 'Salary - Bank Voucher';
jv.fiscal_year = doc.fiscal_year;
jv.company = doc.company;
// credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.account = r.message['default_bank_account'];
// debit to salary account
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
d1.account = r.message['default_salary_account'];
if(!r.message['default_salary_account'] && !r.message['default_bank_account']) alert("To debit salary amount in salary head and credit amount from bank, you need to specify default salary account and default bank account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Salary Account, Default Bank Account from Accounting tab.");
else if(!r.message['default_salary_account']) alert("To debit salary amount you need to specify default salary account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Salary Account from Accounting tab.");
else if(!r.message['default_bank_account']) alert("To credit salary amount you need to specify default bank account in Global Defaults.\nGo to Setup, click on Company. Select a company.\nSelect Default Bank Account from Accounting tab.");
loaddoc('Journal Voucher', jv.name);
}
$c_obj(make_doclist(dt,dn),'get_acct_dtl','',call_back);
}
// Make Journal Voucher
// --------------------
cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
cur_frm.cscript.make_jv(doc,dt,dn);
}

View File

@ -1,137 +0,0 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
class DocType:
def __init__(self, doc, doclist):
self.doc = doc
self.doclist = doclist
# Get Employees
# **********************************************************************
def get_employee(self):
e1 = self.emp_fr_memp() #get employee list from employee where employee is active
e2 = self.emp_fr_salstr(e1) #get employee list from salary structure whose salary structure is created and is active
e3 = self.emp_fr_salslip(e2) #get employee list from salary slip whose salary slip not yet created for this month and year
return e3
# **********************************************************************
def emp_fr_memp(self):
lst1 = [[self.doc.employee_type,"employment_type"],[self.doc.branch,"branch"],[self.doc.designation,"designation"],[self.doc.department, "department"],[self.doc.grade,"grade"]]
condition = ""
#flag = 0
for l in lst1:
if(l[0]):
#if flag == 0:
# condition += l[1] + "= '" + l[0] +"'"
#else:
condition += " and " + l[1]+ "= '" +l[0] +"'"
#flag = 1
emp_query = "select name from `tabEmployee` where status = 'Active'"
#if flag == 1:
emp_query += condition
e = sql(emp_query)
return e
# **********************************************************************
def emp_fr_salstr(self,e1):
lst = []
for r in e1:
lst.append(r[0])
e_lst = "%s"%lst
e_lst=e_lst.replace("[","(")
e_lst=e_lst.replace("]",")")
cond = ''
if e1:
cond = " and employee in %s"%e_lst
el=sql("select employee from `tabSalary Structure` where is_active = 'Yes'"+cond)
return el
# **********************************************************************
def emp_fr_salslip(self,e2):
e3 = []
for i in e2:
ret = sql("select name from `tabSalary Slip` where month = '%s' and year = '%s' and employee = '%s' and docstatus !=2 "%(self.doc.month,self.doc.year,i[0]))
if not ret:
e3.append(i[0])
return e3
# **********************************************************************
def process_payroll(self):
sal_slip_str = ''
if self.doc.month and self.doc.fiscal_year and self.doc.year:
e = self.get_employee()
if e:
self.doc.emp_lst=e
sal_slip_str += 'Sucessfully created following salary slips:'
for i in e:
ss = Document('Salary Slip')
ss.fiscal_year = self.doc.fiscal_year
ss.employee = i
ss.month = self.doc.month
ss.year= self.doc.year
ss.arrear_amount = self.doc.arrear_amount
ss.email_check = self.doc.email_check
ss.save(1)
salary_obj=get_obj("Salary Slip",ss.name,with_children=1)
salary_obj.process_payroll_all()
sal_slip_str += "<br/>"+ss.name
else:
msgprint("For Process Payroll Fiscal Year, Month, Year fields are mandatory.")
if not sal_slip_str:
sal_slip_str = "No record found."
return cstr(sal_slip_str)
# **********************************************************************
def submit_sal_slip(self):
sal_slip_str = ''
r = sql("select name from `tabSalary Slip` where month='%s' and year = '%s' and fiscal_year = '%s' and docstatus = 0"%(self.doc.month,self.doc.year,self.doc.fiscal_year))
ret = sql("update `tabSalary Slip` set docstatus = 1 where month='%s' and year = '%s' and fiscal_year = '%s' and docstatus = 0"%(self.doc.month,self.doc.year,self.doc.fiscal_year))
if r:
sal_slip_str += 'Sucessfully updated following salary slips:'
for i in r:
salary_obj=get_obj("Salary Slip",i[0],with_children=1)
salary_obj.on_submit()
sal_slip_str += "<br/>"+cstr(i[0])
if not sal_slip_str:
sal_slip_str = "No record found."
return cstr(sal_slip_str)
# **********************************************************************
#get default bank account,default salary acount from company.
def get_acct_dtl(self):
res = sql("select default_bank_account,default_salary_acount from `tabCompany` where name = '%s'"%get_defaults()['company'], as_dict=1)
return res[0]

View File

@ -5,14 +5,14 @@
{
'creation': '2010-12-14 16:50:05',
'docstatus': 0,
'modified': '2011-06-27 14:39:11',
'modified': '2011-08-11 16:56:38',
'modified_by': 'Administrator',
'owner': 'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1308808105',
'_last_update': '1311621379',
'colour': 'White:FFF',
'doctype': 'DocType',
'module': 'HR',
@ -21,7 +21,7 @@
'server_code_error': ' ',
'show_in_menu': 0,
'subject': 'For %(employee_name)s',
'version': 586
'version': 587
},
# These values are common for all DocField
@ -39,7 +39,8 @@
'name': '__common__',
'parent': 'Salary Structure',
'parentfield': 'permissions',
'parenttype': 'DocType'
'parenttype': 'DocType',
'read': 1
},
# DocType, Salary Structure
@ -54,9 +55,9 @@
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'idx': 1,
'permlevel': 0,
'read': 1,
'role': 'Employee',
'submit': 0,
'write': 0
},
@ -66,97 +67,40 @@
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'match': 'owner',
'permlevel': 0,
'read': 1,
'submit': 0,
'write': 0
},
# DocPerm
{
'doctype': 'DocPerm',
'permlevel': 0,
'role': 'Sales User'
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 1,
'read': 1,
'role': 'All',
'submit': 0,
'write': 0
},
# DocPerm
{
'create': 1,
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'idx': 3,
'permlevel': 0,
'read': 1,
'role': 'HR User',
'write': 1
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 1,
'cancel': 1,
'create': 1,
'doctype': 'DocPerm',
'idx': 4,
'permlevel': 0,
'read': 1,
'role': 'HR Manager',
'submit': 1,
'write': 1
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 5,
'permlevel': 1,
'read': 1,
'role': 'HR Manager'
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 6,
'permlevel': 1,
'read': 1,
'role': 'HR User'
},
# DocField
{
'doctype': 'DocField',

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -48,10 +48,9 @@ function startup_setup() {
if(r.message){
login_file = 'http://' + r.message;
}
else {
else if(pscript.is_erpnext_saas) {
login_file = 'http://www.erpnext.com';
}
}
// setup toolbar
pscript.startup_setup_toolbar();
}
@ -539,3 +538,5 @@ pscript.set_user_fullname = function(ele,username,get_latest){
// ====================================================================
startup_setup();
$(document).bind('form_refresh', function() { })

View File

@ -61,15 +61,15 @@ class SupportMailbox(POP3Mailbox):
d.status = 'Open'
try:
d.save(1)
# update feed
update_feed(d)
# send auto reply
self.send_auto_reply(d)
except:
d.description = 'Unable to extract message'
d.save(1)
# update feed
update_feed(d)
# send auto reply
self.send_auto_reply(d)
def send_auto_reply(self, d):
"""