-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatement_analytic.py
126 lines (104 loc) · 4.44 KB
/
statement_analytic.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
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.model import fields
from trytond.pyson import Eval
from trytond.modules.analytic_account import AnalyticMixin
class Line(AnalyticMixin, metaclass=PoolMeta):
__name__ = 'account.statement.line'
@classmethod
def __setup__(cls):
super().__setup__()
cls.analytic_accounts.domain = [
('company', '=', Eval('company', -1)),
]
cls.analytic_accounts.states = {
'readonly': Eval('statement_state') != 'draft',
}
def get_move_line(self):
pool = Pool()
AnalyticLine = pool.get('analytic_account.line')
move_line = super().get_move_line()
if not hasattr(self, 'analytic_accounts'):
return move_line
if move_line and self.analytic_accounts:
for analytic_account in self.analytic_accounts:
if analytic_account.account:
account = analytic_account.account
if move_line.account != self.account:
continue
analytic_line = AnalyticLine()
analytic_line.debit = move_line.debit
analytic_line.credit = move_line.credit
analytic_line.account = account
analytic_line.date = self.date
if not hasattr(move_line, 'analytic_lines'):
move_line.analytic_lines = (analytic_line,)
else:
move_line.analytic_lines += (analytic_line,)
return move_line
class Origin(metaclass=PoolMeta):
__name__ = 'account.statement.origin'
def _get_suggested_values(self, parent, name, line, amount, related_to,
similarity):
pool = Pool()
AnalyticAccountEntry = pool.get('analytic.account.entry')
values = super()._get_suggested_values(parent, name, line, amount,
related_to, similarity)
if hasattr(line, 'analytic_accounts') and line.analytic_accounts:
new_entry = AnalyticAccountEntry.copy(line.analytic_accounts,
default={
'origin': None,
})
values['analytic_accounts'] = [('add', [e.id for e in new_entry])]
return values
class OriginSuggestedLine(AnalyticMixin, metaclass=PoolMeta):
__name__ = 'account.statement.origin.suggested.line'
@classmethod
def __setup__(cls):
super().__setup__()
cls.analytic_accounts.domain = [
('company', '=', Eval('company', -1)),
]
cls.analytic_accounts.states = {
'readonly': Eval('origin.state') != 'registered',
}
@classmethod
def get_suggested_values(cls, child, description=None):
pool = Pool()
AnalyticAccountEntry = pool.get('analytic.account.entry')
values = super().get_suggested_values(child, description)
if child.analytic_accounts:
new_entry = AnalyticAccountEntry.copy(child.analytic_accounts,
default={
'origin': None,
})
values['analytic_accounts'] = [('add', [e.id for e in new_entry])]
return values
class AnalyticAccountEntry(metaclass=PoolMeta):
__name__ = 'analytic.account.entry'
@classmethod
def _get_origin(cls):
origins = super()._get_origin()
return origins + ['account.statement.line',
'account.statement.origin.suggested.line']
@fields.depends('origin')
def on_change_with_company(self, name=None):
pool = Pool()
StatementLine = pool.get('account.statement.line')
SuggestedLine = pool.get('account.statement.origin.suggested.line')
company = super().on_change_with_company(name)
if (isinstance(self.origin, StatementLine)
or isinstance(self.origin, SuggestedLine)):
company = self.origin.company.id
return company
@classmethod
def search_company(cls, name, clause):
domain = super().search_company(name, clause),
return ['OR',
domain,
(('origin.company',) + tuple(clause[1:]) +
('account.statement.line',)),
(('origin.company',) + tuple(clause[1:]) +
('account.statement.origin.suggested.line',)),
]