[fix] remove first row on mapping, fixes #5707

This commit is contained in:
Rushabh Mehta 2016-07-14 17:43:48 +05:30
parent 62fcaa7900
commit 176b63b354
18 changed files with 99 additions and 40 deletions

View File

@ -47,7 +47,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
if(doc.docstatus===0) { if(doc.docstatus===0) {
cur_frm.add_custom_button(__('Purchase Order'), function() { cur_frm.add_custom_button(__('Purchase Order'), function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice", method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
source_doctype: "Purchase Order", source_doctype: "Purchase Order",
get_query_filters: { get_query_filters: {
@ -61,7 +61,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}, __("Get items from")); }, __("Get items from"));
cur_frm.add_custom_button(__('Purchase Receipt'), function() { cur_frm.add_custom_button(__('Purchase Receipt'), function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice", method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice",
source_doctype: "Purchase Receipt", source_doctype: "Purchase Receipt",
get_query_filters: { get_query_filters: {

View File

@ -101,7 +101,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
sales_order_btn: function() { sales_order_btn: function() {
this.$sales_order_btn = cur_frm.add_custom_button(__('Sales Order'), this.$sales_order_btn = cur_frm.add_custom_button(__('Sales Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice", method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {
@ -118,7 +118,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
delivery_note_btn: function() { delivery_note_btn: function() {
this.$delivery_note_btn = cur_frm.add_custom_button(__('Delivery Note'), this.$delivery_note_btn = cur_frm.add_custom_button(__('Delivery Note'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice", method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice",
source_doctype: "Delivery Note", source_doctype: "Delivery Note",
get_query: function() { get_query: function() {

View File

@ -45,6 +45,6 @@ def get_entries(filters):
reference_no, clearance_date, party, if(paid_from=%(account)s, paid_amount, received_amount) reference_no, clearance_date, party, if(paid_from=%(account)s, paid_amount, received_amount)
from `tabPayment Entry` from `tabPayment Entry`
where docstatus=1 and (paid_from = %(account)s or paid_to = %(account)s) {0} where docstatus=1 and (paid_from = %(account)s or paid_to = %(account)s) {0}
order by posting_date DESC, name DESC""".format(conditions), filters, as_list=1, debug=1) order by posting_date DESC, name DESC""".format(conditions), filters, as_list=1)
return sorted(journal_entries + payment_entries, key=lambda k: k[2] or getdate(nowdate())) return sorted(journal_entries + payment_entries, key=lambda k: k[2] or getdate(nowdate()))

View File

@ -87,7 +87,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
}, },
get_items_from_open_material_requests: function() { get_items_from_open_material_requests: function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order_based_on_supplier", method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order_based_on_supplier",
source_name: this.frm.doc.supplier, source_name: this.frm.doc.supplier,
get_query_filters: { get_query_filters: {
@ -150,7 +150,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
add_from_mappers: function() { add_from_mappers: function() {
cur_frm.add_custom_button(__('Material Request'), cur_frm.add_custom_button(__('Material Request'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order", method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order",
source_doctype: "Material Request", source_doctype: "Material Request",
get_query_filters: { get_query_filters: {
@ -165,7 +165,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
cur_frm.add_custom_button(__('Supplier Quotation'), cur_frm.add_custom_button(__('Supplier Quotation'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order", method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",
source_doctype: "Supplier Quotation", source_doctype: "Supplier Quotation",
get_query_filters: { get_query_filters: {

View File

@ -135,7 +135,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Material Request'), cur_frm.add_custom_button(__('Material Request'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.material_request.material_request.make_request_for_quotation", method: "erpnext.stock.doctype.material_request.material_request.make_request_for_quotation",
source_doctype: "Material Request", source_doctype: "Material Request",
get_query_filters: { get_query_filters: {

View File

@ -15,7 +15,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
else if (this.frm.doc.docstatus===0) { else if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Material Request'), cur_frm.add_custom_button(__('Material Request'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.material_request.material_request.make_supplier_quotation", method: "erpnext.stock.doctype.material_request.material_request.make_supplier_quotation",
source_doctype: "Material Request", source_doctype: "Material Request",
get_query_filters: { get_query_filters: {

View File

@ -128,7 +128,7 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) {
cur_frm.cscript.lead = function(doc, cdt, cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) {
cur_frm.toggle_display("contact_info", doc.customer || doc.lead); cur_frm.toggle_display("contact_info", doc.customer || doc.lead);
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity", method: "erpnext.crm.doctype.lead.lead.make_opportunity",
source_name: cur_frm.doc.lead, source_name: cur_frm.doc.lead,
frm: cur_frm frm: cur_frm

View File

@ -24,7 +24,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
} }
cur_frm.cscript.kra_template = function(doc, dt, dn) { cur_frm.cscript.kra_template = function(doc, dt, dn) {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template", method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template",
source_name: cur_frm.doc.kra_template, source_name: cur_frm.doc.kra_template,
frm: cur_frm frm: cur_frm

View File

@ -20,7 +20,7 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
if (this.frm.doc.docstatus === 0) { if (this.frm.doc.docstatus === 0) {
this.frm.add_custom_button(__('Sales Order'), this.frm.add_custom_button(__('Sales Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule", method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {

View File

@ -19,7 +19,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Maintenance Schedule'), cur_frm.add_custom_button(__('Maintenance Schedule'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
source_doctype: "Maintenance Schedule", source_doctype: "Maintenance Schedule",
get_query_filters: { get_query_filters: {
@ -31,7 +31,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
}, __("Get items from")); }, __("Get items from"));
cur_frm.add_custom_button(__('Warranty Claim'), cur_frm.add_custom_button(__('Warranty Claim'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit",
source_doctype: "Warranty Claim", source_doctype: "Warranty Claim",
get_query_filters: { get_query_filters: {
@ -43,7 +43,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
}, __("Get items from")); }, __("Get items from"));
cur_frm.add_custom_button(__('Sales Order'), cur_frm.add_custom_button(__('Sales Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit", method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {

View File

@ -10,4 +10,4 @@ def execute():
frappe.db.sql(""" update `tab{doctype}` set is_group = 1 frappe.db.sql(""" update `tab{doctype}` set is_group = 1
where name in (select parent_{field} from (select distinct parent_{field} from `tab{doctype}` where name in (select parent_{field} from (select distinct parent_{field} from `tab{doctype}`
where parent_{field} != '') as dummy_table) where parent_{field} != '') as dummy_table)
""".format(doctype=doctype, field=doctype.strip().lower().replace(' ','_')), debug=1) """.format(doctype=doctype, field=doctype.strip().lower().replace(' ','_')))

View File

@ -120,6 +120,65 @@ $.extend(erpnext.utils, {
} }
}); });
erpnext.utils.map_current_doc = function(opts) {
if(opts.get_query_filters) {
opts.get_query = function() {
return {filters: opts.get_query_filters};
}
}
var _map = function() {
// remove first item row if empty
if($.isArray(cur_frm.doc.items)) {
if(!cur_frm.doc.items[0].item_code) {
cur_frm.doc.items = cur_frm.doc.items.splice(1);
}
}
return frappe.call({
// Sometimes we hit the limit for URL length of a GET request
// as we send the full target_doc. Hence this is a POST request.
type: "POST",
method: opts.method,
args: {
"source_name": opts.source_name,
"target_doc": cur_frm.doc
},
callback: function(r) {
if(!r.exc) {
var doc = frappe.model.sync(r.message);
cur_frm.refresh();
}
}
});
}
if(opts.source_doctype) {
var d = new frappe.ui.Dialog({
title: __("Get From ") + __(opts.source_doctype),
fields: [
{
fieldtype: "Link",
label: __(opts.source_doctype),
fieldname: opts.source_doctype,
options: opts.source_doctype,
get_query: opts.get_query,
reqd:1
},
]
});
d.set_primary_action(__('Get Items'), function() {
var values = d.get_values();
if(!values)
return;
opts.source_name = values[opts.source_doctype];
d.hide();
_map();
})
d.show();
} else if(opts.source_name) {
_map();
}
}
// add description on posting time // add description on posting time
$(document).on('app_ready', function() { $(document).on('app_ready', function() {
if(!frappe.datetime.is_timezone_same()) { if(!frappe.datetime.is_timezone_same()) {

View File

@ -49,7 +49,7 @@ erpnext.selling.InstallationNote = frappe.ui.form.Controller.extend({
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('From Delivery Note'), cur_frm.add_custom_button(__('From Delivery Note'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note", method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note",
source_doctype: "Delivery Note", source_doctype: "Delivery Note",
get_query_filters: { get_query_filters: {

View File

@ -29,7 +29,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Opportunity'), cur_frm.add_custom_button(__('Opportunity'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation", method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation",
source_doctype: "Opportunity", source_doctype: "Opportunity",
get_query_filters: { get_query_filters: {

View File

@ -97,7 +97,7 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Quotation'), cur_frm.add_custom_button(__('Quotation'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.quotation.quotation.make_sales_order", method: "erpnext.selling.doctype.quotation.quotation.make_sales_order",
source_doctype: "Quotation", source_doctype: "Quotation",
get_query_filters: { get_query_filters: {

View File

@ -37,7 +37,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Sales Order'), cur_frm.add_custom_button(__('Sales Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note", method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {

View File

@ -87,7 +87,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
if (this.frm.doc.docstatus===0) { if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__('Sales Order'), cur_frm.add_custom_button(__('Sales Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request", method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request",
source_doctype: "Sales Order", source_doctype: "Sales Order",
get_query_filters: { get_query_filters: {

View File

@ -52,7 +52,7 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
if(this.frm.doc.docstatus==0) { if(this.frm.doc.docstatus==0) {
cur_frm.add_custom_button(__('Purchase Order'), cur_frm.add_custom_button(__('Purchase Order'),
function() { function() {
frappe.model.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt", method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
source_doctype: "Purchase Order", source_doctype: "Purchase Order",
get_query_filters: { get_query_filters: {