New feature for issue #2419

This commit is contained in:
Neil Trini Lasrado 2014-12-09 12:36:50 +05:30
parent a94478a618
commit f13c4f0145
6 changed files with 260 additions and 214 deletions

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, flt, fmt_money, formatdate, getdate from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, cint
from frappe import msgprint, _, scrub from frappe import msgprint, _, scrub
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
from erpnext.controllers.accounts_controller import AccountsController from erpnext.controllers.accounts_controller import AccountsController
@ -37,11 +37,13 @@ class JournalVoucher(AccountsController):
self.validate_against_sales_order() self.validate_against_sales_order()
self.validate_against_purchase_order() self.validate_against_purchase_order()
self.check_credit_days() self.check_credit_days()
self.validate_expense_claim()
def on_submit(self): def on_submit(self):
self.check_credit_limit() self.check_credit_limit()
self.make_gl_entries() self.make_gl_entries()
self.update_advance_paid() self.update_advance_paid()
self.update_expense_claim()
def update_advance_paid(self): def update_advance_paid(self):
advance_paid = frappe._dict() advance_paid = frappe._dict()
@ -62,6 +64,7 @@ class JournalVoucher(AccountsController):
self.make_gl_entries(1) self.make_gl_entries(1)
self.update_advance_paid() self.update_advance_paid()
self.update_expense_claim()
def validate_party(self): def validate_party(self):
for d in self.get("entries"): for d in self.get("entries"):
@ -420,6 +423,22 @@ class JournalVoucher(AccountsController):
return frappe.db.sql("""select name, credit_to as account, supplier as party, outstanding_amount return frappe.db.sql("""select name, credit_to as account, supplier as party, outstanding_amount
from `tabPurchase Invoice` where docstatus = 1 and company = %s from `tabPurchase Invoice` where docstatus = 1 and company = %s
and outstanding_amount > 0 %s""" % ('%s', cond), self.company, as_dict=True) and outstanding_amount > 0 %s""" % ('%s', cond), self.company, as_dict=True)
def update_expense_claim(self):
for d in self.entries:
if d.against_expense_claim:
amt = frappe.db.sql("""select sum(debit) as amt from `tabJournal Voucher Detail`
where against_expense_claim = %s and docstatus = 1""", d.against_expense_claim ,as_dict=1)[0].amt
frappe.db.sql("update `tabExpense Claim` set total_amount_reimbursed = %s where name = %s",(amt, d.against_expense_claim))
def validate_expense_claim(self):
for d in self.entries:
if d.against_expense_claim:
sanctioned_amount = cint(frappe.db.get_value("Expense Claim", d.against_expense_claim, "total_sanctioned_amount"))
reimbursed_amount = cint(frappe.db.get_value("Expense Claim", d.against_expense_claim, "total_amount_reimbursed"))
pending_amount = sanctioned_amount - reimbursed_amount
if d.debit > pending_amount:
frappe.throw("Amount cannot be greater than Expense Claim")
@frappe.whitelist() @frappe.whitelist()
def get_default_bank_cash_account(company, voucher_type): def get_default_bank_cash_account(company, voucher_type):

View File

