'Merge account move lines (and hence analytic lines) if invoice line hashcodes are equals'

def group_lines(self, iml, line):

    if self.journal_id.group_invoice_lines:
        line2 = {}
        for (x, y, l) in line:
            tmp = self.inv_line_characteristic_hashcode(l)
            if (tmp in line2):
                am = ((line2[tmp]['debit'] - line2[tmp]['credit']) + (l['debit'] - l['credit']))
                line2[tmp]['debit'] = (((am > 0) and am) or 0.0)
                line2[tmp]['credit'] = (((am < 0) and (- am)) or 0.0)
                line2[tmp]['amount_currency'] += l['amount_currency']
                line2[tmp]['analytic_line_ids'] += l['analytic_line_ids']
                qty = l.get('quantity')
                if qty:
                    line2[tmp]['quantity'] = (line2[tmp].get('quantity', 0.0) + qty)
            else:
                line2[tmp] = l
        line = []
        for (key, val) in line2.items():
            line.append((0, 0, val))
    return line
