Advance customisation of dashboard

Currently if you want add number of related childtables in the Doctype dashboard you do something like this:

example from

		'transactions': [
				'label': _('Traceability'),
				'items': ['Serial No', 'Batch']

but assume that you want to count Batches that have some Custom condition like Batches with qty > 0

How this can be done “frappe / erpnext” customization way?

because now I using a combination of a callback and JQuery

refresh: function(frm){
          method: 'newmatik.api.kitting_data.item_active_batches',
          freeze: true,
          args: {
              'item_code': frm.doc.item_code,
          callback: function(r){