@ -173,6 +173,14 @@
"options": "Purchase Order", "options": "Purchase Order",
"permlevel": 0 "permlevel": 0
}, },
{
"fieldname": "against_expense_claim",
"fieldtype": "Link",
"label": "Against Expense Claim",
"options": "Expense Claim",
"permlevel": 0,
"precision": ""
},
{ {
"fieldname": "is_advance", "fieldname": "is_advance",
"fieldtype": "Select", "fieldtype": "Select",
@ -198,7 +206,7 @@
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"modified": "2014-09-17 13:02:42.012069", "modified": "2014-12-08 19:32:47.996777",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Voucher Detail", "name": "Journal Voucher Detail",

View File

@ -89,7 +89,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
if(doc.docstatus==0 && doc.exp_approver==user && doc.approval_status=="Approved") if(doc.docstatus==0 && doc.exp_approver==user && doc.approval_status=="Approved")
cur_frm.savesubmit(); cur_frm.savesubmit();
if(doc.docstatus==1 && frappe.model.can_create("Journal Voucher")) if(doc.docstatus==1 && frappe.model.can_create("Journal Voucher") && doc.total_amount_reimbursed < doc.total_sanctioned_amount)
cur_frm.add_custom_button(__("Make Bank Voucher"), cur_frm.add_custom_button(__("Make Bank Voucher"),
cur_frm.cscript.make_bank_voucher, frappe.boot.doctype_icons["Journal Voucher"]); cur_frm.cscript.make_bank_voucher, frappe.boot.doctype_icons["Journal Voucher"]);
} }
@ -109,6 +109,9 @@ cur_frm.cscript.set_help = function(doc) {
} else { } else {
if(doc.approval_status=="Approved") { if(doc.approval_status=="Approved") {
cur_frm.set_intro(__("Expense Claim has been approved.")); cur_frm.set_intro(__("Expense Claim has been approved."));
if(doc.total_amount_reimbursed== doc.total_sanctioned_amount){
cur_frm.set_intro(__("Expense Claim has been reimbursed."));
}
} else if(doc.approval_status=="Rejected") { } else if(doc.approval_status=="Rejected") {
cur_frm.set_intro(__("Expense Claim has been rejected.")); cur_frm.set_intro(__("Expense Claim has been rejected."));
} }

View File

@ -1,257 +1,267 @@
{ {
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-01-10 16:34:14", "creation": "2013-01-10 16:34:14",
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"fields": [ "fields": [
{ {
"default": "EXP", "default": "EXP",
"fieldname": "naming_series", "fieldname": "naming_series",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Series", "label": "Series",
"no_copy": 1, "no_copy": 1,
"options": "EXP", "options": "EXP",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 1, "print_hide": 1,
"reqd": 1 "reqd": 1
}, },
{ {
"default": "Draft", "default": "Draft",
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "approval_status", "fieldname": "approval_status",
"fieldtype": "Select", "fieldtype": "Select",
"in_filter": 1, "in_filter": 1,
"in_list_view": 1, "in_list_view": 1,
"label": "Approval Status", "label": "Approval Status",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "approval_status", "oldfieldname": "approval_status",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "Draft\nApproved\nRejected", "options": "Draft\nApproved\nRejected",
"permlevel": 0, "permlevel": 0,
"search_index": 1 "search_index": 1
}, },
{ {
"description": "A user with \"Expense Approver\" role", "description": "A user with \"Expense Approver\" role",
"fieldname": "exp_approver", "fieldname": "exp_approver",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Approver", "label": "Approver",
"oldfieldname": "exp_approver", "oldfieldname": "exp_approver",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "User", "options": "User",
"permlevel": 0, "permlevel": 0,
"width": "160px" "width": "160px"
}, },
{ {
"fieldname": "column_break0", "fieldname": "column_break0",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"oldfieldtype": "Column Break", "oldfieldtype": "Column Break",
"permlevel": 0, "permlevel": 0,
"width": "50%" "width": "50%"
}, },
{ {
"fieldname": "total_claimed_amount", "fieldname": "total_claimed_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Total Claimed Amount", "label": "Total Claimed Amount",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "total_claimed_amount", "oldfieldname": "total_claimed_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"permlevel": 0, "permlevel": 0,
"read_only": 1, "read_only": 1,
"reqd": 0, "reqd": 0,
"width": "160px" "width": "160px"
}, },
{ {
"fieldname": "total_sanctioned_amount", "fieldname": "total_sanctioned_amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Total Sanctioned Amount", "label": "Total Sanctioned Amount",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "total_sanctioned_amount", "oldfieldname": "total_sanctioned_amount",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"permlevel": 0, "permlevel": 0,
"read_only": 1, "read_only": 1,
"width": "160px" "width": "160px"
}, },
{ {
"fieldname": "expense_details", "fieldname": "expense_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Expense Details", "label": "Expense Details",
"oldfieldtype": "Section Break", "oldfieldtype": "Section Break",
"permlevel": 0 "permlevel": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"fieldname": "expense_voucher_details", "fieldname": "expense_voucher_details",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Expense Claim Details", "label": "Expense Claim Details",
"oldfieldname": "expense_voucher_details", "oldfieldname": "expense_voucher_details",
"oldfieldtype": "Table", "oldfieldtype": "Table",
"options": "Expense Claim Detail", "options": "Expense Claim Detail",
"permlevel": 0 "permlevel": 0
}, },
{ {
"fieldname": "sb1", "fieldname": "sb1",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"options": "Simple", "options": "Simple",
"permlevel": 0 "permlevel": 0
}, },
{ {
"fieldname": "posting_date", "fieldname": "posting_date",
"fieldtype": "Date", "fieldtype": "Date",
"in_filter": 1, "in_filter": 1,
"label": "Posting Date", "label": "Posting Date",
"oldfieldname": "posting_date", "oldfieldname": "posting_date",
"oldfieldtype": "Date", "oldfieldtype": "Date",
"permlevel": 0, "permlevel": 0,
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "employee", "fieldname": "employee",
"fieldtype": "Link", "fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"label": "From Employee", "label": "From Employee",
"oldfieldname": "employee", "oldfieldname": "employee",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Employee", "options": "Employee",
"permlevel": 0, "permlevel": 0,
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1
}, },
{ {
"fieldname": "employee_name", "fieldname": "employee_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_filter": 1, "in_filter": 1,
"in_list_view": 1, "in_list_view": 1,
"label": "Employee Name", "label": "Employee Name",
"oldfieldname": "employee_name", "oldfieldname": "employee_name",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"permlevel": 0, "permlevel": 0,
"read_only": 1, "read_only": 1,
"search_index": 0, "search_index": 0,
"width": "150px" "width": "150px"
}, },
{ {
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"label": "Company", "label": "Company",
"oldfieldname": "company", "oldfieldname": "company",
"oldfieldtype": "Link", "oldfieldtype": "Link",
"options": "Company", "options": "Company",
"permlevel": 0, "permlevel": 0,
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "fiscal_year", "fieldname": "fiscal_year",
"fieldtype": "Link", "fieldtype": "Link",
"in_filter": 1, "in_filter": 1,
"label": "Fiscal Year", "label": "Fiscal Year",
"oldfieldname": "fiscal_year", "oldfieldname": "fiscal_year",
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "Fiscal Year", "options": "Fiscal Year",
"permlevel": 0, "permlevel": 0,
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "cb1", "fieldname": "cb1",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"permlevel": 0 "permlevel": 0
}, },
{ {
"allow_on_submit": 0, "fieldname": "total_amount_reimbursed",
"fieldname": "remark", "fieldtype": "Currency",
"fieldtype": "Small Text", "label": "Total Amount Reimbursed",
"label": "Remark", "no_copy": 1,
"no_copy": 1, "options": "Company:company:default_currency",
"oldfieldname": "remark", "permlevel": 0,
"oldfieldtype": "Small Text", "precision": "",
"read_only": 1
},
{
"allow_on_submit": 0,
"fieldname": "remark",
"fieldtype": "Small Text",
"label": "Remark",
"no_copy": 1,
"oldfieldname": "remark",
"oldfieldtype": "Small Text",
"permlevel": 0 "permlevel": 0
}, },
{ {
"fieldname": "email_id", "fieldname": "email_id",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 1, "hidden": 1,
"label": "Employees Email Id", "label": "Employees Email Id",
"oldfieldname": "email_id", "oldfieldname": "email_id",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"permlevel": 0, "permlevel": 0,
"print_hide": 1 "print_hide": 1
}, },
{ {
"fieldname": "amended_from", "fieldname": "amended_from",
"fieldtype": "Link", "fieldtype": "Link",
"ignore_user_permissions": 1, "ignore_user_permissions": 1,
"label": "Amended From", "label": "Amended From",
"no_copy": 1, "no_copy": 1,
"oldfieldname": "amended_from", "oldfieldname": "amended_from",
"oldfieldtype": "Data", "oldfieldtype": "Data",
"options": "Expense Claim", "options": "Expense Claim",
"permlevel": 0, "permlevel": 0,
"print_hide": 1, "print_hide": 1,
"read_only": 1, "read_only": 1,
"report_hide": 1, "report_hide": 1,
"width": "160px" "width": "160px"
} }
], ],
"icon": "icon-money", "icon": "icon-money",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2014-11-24 18:25:53.038826", "modified": "2014-12-09 11:52:32.196383",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Expense Claim", "name": "Expense Claim",
"owner": "harshada@webnotestech.com", "owner": "harshada@webnotestech.com",
"permissions": [ "permissions": [
{ {
"apply_user_permissions": 1, "apply_user_permissions": 1,
"create": 1, "create": 1,
"delete": 0, "delete": 0,
"email": 1, "email": 1,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Employee", "role": "Employee",
"write": 1 "write": 1
}, },
{ {
"amend": 1, "amend": 1,
"apply_user_permissions": 1, "apply_user_permissions": 1,
"cancel": 1, "cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "Expense Approver", "role": "Expense Approver",
"submit": 1, "submit": 1,
"write": 1 "write": 1
}, },
{ {
"amend": 1, "amend": 1,
"apply_user_permissions": 1, "apply_user_permissions": 1,
"cancel": 1, "cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "HR User", "role": "HR User",
"submit": 1, "submit": 1,
"write": 1 "write": 1
} }
], ],
"search_fields": "approval_status,employee,employee_name", "search_fields": "approval_status,employee,employee_name",
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC" "sort_order": "DESC"
} }

View File

@ -13,7 +13,12 @@
data-filter="status,=,{%= doc.approval_status %}"> data-filter="status,=,{%= doc.approval_status %}">
{%= doc.approval_status %} {%= doc.approval_status %}
</span> </span>
{% if(doc.total_amount_reimbursed== doc.total_sanctioned_amount && doc.docstatus== 1) { %}
<span class="label label-success">
"Reimbursed"
</span>
{% } %}
</div> </div>
</div> </div>
<!-- sample graph --> <!-- sample graph -->

View File

@ -1,4 +1,5 @@
frappe.listview_settings['Expense Claim'] = { frappe.listview_settings['Expense Claim'] = {
add_fields: ["approval_status", "employee", "employee_name", "total_claimed_amount"], add_fields: ["approval_status", "employee", "employee_name",
"total_claimed_amount", "total_amount_reimbursed", "total_sanctioned_amount", "docstatus"],
filters:[["approval_status","!=", "Rejected"]] filters:[["approval_status","!=", "Rejected"]]
}; };