1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
6 # Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
22 from openerp.osv import osv, fields
24 class account_bank_statement(osv.osv):
25 _inherit = 'account.bank.statement'
27 'coda_note': fields.text('CODA Notes'),
31 class account_bank_statement_line(osv.osv):
32 _inherit = 'account.bank.statement.line'
34 'coda_account_number': fields.char('Account Number', help="The Counter Party Account Number")
37 def create(self, cr, uid, data, context=None):
39 This function creates a Bank Account Number if, for a bank statement line,
40 the partner_id field and the coda_account_number field are set,
41 and the account number does not exist in the database
43 if 'partner_id' in data and data['partner_id'] and 'coda_account_number' in data and data['coda_account_number']:
44 acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', data['coda_account_number'])])
45 if len(acc_number_ids) == 0:
47 type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
48 type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
49 self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': data['coda_account_number'], 'partner_id': data['partner_id'], 'state': type_id.code}, context=context)
52 return super(account_bank_statement_line, self).create(cr, uid, data, context=context)
54 def write(self, cr, uid, ids, vals, context=None):
55 super(account_bank_statement_line, self).write(cr, uid, ids, vals, context)
57 Same as create function above, but for write function
59 if 'partner_id' in vals:
60 for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
61 if line.coda_account_number:
62 acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', line.coda_account_number)])
63 if len(acc_number_ids) == 0:
65 type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
66 type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
67 self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': line.coda_account_number, 'partner_id': vals['partner_id'], 'state': type_id.code}, context=context)
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: