只检查最后一行而不是整行

Only checks the last row instead of entire rows

这里是 python Odoo 代码,用于交叉检查两个单独的每一行 classes.But 它只显示最后一行检查而不是整行和整列!谁能帮帮我!

@api.multi
    def compare_gstr(self):
        for gstr_file in self:
            err={}
            result=[]

            gstr_upload = self.env['bi.gstr.upload'].search([('gstr_upload_id','=', gstr_file.id)])
            gstr = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id)])
            for details in gstr_upload:
                # for det in gstr:
                if details.gstin:
                    gstin = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('gst_recipient','=', details.gstin)])
                    if not gstin:
                        err['GST Number']=str(details.gstin)+' Missmatch'

                if details.b2b_inv_inum:
                    b2b_inv_inum = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_ids','=', details.b2b_inv_inum)])
                    if not b2b_inv_inum:
                        err['Invoice Number']=str(details.b2b_inv_inum)+' Missmatch'

                if details.b2b_inv_idt:
                    b2b_inv_idt = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_date','=', details.b2b_inv_idt)])
                    if not b2b_inv_idt:
                        err['Invoice Date']=str(details.b2b_inv_idt)+' Missmatch'

                if details.b2b_inv_val:
                    b2b_inv_val = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_value','=', details.b2b_inv_val)])
                    if not b2b_inv_val:
                        err['Invoice Value']=str(details.b2b_inv_val)+' Missmatch'

                result.append(err)

            raise UserError(_(str(err)))

如果您正在验证 gstr_file 的行,请将代码更改为:

@api.multi
def compare_gstr(self):
    # put the list of error here
    result=[]
    for gstr_file in self:
        # list of errors of details
        details_errors = []
        gstr_upload = self.env['bi.gstr.upload'].search([('gstr_upload_id','=', gstr_file.id)])
        gstr = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id)])
        for details in gstr_upload:
            # you are getting one single erro be cause you always use the same
            # dictionary for every record
            # every row save it's error here
            err={}
            # for det in gstr:
            if details.gstin:
                gstin = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('gst_recipient','=', details.gstin)])
                if not gstin:
                    err['GST Number']=str(details.gstin)+' Missmatch'

            if details.b2b_inv_inum:
                b2b_inv_inum = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_ids','=', details.b2b_inv_inum)])
                if not b2b_inv_inum:
                    err['Invoice Number']=str(details.b2b_inv_inum)+' Missmatch'

            if details.b2b_inv_idt:
                b2b_inv_idt = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_date','=', details.b2b_inv_idt)])
                if not b2b_inv_idt:
                    err['Invoice Date']=str(details.b2b_inv_idt)+' Missmatch'

            if details.b2b_inv_val:
                b2b_inv_val = self.env['bi.gstr'].search([('gstr2_id','=', gstr_file.id),('invoice_value','=', details.b2b_inv_val)])
                if not b2b_inv_val:
                    err['Invoice Value']=str(details.b2b_inv_val)+' Missmatch'
            # add err to local list of this record
            details_errors.append(err)
        # add list of error to the global 
        # global list contains list of dictionary the key of dictionary contains the id of the
        # record so when you raise error you know with record have erro you can change
        # id by name this is good so you can read the message.
        result.append({'gstr_file id: %s' % gstr_file.id: details_errors})

    if result: # i think you need to check this because you are raising the error no matter what
        # you put raise out of the first loop
        raise UserError(_(str(result)))

如果你正在验证 details 只需更改 raise 将其放在第一个循环中但更改列表 details_errors 并且根本不使用结果。

 if details_errors: 
        # you put raise out of the first loop
        raise UserError(_(str(details_errors)))