1
# -*- coding: utf-8 -*-
4
# Author: Laurent Mignon
5
# Copyright 2013 'ACSONE SA/NV'
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
from openerp.tools.translate import _
24
from openerp.osv.orm import Model
25
from openerp.osv import fields
26
from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner
29
class AccountStatementCompletionRule(Model):
31
"""Add a rule based on transaction ID"""
33
_inherit = "account.statement.completion.rule"
35
def _get_functions(self, cr, uid, context=None):
36
res = super(AccountStatementCompletionRule, self)._get_functions(
37
cr, uid, context=context)
38
res.append(('get_from_bank_account',
39
'From bank account number (Nomal or IBAN)'))
43
'function_to_call': fields.selection(_get_functions, 'Method'),
46
def get_from_bank_account(self, cr, uid, st_line, context=None):
48
Match the partner based on the partner account number field
49
Then, call the generic st_line method to complete other values.
50
In that case, we always fullfill the reference of the line with the SO name.
51
:param dict st_line: read of the concerned account.bank.statement.line
53
A dict of value that can be passed directly to the write method of
54
the statement line or {}
59
if st_line['partner_acc_number'] == False:
61
st_obj = self.pool.get('account.bank.statement.line')
63
res_bank = self.pool.get('res.partner.bank')
64
ids = res_bank.search(cr,
66
[('acc_number', '=', st_line['partner_acc_number'])],
69
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than '
70
'one partner.') % (st_line['name'], st_line['ref']))
72
partner = self.pool.get('res.partner.bank').browse(cr, uid, ids[0], context=context).partner_id
73
res['partner_id'] = partner.id
74
st_vals = st_obj.get_values_for_line(cr,
76
profile_id=st_line['profile_id'],
77
master_account_id=st_line['master_account_id'],
78
partner_id=res.get('partner_id', False),
79
line_type=st_line['type'],
80
amount=st_line['amount'] if st_line['amount'] else 0.0,
86
class AccountStatementLine(Model):
87
_inherit = "account.bank.statement.line"
90
# 'additionnal_bank_fields' : fields.serialized('Additionnal infos from bank', help="Used by completion and import system."),
91
'partner_acc_number': fields.sparse(
93
string='Account Number',
95
serialization_field='additionnal_bank_fields',
96
help="Account number of the partner"),
97
'partner_bank_bic': fields.sparse(
99
string='Bank Identifier Code',
101
serialization_field='additionnal_bank_fields',
102
help="Bank Identifier Code"),