Check my solution here
https://discuss.frappe.io/t/setting-batch-for-existing-items/16054/8?u=ahmedfme