2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
import re
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra import fields, models, api, _
|
|
|
|
from flectra.exceptions import UserError
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ResPartnerBank(models.Model):
|
|
|
|
_inherit = 'res.partner.bank'
|
|
|
|
|
|
|
|
aba_routing = fields.Integer(string="ABA/Routing", help="American Bankers Association Routing Number")
|
|
|
|
|
|
|
|
def _check_aba_routing(self, aba_routing):
|
|
|
|
if aba_routing and not re.match(r'^\d{1,9}$', aba_routing):
|
|
|
|
raise UserError(_('ABA/Routing should only contains numbers (maximum 9 digits).'))
|
|
|
|
return aba_routing
|
|
|
|
|
|
|
|
# ONLY FOR v11. DO NOT FORWARDPORT!
|
|
|
|
@api.model
|
|
|
|
def create(self, vals):
|
|
|
|
if vals.get('aba_routing'):
|
|
|
|
vals['aba_routing'] = int(self._check_aba_routing(vals['aba_routing']))
|
|
|
|
return super(ResPartnerBank, self).create(vals)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def write(self, vals):
|
|
|
|
if vals.get('aba_routing'):
|
|
|
|
vals['aba_routing'] = int(self._check_aba_routing(vals['aba_routing']))
|
|
|
|
return super(ResPartnerBank, self).write(vals)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def read(self, fields=None, load='_classic_read'):
|
|
|
|
result = super(ResPartnerBank, self).read(fields, load=load)
|
|
|
|
for record in result:
|
|
|
|
if record.get('aba_routing'):
|
|
|
|
record['aba_routing'] = str(record['aba_routing'])
|
|
|
|
return result
|