mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-15 01:43:10 +00:00
Server side onload functionality in multiple docs
This commit is contained in:
@@ -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); });
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user