Pass Custom Value in Purchase Receipt Item to Custom Field in Batch DocType

I have custom fields in the Purchase Receipt Item that I want to be entered in to the associated Batch when it is created. I tried to do this by giving the DocTypes fields in each the same name and type but the information is not transferred from PR Item to Batch.

Does this need an additional step/script?

Thanks,
Paul

Can anyone help with this one?

I have two custom fields in the Purchase Receipt Item, not the Purchase Receipt DocType.
manufacturers_lot_no, a Data field
manufacturers_expiry_date, a Date field

When the Purchase Receipt is Submitted and new Batch No assigned to theitem, how can this accompanying information be added to corresponding fields in the Batch No DocType?

Any help on this would be great :smiley:

You can use The fetch from feature
In batch doctype add a new 2 field , and in fetch from add this { field contains purchase receipt id in batch doctype } . { Field name in purchase receipt }

1 Like
  1. batch no manually created via batch no link field, ensure the referenced (to-be copied field filled before create batch no), please create the following client script

frappe.ui.form.on('Purchase Receipt', {
	refresh(frm) {
	    let batch_field = frm.get_docfield("items", "batch_no");
		batch_field.get_route_options_for_new_doc = function(row) {
			//if (frm.is_new()) return;
			return {
				"manufacturer_part": row.doc.manufacturer_part,
				"item": row.doc.item_code
			}
		}
	}
})
  1. auto batch no case, please create the following server script

for item in doc.items:
    if item.batch_no and item.manufacturer_part:
        batch_doc = frappe.get_doc('Batch', item.batch_no)
        if batch_doc.reference_doctype == doc.doctype and batch_doc.reference_name == doc.name:
            batch_doc.manufacturer_part = item.manufacturer_part
            batch_doc.save()

for both scripts, please adapt the field name accordingly.

2 Likes

Thanks @szufisher , that script works brilliantly for v14.
Unfortunately I’m using the develop branch and it doesn’t work with the new Serial and Batch Bundle approach (batch_no is no longer used). However, it does give me a good direction to work on :smiley:

yes, from v15, the serial number and batch feature has been refactored, looking forward your sharing of the solution on v15.

1 Like