Deprecated client side mapper: frappe.model.map. Fixes #1530

This commit is contained in:
Anand Doshi 2014-04-25 18:36:39 +05:30
parent e3f6b6d899
commit 1872312cc6
6 changed files with 88 additions and 84 deletions

View File

@ -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"
}
},
}
}

View File

@ -20,7 +20,7 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
refresh: function() { refresh: function() {
var me = this; var me = this;
erpnext.toggle_naming_series(); 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() { cur_frm.add_custom_button(__('Make Salary Structure'), function() {
me.make_salary_structure(this); }); me.make_salary_structure(this); });
} }
@ -58,35 +58,10 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
}, },
make_salary_structure: function(btn) { make_salary_structure: function(btn) {
var me = this; frappe.model.open_mapped_doc({
this.validate_salary_structure(btn, function(r) { method: "erpnext.hr.doctype.employee.employee.make_salary_structure",
if(r.message) { source_name: cur_frm.doc.name
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"
}); });
} }
});
},
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}); cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm});

View File

@ -10,8 +10,21 @@ from frappe import throw, _
import frappe.permissions import frappe.permissions
from frappe.defaults import get_restrictions from frappe.defaults import get_restrictions
from frappe.model.document import Document from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
class Employee(Document): 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): def autoname(self):
naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by") naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by")
if not naming_method: if not naming_method:
@ -203,3 +216,16 @@ def get_retirement_date(date_of_birth=None):
dt = getdate(date_of_birth) + datetime.timedelta(21915) dt = getdate(date_of_birth) + datetime.timedelta(21915)
ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')} ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')}
return ret 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

View File

@ -30,9 +30,9 @@ $.extend(cur_frm.cscript, {
} }
}, },
make_invoice: function() { make_invoice: function() {
frappe.model.map({ frappe.model.open_mapped_doc({
source: cur_frm.doc, method: "erpnext.projects.doctype.time_log_batch.time_log_batch.make_sales_invoice",
target: "Sales Invoice" source_name: cur_frm.doc.name
}); });
} }
}); });

View File

@ -8,6 +8,7 @@ import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
class TimeLogBatch(Document): class TimeLogBatch(Document):
@ -58,3 +59,24 @@ class TimeLogBatch(Document):
tl.sales_invoice = self.sales_invoice tl.sales_invoice = self.sales_invoice
tl.ignore_validate_update_after_submit = True tl.ignore_validate_update_after_submit = True
tl.save() 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