Fetch from Link field into child tables Link Field

Hello ,

I want something to set a particular warehouse for all the items to be added.
Currently it sets the default warehouse for each item in Sales Invoice and Purchase Invoice , and i want to make all warehouse same for all items when i set the warehouse field in global .

To that end i created a custom link field in parent doc(sales invoice) as default warehouse and when i add any child in items table it should should set the warehouse of that item as the one set above and not the default one.

I tried add_fetch method --no luck ,
maybe coz i heard add_fetch only works onload ,

then i used the code

	method: "frappe.client.get_value",
	args: { 
		doctype: "Sales Item",
		fieldname: "default_warehouse",
		filters: { name: frm.doc.sales_invoice},
	callback: function(r) {
		if (r.message){
			frappe.model.set_value(cdt, cdn, "warehouse", r.message.warehouse);

i just put it after everything in sales invoice.js as i dont know any better but no luck -

Can any one suggest me how to achieve this?


what i guess is that you have custom field on sales invoice which you want to use in item child table everywhere instead you write ajax on any trigger you can write hook event before_save

for item in doc.items:
      item.<warehousefield> = doc.default_warehouse

yep , this logic worked … thanks