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 ##############################################################################
24 from osv import osv, fields
25 import decimal_precision as dp
26 from tools.translate import _
28 class account_bank_statement(osv.osv):
29 _inherit = 'account.bank.statement'
31 def write(self, cr, uid, ids, vals, context=None):
34 # bypass obsolete statement line resequencing
35 if vals.get('line_ids', False) or context.get('ebanking_import', False):
36 res = super(osv.osv, self).write(cr, uid, ids, vals, context=context)
38 res = super(account_bank_statement, self).write(cr, uid, ids, vals, context=context)
41 def button_confirm_bank(self, cr, uid, ids, context=None):
42 super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, context=context)
43 for st in self.browse(cr, uid, ids, context=context):
44 cr.execute("UPDATE account_bank_statement_line \
45 SET state='confirm' WHERE id in %s ",
46 (tuple([x.id for x in st.line_ids]),))
49 def button_cancel(self, cr, uid, ids, context=None):
50 super(account_bank_statement, self).button_cancel(cr, uid, ids, context=context)
51 for st in self.browse(cr, uid, ids, context=context):
53 cr.execute("UPDATE account_bank_statement_line \
54 SET state='draft' WHERE id in %s ",
55 (tuple([x.id for x in st.line_ids]),))
58 account_bank_statement()
60 class account_bank_statement_line_global(osv.osv):
61 _name = 'account.bank.statement.line.global'
62 _description = 'Batch Payment Info'
65 'name': fields.char('Communication', size=128, required=True),
66 'code': fields.char('Code', size=64, required=True),
67 'parent_id': fields.many2one('account.bank.statement.line.global', 'Parent Code', ondelete='cascade'),
68 'child_ids': fields.one2many('account.bank.statement.line.global', 'parent_id', 'Child Codes'),
69 'type': fields.selection([
70 ('iso20022', 'ISO 20022'),
73 ], 'Type', required=True),
74 'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
75 'bank_statement_line_ids': fields.one2many('account.bank.statement.line', 'globalisation_id', 'Bank Statement Lines'),
79 'code': lambda s,c,u,ctx={}: s.pool.get('ir.sequence').get(c, u, 'account.bank.statement.line.global'),
83 ('code_uniq', 'unique (code)', 'The code must be unique !'),
86 def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
91 ids = self.search(cr, user, [('code', 'ilike', name)] + args, limit=limit)
93 ids = self.search(cr, user, [('name', operator, name)] + args, limit=limit)
94 if not ids and len(name.split()) >= 2:
95 #Separating code and name for searching
96 operand1, operand2 = name.split(' ', 1) #name can contain spaces
97 ids = self.search(cr, user, [('code', 'like', operand1), ('name', operator, operand2)] + args, limit=limit)
99 ids = self.search(cr, user, args, context=context, limit=limit)
100 return self.name_get(cr, user, ids, context=context)
102 account_bank_statement_line_global()
104 class account_bank_statement_line(osv.osv):
105 _inherit = 'account.bank.statement.line'
107 'date': fields.date('Entry Date', required=True, states={'confirm': [('readonly', True)]}),
108 'val_date': fields.date('Valuta Date', states={'confirm': [('readonly', True)]}),
109 'globalisation_id': fields.many2one('account.bank.statement.line.global', 'Globalisation ID',
110 states={'confirm': [('readonly', True)]},
111 help="Code to identify transactions belonging to the same globalisation level within a batch payment"),
112 'globalisation_amount': fields.related('globalisation_id', 'amount', type='float',
113 relation='account.bank.statement.line.global', string='Glob. Amount', readonly=True),
114 'state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed')],
115 'Status', required=True, readonly=True),
116 'counterparty_name': fields.char('Counterparty Name', size=35),
117 'counterparty_bic': fields.char('Counterparty BIC', size=11),
118 'counterparty_number': fields.char('Counterparty Number', size=34),
119 'counterparty_currency': fields.char('Counterparty Currency', size=3),
125 def unlink(self, cr, uid, ids, context=None):
128 if context.get('block_statement_line_delete', False):
129 raise osv.except_osv(_('Warning'), _('Delete operation not allowed ! \
130 Please go to the associated bank statement in order to delete and/or modify this bank statement line'))
131 return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
133 account_bank_statement_line()
135 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: