Deprecated client side mapper: frappe.model.map. Fixes #1530
This commit is contained in:
parent
e3f6b6d899
commit
1872312cc6
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.model.map_info["Sales Invoice"] = {
|
||||
"Time Log Batch": {
|
||||
table_map: {
|
||||
"Sales Invoice Item": "Time Log Batch",
|
||||
},
|
||||
field_map: {
|
||||
"Sales Invoice Item": {
|
||||
"base_rate": "rate",
|
||||
"time_log_batch": "name",
|
||||
"qty": "total_hours",
|
||||
"stock_uom": "=Hour",
|
||||
"description": "=via Time Logs"
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
|
||||
refresh: function() {
|
||||
var me = this;
|
||||
erpnext.toggle_naming_series();
|
||||
if(!this.frm.doc.__islocal) {
|
||||
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); });
|
||||
}
|
||||
@ -58,35 +58,10 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
|
||||
},
|
||||
|
||||
make_salary_structure: function(btn) {
|
||||
var me = this;
|
||||
this.validate_salary_structure(btn, function(r) {
|
||||
if(r.message) {
|
||||
msgprint(__("Active Salary Sructure already exists for Employee {0}", [me.frm.doc.name]));
|
||||
} else if(!r.exc) {
|
||||
frappe.model.map({
|
||||
source: me.frm.doc,
|
||||
target: "Salary Structure"
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.hr.doctype.employee.employee.make_salary_structure",
|
||||
source_name: cur_frm.doc.name
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
validate_salary_structure: function(btn, callback) {
|
||||
var me = this;
|
||||
return this.frm.call({
|
||||
btn: btn,
|
||||
method: "frappe.client.get_value",
|
||||
args: {
|
||||
doctype: "Salary Structure",
|
||||
fieldname: "name",
|
||||
filters: {
|
||||
employee: me.frm.doc.name,
|
||||
is_active: "Yes",
|
||||
docstatus: ["!=", 2]
|
||||
},
|
||||
},
|
||||
callback: callback
|
||||
});
|
||||
},
|
||||
});
|
||||
cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});
|
||||
|
@ -10,8 +10,21 @@ from frappe import throw, _
|
||||
import frappe.permissions
|
||||
from frappe.defaults import get_restrictions
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
class Employee(Document):
|
||||
def onload(self):
|
||||
self.salary_structure_exists = frappe.db.get_value("Salary Structure",
|
||||
{"employee": self.name, "is_active": "Yes", "docstatus": ["!=", 2]})
|
||||
|
||||
def as_dict(self):
|
||||
doc = super(Employee, self).as_dict()
|
||||
|
||||
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:
|
||||
@ -203,3 +216,16 @@ def get_retirement_date(date_of_birth=None):
|
||||
dt = getdate(date_of_birth) + datetime.timedelta(21915)
|
||||
ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')}
|
||||
return ret
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_salary_structure(source_name, target=None):
|
||||
target = get_mapped_doc("Employee", source_name, {
|
||||
"Employee": {
|
||||
"doctype": "Salary Structure",
|
||||
"field_map": {
|
||||
"name": "employee"
|
||||
}
|
||||
}
|
||||
})
|
||||
target.make_earn_ded_table()
|
||||
return target
|
||||
|
@ -30,9 +30,9 @@ $.extend(cur_frm.cscript, {
|
||||
}
|
||||
},
|
||||
make_invoice: function() {
|
||||
frappe.model.map({
|
||||
source: cur_frm.doc,
|
||||
target: "Sales Invoice"
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.projects.doctype.time_log_batch.time_log_batch.make_sales_invoice",
|
||||
source_name: cur_frm.doc.name
|
||||
});
|
||||
}
|
||||
});
|
@ -8,6 +8,7 @@ import frappe
|
||||
from frappe import _
|
||||
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
class TimeLogBatch(Document):
|
||||
|
||||
@ -58,3 +59,24 @@ class TimeLogBatch(Document):
|
||||
tl.sales_invoice = self.sales_invoice
|
||||
tl.ignore_validate_update_after_submit = True
|
||||
tl.save()
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_sales_invoice(source_name, target=None):
|
||||
def update_item(source_doc, target_doc, source_parent):
|
||||
target_doc.stock_uom = "Hour"
|
||||
target_doc.description = "via Time Logs"
|
||||
|
||||
target = frappe.new_doc("Sales Invoice")
|
||||
target.append("entries", get_mapped_doc("Time Log Batch", source_name, {
|
||||
"Time Log Batch": {
|
||||
"doctype": "Sales Invoice Item",
|
||||
"field_map": {
|
||||
"rate": "base_rate",
|
||||
"name": "time_log_batch",
|
||||
"total_hours": "qty",
|
||||
},
|
||||
"postprocess": update_item
|
||||
}
|
||||
}))
|
||||
|
||||
return target
|
||||
|
Loading…
x
Reference in New Issue
Block a user