forked from OCA/account-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasy_reconcile_history.py
139 lines (126 loc) · 4.97 KB
/
easy_reconcile_history.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Guewen Baconnier, Damien Crier
# Copyright 2012, 2015 Camptocamp SA
#
# 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 import models, api, fields, _
class EasyReconcileHistory(models.Model):
""" Store an history of the runs per profile
Each history stores the list of reconciliations done"""
_name = 'easy.reconcile.history'
_rec_name = 'easy_reconcile_id'
_order = 'date DESC'
@api.one
@api.depends('reconcile_ids', 'reconcile_partial_ids')
def _get_reconcile_line_ids(self):
move_line_ids = []
for reconcile in self.reconcile_ids:
move_lines = reconcile.mapped('line_id')
move_line_ids.extend(move_lines.ids)
self.reconcile_line_ids = move_line_ids
move_line_ids2 = []
for reconcile2 in self.reconcile_partial_ids:
move_lines2 = reconcile2.mapped('line_partial_ids')
move_line_ids2.extend(move_lines2.ids)
self.partial_line_ids = move_line_ids2
easy_reconcile_id = fields.Many2one(
'account.easy.reconcile',
string='Reconcile Profile',
readonly=True
)
date = fields.Datetime(string='Run date', readonly=True, required=True)
reconcile_ids = fields.Many2many(
comodel_name='account.move.reconcile',
relation='account_move_reconcile_history_rel',
string='Partial Reconciliations',
readonly=True
)
reconcile_partial_ids = fields.Many2many(
comodel_name='account.move.reconcile',
relation='account_move_reconcile_history_partial_rel',
string='Partial Reconciliations',
readonly=True
)
reconcile_line_ids = fields.Many2many(
comodel_name='account.move.line',
relation='account_move_line_history_rel',
string='Reconciled Items',
compute='_get_reconcile_line_ids'
)
partial_line_ids = fields.Many2many(
comodel_name='account.move.line',
relation='account_move_line_history_partial_rel',
string='Partially Reconciled Items',
compute='_get_reconcile_line_ids'
)
company_id = fields.Many2one(
'res.company',
string='Company',
store=True,
readonly=True,
related='easy_reconcile_id.company_id'
)
@api.multi
def _open_move_lines(self, rec_type='full'):
""" For an history record, open the view of move line with
the reconciled or partially reconciled move lines
:param history_id: id of the history
:param rec_type: 'full' or 'partial'
:return: action to open the move lines
"""
assert rec_type in ('full', 'partial'), \
"rec_type must be 'full' or 'partial'"
move_line_ids = []
if rec_type == 'full':
move_line_ids = self.mapped('reconcile_ids.line_id').ids
name = _('Reconciliations')
else:
move_line_ids = self.mapped(
'reconcile_partial_ids.line_partial_ids').ids
name = _('Partial Reconciliations')
return {
'name': name,
'view_mode': 'tree,form',
'view_id': False,
'view_type': 'form',
'res_model': 'account.move.line',
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'current',
'domain': unicode([('id', 'in', move_line_ids)]),
}
@api.multi
def open_reconcile(self):
""" For an history record, open the view of move line
with the reconciled move lines
:param history_ids: id of the record as int or long
Accept a list with 1 id too to be
used from the client.
"""
self.ensure_one()
return self._open_move_lines(rec_type='full')
@api.multi
def open_partial(self):
""" For an history record, open the view of move line
with the partially reconciled move lines
:param history_ids: id of the record as int or long
Accept a list with 1 id too to be
used from the client.
"""
self.ensure_one()
return self._open_move_lines(rec_type='partial')