'Update quantities or amount in child table'

def _update_children(self, args, update_modified):

    for d in self.get_all_children():
        if (d.doctype != args[u'source_dt']):
            continue
        self._update_modified(args, update_modified)
        args[u'detail_id'] = d.get(args[u'join_field'])
        args[u'second_source_condition'] = u''
        if (args.get(u'second_source_dt') and args.get(u'second_source_field') and args.get(u'second_join_field')):
            if (not args.get(u'second_source_extra_cond')):
                args[u'second_source_extra_cond'] = u''
            args[u'second_source_condition'] = (u'    +    ifnull((select    sum(%(second_source_field)s)\n DCTB  DCTB  DCTB  DCTB  DCTB from    `tab%(second_source_dt)s`\n DCTB  DCTB  DCTB  DCTB  DCTB where    `%(second_join_field)s`="%(detail_id)s"\n DCTB  DCTB  DCTB  DCTB  DCTB and    (`tab%(second_source_dt)s`.docstatus=1)    %(second_source_extra_cond)s),    0)    ' % args)
        if args[u'detail_id']:
            if (not args.get(u'extra_cond')):
                args[u'extra_cond'] = u''
            frappe.db.sql((u'update    `tab%(target_dt)s`\n DCTB  DCTB  DCTB  DCTB  DCTB set    %(target_field)s    =    (\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB (select    ifnull(sum(%(source_field)s),    0)\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB from    `tab%(source_dt)s`    where    `%(join_field)s`="%(detail_id)s"\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB and    (docstatus=1    %(cond)s)    %(extra_cond)s)\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB %(second_source_condition)s\n DCTB  DCTB  DCTB  DCTB  DCTB )\n DCTB  DCTB  DCTB  DCTB  DCTB %(update_modified)s\n DCTB  DCTB  DCTB  DCTB  DCTB where    name=\'%(detail_id)s\'' % args))
