Merge pull request #29454 from nextchamp-saqib/fix-dn-mapping

fix(sales order): incorrect no. of items fetched while creating dn
This commit is contained in:
Saqib Ansari 2022-01-31 11:38:57 +05:30 committed by GitHub
commit 6b377703b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 17 deletions

View File

@ -457,12 +457,8 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
make_delivery_note_based_on_delivery_date() { make_delivery_note_based_on_delivery_date() {
var me = this; var me = this;
var delivery_dates = []; var delivery_dates = this.frm.doc.items.map(i => i.delivery_date);
$.each(this.frm.doc.items || [], function(i, d) { delivery_dates = [ ...new Set(delivery_dates) ];
if(!delivery_dates.includes(d.delivery_date)) {
delivery_dates.push(d.delivery_date);
}
});
var item_grid = this.frm.fields_dict["items"].grid; var item_grid = this.frm.fields_dict["items"].grid;
if(!item_grid.get_selected().length && delivery_dates.length > 1) { if(!item_grid.get_selected().length && delivery_dates.length > 1) {
@ -500,14 +496,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
if(!dates) return; if(!dates) return;
$.each(dates, function(i, d) { me.make_delivery_note(dates);
$.each(item_grid.grid_rows || [], function(j, row) {
if(row.doc.delivery_date == d) {
row.doc.__checked = 1;
}
});
})
me.make_delivery_note();
dialog.hide(); dialog.hide();
}); });
dialog.show(); dialog.show();
@ -516,10 +505,13 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
} }
} }
make_delivery_note() { make_delivery_note(delivery_dates) {
frappe.model.open_mapped_doc({ frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note", method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
frm: this.frm frm: this.frm,
args: {
delivery_dates
}
}) })
} }

View File

@ -565,6 +565,13 @@ def make_delivery_note(source_name, target_doc=None, skip_item_mapping=False):
} }
if not skip_item_mapping: if not skip_item_mapping:
def condition(doc):
# make_mapped_doc sets js `args` into `frappe.flags.args`
if frappe.flags.args and frappe.flags.args.delivery_dates:
if cstr(doc.delivery_date) not in frappe.flags.args.delivery_dates:
return False
return abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1
mapper["Sales Order Item"] = { mapper["Sales Order Item"] = {
"doctype": "Delivery Note Item", "doctype": "Delivery Note Item",
"field_map": { "field_map": {
@ -573,7 +580,7 @@ def make_delivery_note(source_name, target_doc=None, skip_item_mapping=False):
"parent": "against_sales_order", "parent": "against_sales_order",
}, },
"postprocess": update_item, "postprocess": update_item,
"condition": lambda doc: abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1 "condition": condition
} }
target_doc = get_mapped_doc("Sales Order", source_name, mapper, target_doc, set_missing_values) target_doc = get_mapped_doc("Sales Order", source_name, mapper, target_doc, set_missing_values)