[Bug] Batch No Validation and Filter on Stock Reconciliation Item Table

Github Issue: Batch No Validation and Filter on Stock Reconciliation Item Table · Issue #25491 · frappe/erpnext · GitHub

Description of the issue

In the Stock Reconciliation Item table,

  1. Batch No field is not filtered for the Item Selected (Item Code in Child Table)
  2. Batch No is not validated on Submit, if it belongs to the item code associated with it on Item Table
    Due to the above two missing validation/filter, Qty is added to wrong Item Code and the Stock Balance becomes inconsistent

Context information (for bug reports)

This is applicable mainly for Batched Items being Reconciled through Stock Reconciliation.
Need to add filter for manual entry through Form view and need validation to avoid this mistake is data is set using Import Export

Output of bench version

ERPNext: v13.1.0 (version-13)

Frappe Framework: v13.1.2 (version-13)

Steps to reproduce the issue

  1. Create an Item; Batched Item 1, with Has Batch No = 1 and Batched Item 2 with Has Batch No = 1
  2. Create a Batch ID from Batch Doctype for Item Code = Batched Item 1, Batch ID = B1-1
  3. Create new Stock Reconciliation, Purpose = Opening/Stock Reconciliation, Item Code = Batched Item 2, Qty= 100, Batch No = B1-1 (over here this field is not filtered based on Item selected and therefore user can set any Batch No)
  4. Submit Stock Reconciliation

Observed result

  1. Stock Ledger will add Qty to Batched Item 2 (Item set on Stock Reconciliation Form)
  2. Batch B1-1 will show Qty in Item Batched Item 1
  3. This creates inconsistent Stock Data, when you go to deliver Batched Item 2 with Batch No =B1-1, a validation error will be thrown saying the Qty will become negative as the Stock data is inconsistent

Expected result

  1. Filter Batch No field on Stock Reconciliation Item to show Batch Nos belonging to the Item selected. This will prevent errors from the Form
  2. Validate Stock Reconciliation on Submit to check if the Batch No set on Item table belongs to that Item Code. This will prevent errors if data is added to child table through Import/Export and then Submitted