~therp-nl/banking-addons/ba61-move_ref

« back to all changes in this revision

Viewing changes to account_banking/banking_import_transaction.py

[RFR] Clarify code and fix consistency of _get_move_info

Show diffs side-by-side

added added

removed removed

Lines of Context:
1016
1016
                  'account_id': False,
1017
1017
                  }
1018
1018
        move_lines = self.pool.get('account.move.line').browse(cr, uid, move_line_ids)
1019
 
        for move_line in move_lines:
1020
 
            if move_line.partner_id:
1021
 
                if retval['partner_id']:
1022
 
                    if retval['partner_id'] != move_line.partner_id.id:
1023
 
                        retval['partner_id'] = False
1024
 
                        break
1025
 
                else:
1026
 
                    retval['partner_id'] = move_line.partner_id.id
1027
 
            else:
1028
 
                if retval['partner_id']: 
1029
 
                    retval['partner_id'] = False
1030
 
                    break
1031
 
        for move_line in move_lines:
1032
 
            if move_line.account_id:
1033
 
                if retval['account_id']:
1034
 
                    if retval['account_id'] != move_line.account_id.id:
1035
 
                        retval['account_id'] = False
1036
 
                        break
1037
 
                else:
1038
 
                    retval['account_id'] = move_line.account_id.id
1039
 
            else:
1040
 
                if retval['account_id']: 
1041
 
                    retval['account_id'] = False
1042
 
                    break
1043
 
        for move_line in move_lines:
1044
 
            if move_line.invoice:
1045
 
                if retval['match_type']:
1046
 
                    if retval['match_type'] != 'invoice':
1047
 
                        retval['match_type'] = False
1048
 
                        break
1049
 
                else:
1050
 
                    retval['match_type'] = 'invoice'
1051
 
            else:
1052
 
                if retval['match_type']: 
1053
 
                    retval['match_type'] = False
1054
 
                    break
1055
 
        if move_lines and not retval['match_type']:
 
1019
 
 
1020
        if not move_lines:
 
1021
            return retval
 
1022
 
 
1023
        if move_lines[0].partner_id and all(
 
1024
                [move_line.partner_id == move_lines[0].partner_id
 
1025
                    for move_line in move_lines]):
 
1026
            retval['partner_id'] = move_lines[0].partner_id.id
 
1027
 
 
1028
        if move_lines[0].account_id and all(
 
1029
                [move_line.account_id == move_lines[0].account_id
 
1030
                    for move_line in move_lines]):
 
1031
            retval['account_id'] = move_lines[0].account_id.id
 
1032
 
 
1033
        if move_lines[0].invoice and all(
 
1034
                [move_line.invoice == move_lines[0].invoice
 
1035
                    for move_line in move_lines]):
 
1036
            retval['match_type'] = 'invoice'
 
1037
            retval['type'] = type_map[move_lines[0].invoice.type]
 
1038
            retval['invoice_ids'] = list(
 
1039
                set([x.invoice.id for x in move_lines]))
 
1040
 
 
1041
        if not retval['match_type']:
1056
1042
            retval['match_type'] = 'move'
1057
 
        if move_lines and len(move_lines) == 1:
 
1043
 
 
1044
        if len(move_lines) == 1:
1058
1045
            retval['reference'] = move_lines[0].ref
1059
 
        if retval['match_type'] == 'invoice':
1060
 
            retval['invoice_ids'] = list(set([x.invoice.id for x in move_lines]))
1061
 
            retval['type'] = type_map[move_lines[0].invoice.type]
 
1046
 
1062
1047
        return retval
1063
1048
    
1064
1049
    def match(self, cr, uid, ids, results=None, context=None):