ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Sales Invoice Must to create DN


#1

Hello Dears

We have a use case that sales invoice must be created before create a DN from sales order

so how to restrict make Delivery note function to be allowed from sales invoice only ??


#2

Hello @Mahmoud_Ghoneem,

In Delivery Note, you can validate the document whether the document is created from Sales Invoice or not.

   validate: if(cur_frm.doc.items == undefined ||  cur_frm.doc.items[0].against_sales_invoice == undefined) {

    		frappe.msgprint({
    			title: __('Not Found'),
    			message: __('Delivery Note can not generate without Sales Invoice.'),
    			indicator: 'red'
    		});
            frappe.validated = false;
        }
        else
    	{
    		return true;
    	}

Thank you
Rohan


#3
SyntaxError: Illegal return statement
at init.setup (https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:60222)
at _f.Frm.setup (https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:13114)
at _f.Frm.refresh (https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:19032)
at frappe.views.FormFactory.load (https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:11600)
at https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:11326
at https://erp.riadco.com.eg/assets/js/desk.min.js?ver=1560658090.0:1:114762
at new Promise ()
at Object.with_doc (https://erp.riadco.com.eg/assets/js/desk.min.js?ver=1560658090.0:1:114505)
at frappe.views.FormFactory.show_doc (https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:11255)
at https://erp.riadco.com.eg/assets/js/form.min.js?ver=1560658090.0:1:10603

#4

@Mahmoud_Ghoneem
Just Remove else part from the code.

validate:function (frm) {

		if (cur_frm.doc.items == undefined || cur_frm.doc.items[0].against_sales_invoice == undefined) {

			frappe.msgprint({
				title: __('Not Found'),
				message: __('Delivery Note can not generate without Sales Invoice.'),
				indicator: 'red'
			});
			frappe.validated = false;
		}
	}

#5

ok thank you man

it works

but it shows only msg user can close the message and save also submit the DN :slight_smile:


#6

Done by this way

frappe.ui.form.on("Delivery Note", "before_save", function(frm, cdt, cdn) {
  
	if (cur_frm.doc.items == undefined || cur_frm.doc.items[0].against_sales_invoice == undefined) {
		frappe.throw("Delivery Note can not generate without Sales Invoice.");
		
	}

});

Thank you @ROHAN_JAIN1