[fix] remove first row on mapping, fixes #5707
This commit is contained in:
parent
62fcaa7900
commit
176b63b354
@ -47,7 +47,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
|
||||
if(doc.docstatus===0) {
|
||||
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",
|
||||
source_doctype: "Purchase Order",
|
||||
get_query_filters: {
|
||||
@ -61,7 +61,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
}, __("Get items from"));
|
||||
|
||||
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",
|
||||
source_doctype: "Purchase Receipt",
|
||||
get_query_filters: {
|
||||
|
@ -101,7 +101,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
sales_order_btn: function() {
|
||||
this.$sales_order_btn = cur_frm.add_custom_button(__('Sales Order'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
|
||||
source_doctype: "Sales Order",
|
||||
get_query_filters: {
|
||||
@ -118,7 +118,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
delivery_note_btn: function() {
|
||||
this.$delivery_note_btn = cur_frm.add_custom_button(__('Delivery Note'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice",
|
||||
source_doctype: "Delivery Note",
|
||||
get_query: function() {
|
||||
|
@ -8,43 +8,43 @@ from frappe.utils import nowdate, getdate
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
|
||||
|
||||
columns = get_columns()
|
||||
data = get_entries(filters)
|
||||
|
||||
|
||||
return columns, data
|
||||
|
||||
|
||||
def get_columns():
|
||||
return [
|
||||
_("Payment Document") + ":Link/DocType:130",
|
||||
_("Payment Entry") + ":Dynamic Link/"+_("Payment Document")+":110",
|
||||
_("Posting Date") + ":Date:100",
|
||||
_("Payment Document") + ":Link/DocType:130",
|
||||
_("Payment Entry") + ":Dynamic Link/"+_("Payment Document")+":110",
|
||||
_("Posting Date") + ":Date:100",
|
||||
_("Cheque/Reference No") + "::120",
|
||||
_("Clearance Date") + ":Date:100",
|
||||
_("Against Account") + ":Link/Account:170",
|
||||
_("Clearance Date") + ":Date:100",
|
||||
_("Against Account") + ":Link/Account:170",
|
||||
_("Amount") + ":Currency:120"
|
||||
]
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = ""
|
||||
|
||||
|
||||
if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s"
|
||||
if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s"
|
||||
|
||||
|
||||
return conditions
|
||||
|
||||
|
||||
def get_entries(filters):
|
||||
conditions = get_conditions(filters)
|
||||
journal_entries = frappe.db.sql("""select "Journal Entry", jv.name, jv.posting_date,
|
||||
journal_entries = frappe.db.sql("""select "Journal Entry", jv.name, jv.posting_date,
|
||||
jv.cheque_no, jv.clearance_date, jvd.against_account, (jvd.debit - jvd.credit)
|
||||
from `tabJournal Entry Account` jvd, `tabJournal Entry` jv
|
||||
from `tabJournal Entry Account` jvd, `tabJournal Entry` jv
|
||||
where jvd.parent = jv.name and jv.docstatus=1 and jvd.account = %(account)s {0}
|
||||
order by posting_date DESC, jv.name DESC""".format(conditions), filters, as_list=1)
|
||||
|
||||
payment_entries = frappe.db.sql("""select "Payment Entry", name, posting_date,
|
||||
|
||||
payment_entries = frappe.db.sql("""select "Payment Entry", name, posting_date,
|
||||
reference_no, clearance_date, party, if(paid_from=%(account)s, paid_amount, received_amount)
|
||||
from `tabPayment Entry`
|
||||
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()))
|
@ -87,7 +87,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
},
|
||||
|
||||
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",
|
||||
source_name: this.frm.doc.supplier,
|
||||
get_query_filters: {
|
||||
@ -150,7 +150,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
add_from_mappers: function() {
|
||||
cur_frm.add_custom_button(__('Material Request'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order",
|
||||
source_doctype: "Material Request",
|
||||
get_query_filters: {
|
||||
@ -165,7 +165,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
|
||||
|
||||
cur_frm.add_custom_button(__('Supplier Quotation'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",
|
||||
source_doctype: "Supplier Quotation",
|
||||
get_query_filters: {
|
||||
|
@ -135,7 +135,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Material Request'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.stock.doctype.material_request.material_request.make_request_for_quotation",
|
||||
source_doctype: "Material Request",
|
||||
get_query_filters: {
|
||||
|
@ -15,7 +15,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
|
||||
else if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Material Request'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.stock.doctype.material_request.material_request.make_supplier_quotation",
|
||||
source_doctype: "Material Request",
|
||||
get_query_filters: {
|
||||
|
@ -128,7 +128,7 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) {
|
||||
|
||||
cur_frm.cscript.lead = function(doc, cdt, cdn) {
|
||||
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",
|
||||
source_name: cur_frm.doc.lead,
|
||||
frm: cur_frm
|
||||
|
@ -24,7 +24,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){
|
||||
}
|
||||
|
||||
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",
|
||||
source_name: cur_frm.doc.kra_template,
|
||||
frm: cur_frm
|
||||
|
@ -20,7 +20,7 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
|
||||
if (this.frm.doc.docstatus === 0) {
|
||||
this.frm.add_custom_button(__('Sales Order'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
|
||||
source_doctype: "Sales Order",
|
||||
get_query_filters: {
|
||||
|
@ -19,7 +19,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Maintenance Schedule'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
|
||||
source_doctype: "Maintenance Schedule",
|
||||
get_query_filters: {
|
||||
@ -31,7 +31,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
||||
}, __("Get items from"));
|
||||
cur_frm.add_custom_button(__('Warranty Claim'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit",
|
||||
source_doctype: "Warranty Claim",
|
||||
get_query_filters: {
|
||||
@ -43,7 +43,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
||||
}, __("Get items from"));
|
||||
cur_frm.add_custom_button(__('Sales Order'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit",
|
||||
source_doctype: "Sales Order",
|
||||
get_query_filters: {
|
||||
|
@ -8,6 +8,6 @@ def execute():
|
||||
#In MySQL, you can't modify the same table which you use in the SELECT part.
|
||||
|
||||
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)
|
||||
""".format(doctype=doctype, field=doctype.strip().lower().replace(' ','_')), debug=1)
|
||||
""".format(doctype=doctype, field=doctype.strip().lower().replace(' ','_')))
|
||||
|
@ -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
|
||||
$(document).on('app_ready', function() {
|
||||
if(!frappe.datetime.is_timezone_same()) {
|
||||
|
@ -49,7 +49,7 @@ erpnext.selling.InstallationNote = frappe.ui.form.Controller.extend({
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('From Delivery Note'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note",
|
||||
source_doctype: "Delivery Note",
|
||||
get_query_filters: {
|
||||
|
@ -29,7 +29,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Opportunity'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation",
|
||||
source_doctype: "Opportunity",
|
||||
get_query_filters: {
|
||||
|
@ -97,7 +97,7 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Quotation'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.quotation.quotation.make_sales_order",
|
||||
source_doctype: "Quotation",
|
||||
get_query_filters: {
|
||||
|
@ -37,7 +37,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Sales Order'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
|
||||
source_doctype: "Sales Order",
|
||||
get_query_filters: {
|
||||
|
@ -87,7 +87,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
|
||||
if (this.frm.doc.docstatus===0) {
|
||||
cur_frm.add_custom_button(__('Sales Order'),
|
||||
function() {
|
||||
frappe.model.map_current_doc({
|
||||
erpnext.utils.map_current_doc({
|
||||
method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request",
|
||||
source_doctype: "Sales Order",
|
||||
get_query_filters: {
|
||||
|
@ -52,7 +52,7 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
|
||||
if(this.frm.doc.docstatus==0) {
|
||||
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_receipt",
|
||||
source_doctype: "Purchase Order",
|
||||
get_query_filters: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user