Custom script not working - Manuf module

Hi ,

Please help , the following script works everywhere but not in the production module , I do have a field where the qty entered in the production order should automatically get entered ,

{
function compute(doc, cdt, cdn){
    if (doc.qty){ 
doc.qty1 = doc.qty;
refresh_field("qty1");
    }}
cur_frm.cscript.custom_qty = compute;

}

not even able to access the qty field in the production module by this command ,

cur_frm.add_fetch('production_item','qty','qty');

Please help

Thanks

I tried my best to figure out but I failed . only the problem is with the qty field in the prduction order module .Any help ? Thanks

hello @Muthu,

Try this instead of above method.

cur_frm.set_value(“qty1”, doc.qty);

1 Like

Thanks a lot for reply @Nishant_Jariwala . Tried but it is not working .

@Muthu,
Is there any other function in which you have write this script? [quote=“Muthu, post:1, topic:15317”]
function compute(doc, cdt, cdn){
if (doc.qty){
doc.qty1 = doc.qty;
refresh_field(“qty1”);
}}
cur_frm.cscript.custom_qty = compute;
[/quote]

1 Like

Hi @Nishant_Jariwala . Many thanks for continued support .

I dont have any scripts other than this . My actual problem is when I call the production order number in the stock entry doc it should automatically fetch the item and qty even when the production gets completed . since I am not able to achieve this I am trying weird methods to accomplish this .

Could you please help me with some server side scripts to achieve the above thing .

Thanks

@Muthu,

// FOR .js
frappe.ui.form.on("doctype name", "field_name", function (doc, cdt, cdn) {

frappe.call({
doc: doc,
"method": "method_name",
callback: function(r) {
    if(r.message){
 cur_frm.set_value("item_name1", r.message[0]['item_name']);
cur_frm.set_value("qty", r.message[0]['qty']);
cur_frm.set_value("qty1", r.message[0]['qty']);
         }
}) 

})

// for .py

def method_name(self):
// your query
dt = []
dt.append(
				{ "item_name" : val,
				  "qty" : qty,
				  })
return res
2 Likes

Thanks a lot for the quick response , entering the above code bricks the system , and I opened the console to see the logs , I saw this VM3425:502 Uncaught SyntaxError: Unexpected token ) but could not figure out exactly where the syntax is wrong .

Also the production order field is not working if the manufacturing is completed . Could you please help me how to override this validation with the server side scripting ?

Please help

can you share your code?

2 Likes

@Nishant_Jariwala . Many thanks for the continued support and taking time to solve my problem.

// FOR .js
frappe.ui.form.on("Stock entry", "production_order", function (doc, cdt, cdn) {

frappe.call({
doc: doc,
"method": "method_name",
callback: function(r) {
if(r.message){
cur_frm.set_value("item_name", r.message[0]['item_name']);
cur_frm.set_value("qty", r.message[0]['qty']);
cur_frm.set_value("qty", r.message[0]['qty']);
}
})

})

// for .py

def method_name(self):
// your query
dt = []
dt.append(
{ "item_name" : val,
"qty" : qty,
})
return res

Thanks

after this line there will be one more curly brace to complete callback.

1 Like

The problem with your script is that your function never gets called. You probably want it to get triggered when the production order number gets entered:

frappe.ui.form.on("Stock Entry", "production_order", function (doc, cdt, cdn) {
    if (doc.qty){ 
        doc.qty1 = doc.qty;
        refresh_field("qty1");
    }}
})

I’m not quite sure I understand what you’re trying to do though. Is it that you want each of the items from the production order to fill in for the stock entry?

1 Like

@Nishant_Jariwala . @Ben_Cornwell_Mott. Many thanks for the support. From my observation one thing is clear there is already a code available fro my problem . The only thing I need to do is get the production_order field in the stock entry doc to work even if the manufacturing gets completed .

Please could you guide me how to remove the validation here ?

Thanks a lot

@Ben_Cornwell_Mott . Thanks for the reply .

What I want is ,in stock entry I have to refer the production order number when transferring the materials from one workstation to the other even when the manufacturing gets completed . Once the manufacturing is completed I am not able to use the production order , it shows a error message that BOM is required.

There is a validation in stock entry.py file which has to be removed to achieve this . Could you help me please.

Thanks

Is the error “BOM and Manufacturing Quantity are required”?

1 Like

@Ben_Cornwell_Mott . Many thanks for responding . Exactly the same .

@Ben_Cornwell_Mott . Dear please help

Thanks

So the issue is that one of these fields is not set:

frm.doc.fg_completed_qty 
frm.doc.bom_no

If you use the developer console, you can see which one isn’t getting set and potentially copy the script from stock_entry.js and bypass that. The function that gets called when you enter the production order number is linked here:

1 Like

Hi , @Ben_Cornwell_Mott .

I tried to set the values manually with the below code but it is not working , please help . Again same issue I am getting error message that , BOM and manuf qty are required

erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
		get_items: function() {
		var me = this;
		if(!this.frm.doc.fg_completed_qty || !this.frm.doc.bom_no)
			{
			// if production order / bom is mentioned, get items
			return this.frm.call({
				doc: me.frm.doc,
				method: "get_items",
				callback: function(r) {
					if(!r.exc) refresh_field("items");
				}
			});
		}
	}});

@Ben_Cornwell_Mott . I understand this code in the stock_entry.py file has to be edited , could you please help me on this ?

        def validate_production_order(self):
	if self.purpose in ("Manufacture", "Material Transfer for Manufacture"):
		# check if production order is entered

		if self.purpose=="Manufacture" and self.production_order:
			if not self.fg_completed_qty:
				frappe.throw(_("For Quantity (Manufactured Qty) is mandatory"))
			self.check_if_operations_completed()
			self.check_duplicate_entry_for_production_order()
	elif self.purpose != "Material Transfer":
		self.production_order = None

Thanks