Server side onload functionality in multiple docs

This commit is contained in:
Nabin Hait
2014-05-19 18:15:05 +05:30
parent f87c72646c
commit 2e0620e370
20 changed files with 52 additions and 59 deletions

View File

@@ -18,9 +18,10 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
refresh: function() {
var me = this;
erpnext.toggle_naming_series();
if(!this.frm.doc.__islocal && !this.frm.doc.salary_structure_exists) {
cur_frm.add_custom_button(__('Make Salary Structure'), function() {
me.make_salary_structure(this); });
if(!this.frm.doc.__islocal && this.frm.doc.__onload &&
!this.frm.doc.__onload.salary_structure_exists) {
cur_frm.add_custom_button(__('Make Salary Structure'), function() {
me.make_salary_structure(this); });
}
},

View File

@@ -14,17 +14,9 @@ from frappe.model.mapper import get_mapped_doc
class Employee(Document):
def onload(self):
self.salary_structure_exists = frappe.db.get_value("Salary Structure",
self.get("__onload").salary_structure_exists = frappe.db.get_value("Salary Structure",
{"employee": self.name, "is_active": "Yes", "docstatus": ["!=", 2]})
def as_dict(self, no_nulls=False):
doc = super(Employee, self).as_dict(no_nulls)
if hasattr(self, "salary_structure_exists"):
doc["salary_structure_exists"] = self.salary_structure_exists
return doc
def autoname(self):
naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by")
if not naming_method:

View File

@@ -57,6 +57,7 @@ var calculate_totals = function(doc, cdt, cdn) {
cur_frm.cscript.validate = function(doc, cdt, cdn) {
calculate_totals(doc, cdt, cdn);
if(doc.employee && doc.is_active == "Yes") frappe.model.clear_doc("Employee", doc.employee);
}
cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {