forked from OCA/account-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatement.py
98 lines (88 loc) · 3.81 KB
/
statement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
#
#
# Author: Laurent Mignon
# Copyright 2013 'ACSONE SA/NV'
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
from openerp.tools.translate import _
from openerp.osv.orm import Model
from openerp.osv import fields
from openerp.addons.account_statement_base_completion.statement \
import ErrorTooManyPartner
class AccountStatementCompletionRule(Model):
"""Add a rule based on transaction ID"""
_inherit = "account.statement.completion.rule"
def _get_functions(self, cr, uid, context=None):
res = super(AccountStatementCompletionRule, self)._get_functions(
cr, uid, context=context)
res.append(('get_from_bank_account',
'From bank account number (Normal or IBAN)'))
return res
def get_from_bank_account(self, cr, uid, st_line, context=None):
"""
Match the partner based on the partner account number field
Then, call the generic st_line method to complete other values.
:param dict st_line: read of the concerned account.bank.statement.line
:return:
A dict of value that can be passed directly to the write method of
the statement line or {}
{'partner_id': value,
'account_id' : value,
...}
"""
partner_acc_number = st_line['partner_acc_number']
if not partner_acc_number:
return {}
st_obj = self.pool['account.bank.statement.line']
res = {}
res_bank_obj = self.pool['res.partner.bank']
ids = res_bank_obj.search_by_acc_number(cr,
uid,
partner_acc_number,
context=context)
if len(ids) > 1:
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched '
'by more than one partner for account '
'number "%s".') %
(st_line['name'],
st_line['ref'],
partner_acc_number))
if len(ids) == 1:
partner = res_bank_obj.browse(cr,
uid,
ids[0],
context=context).partner_id
res['partner_id'] = partner.id
st_vals = st_obj.get_values_for_line(
cr, uid, profile_id=st_line['profile_id'],
master_account_id=st_line['master_account_id'],
partner_id=res.get('partner_id', False),
line_type=st_line['type'],
amount=st_line['amount'] if st_line['amount'] else 0.0,
context=context)
res.update(st_vals)
return res
class AccountStatementLine(Model):
_inherit = "account.bank.statement.line"
_columns = {
'partner_acc_number': fields.sparse(
type='char',
string='Account Number',
size=64,
serialization_field='additionnal_bank_fields',
help="Account number of the partner"),
}