Пример #1
0
    def onchange_iban(self, cursor, uid, ids, iban, acc_number, context={}):
        '''
        Trigger to auto complete other fields.
        '''
        acc_number = acc_number.strip()
        country_obj = self.pool.get('res.country')
        partner_obj = self.pool.get('res.partner')
        bic = None
        country_ids = []

        if not iban:
            # Pre fill country based on company address
            user_obj = self.pool.get('res.users')
            user = user_obj.browse(cursor, uid, uid, context)
            country = partner_obj.browse(cursor, uid,
                                         user.company_id.partner_id.id
                                        ).country
            country_ids = [country.id]

            # Complete data with online database when available
            if country.code in sepa.IBAN.countries:
                info = sepa.online.account_info(country.code, acc_number)
                if info:
                    bic = info.bic
                    iban = info.iban
                else:
                    return {}

        iban_acc = sepa.IBAN(iban)
        if iban_acc.valid:
            bank_id, country_id = get_or_create_bank(
                self.pool, cursor, uid, bic or iban_acc.BIC_searchkey
                )
            return {
                'value': {
                    'acc_number': iban_acc.localized_BBAN,
                    'iban': unicode(iban_acc),
                    'country':
                        country_id or
                        country_ids and country_ids[0] or
                        False,
                    'bank':
                        bank_id or bank_ids and bank_id[0] or False,
                }
            }
        raise osv.except_osv(_('Invalid IBAN account number!'),
                             _("The IBAN number doesn't seem to be correct")
                            )
    def onchange_iban(self, cursor, uid, ids, iban, acc_number, context={}):
        '''
        Trigger to auto complete other fields.
        '''
        acc_number = acc_number.strip()
        country_obj = self.pool.get('res.country')
        partner_obj = self.pool.get('res.partner')
        bic = None
        country_ids = []

        if not iban:
            # Pre fill country based on company address
            user_obj = self.pool.get('res.users')
            user = user_obj.browse(cursor, uid, uid, context)
            country = partner_obj.browse(cursor, uid,
                                         user.company_id.partner_id.id).country
            country_ids = [country.id]

            # Complete data with online database when available
            if country.code in sepa.IBAN.countries:
                info = sepa.online.account_info(country.code, acc_number)
                if info:
                    bic = info.bic
                    iban = info.iban
                else:
                    return {}

        iban_acc = sepa.IBAN(iban)
        if iban_acc.valid:
            bank_id, country_id = get_or_create_bank(
                self.pool, cursor, uid, bic or iban_acc.BIC_searchkey)
            return {
                'value': {
                    'acc_number': iban_acc.localized_BBAN,
                    'iban': unicode(iban_acc),
                    'country': country_id or country_ids and country_ids[0]
                    or False,
                    'bank': bank_id or bank_ids and bank_id[0] or False,
                }
            }
        raise osv.except_osv(_('Invalid IBAN account number!'),
                             _("The IBAN number doesn't seem to be correct"))