forked from OCA/account-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_reconciliation.py
113 lines (95 loc) · 4.03 KB
/
simple_reconciliation.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2012-2013, 2015 Camptocamp SA (Guewen Baconnier, Damien Crier)
# Copyright (C) 2010 Sébastien Beau
#
# 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.osv.orm import AbstractModel, TransientModel
from openerp import models, api
class EasyReconcileSimple(models.AbstractModel):
_name = 'easy.reconcile.simple'
_inherit = 'easy.reconcile.base'
# has to be subclassed
# field name used as key for matching the move lines
_key_field = None
@api.multi
def rec_auto_lines_simple(self, lines):
if self._key_field is None:
raise ValueError("_key_field has to be defined")
count = 0
res = []
while (count < len(lines)):
for i in xrange(count + 1, len(lines)):
if lines[count][self._key_field] != lines[i][self._key_field]:
break
check = False
if lines[count]['credit'] > 0 and lines[i]['debit'] > 0:
credit_line = lines[count]
debit_line = lines[i]
check = True
elif lines[i]['credit'] > 0 and lines[count]['debit'] > 0:
credit_line = lines[i]
debit_line = lines[count]
check = True
if not check:
continue
reconciled, dummy = self._reconcile_lines(
[credit_line, debit_line],
allow_partial=False
)
if reconciled:
res += [credit_line['id'], debit_line['id']]
del lines[i]
break
count += 1
return res, [] # empty list for partial, only full rec in "simple" rec
@api.multi
def _simple_order(self, *args, **kwargs):
return "ORDER BY account_move_line.%s" % self._key_field
def _action_rec(self):
"""Match only 2 move lines, do not allow partial reconcile"""
select = self._select()
select += ", account_move_line.%s " % self._key_field
where, params = self._where()
where += " AND account_move_line.%s IS NOT NULL " % self._key_field
where2, params2 = self._get_filter()
query = ' '.join((
select,
self._from(),
where, where2,
self._simple_order()))
self.env.cr.execute(query, params + params2)
lines = self.env.cr.dictfetchall()
return self.rec_auto_lines_simple(lines)
class EasyReconcileSimpleName(models.TransientModel):
_name = 'easy.reconcile.simple.name'
_inherit = 'easy.reconcile.simple'
# has to be subclassed
# field name used as key for matching the move lines
_key_field = 'name'
class EasyReconcileSimplePartner(models.TransientModel):
_name = 'easy.reconcile.simple.partner'
_inherit = 'easy.reconcile.simple'
# has to be subclassed
# field name used as key for matching the move lines
_key_field = 'partner_id'
class EasyReconcileSimpleReference(models.TransientModel):
_name = 'easy.reconcile.simple.reference'
_inherit = 'easy.reconcile.simple'
# has to be subclassed
# field name used as key for matching the move lines
_key_field = 'ref'