forked from acsone/account-financial-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_move_template.py
117 lines (107 loc) · 4.09 KB
/
account_move_template.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
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2011 - 2014 Agile Business Group sagl
# (<http://www.agilebg.com>)
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
#
# 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, fields, api
from openerp.exceptions import ValidationError
class AccountMoveTemplate(models.Model):
_name = 'account.move.template'
_inherit = 'account.document.template'
@api.model
def _company_get(self):
return self.env['res.company']._company_default_get(
object='account.move.template'
)
company_id = fields.Many2one(
comodel_name='res.company',
string='Company',
required=True,
change_default=True,
default=_company_get,
)
template_line_ids = fields.One2many(
comodel_name='account.move.template.line',
inverse_name='template_id',
string='Template Lines'
)
cross_journals = fields.Boolean(string='Cross-Journals')
transitory_acc_id = fields.Many2one(
comodel_name='account.account',
string='Transitory account',
required=False
)
class AccountMoveTemplateLine(models.Model):
_name = 'account.move.template.line'
_inherit = 'account.document.template.line'
journal_id = fields.Many2one(
comodel_name='account.journal',
string='Journal',
required=True
)
account_id = fields.Many2one(
comodel_name='account.account',
string='Account',
required=True,
ondelete="cascade"
)
move_line_type = fields.Selection(
[('cr', 'Credit'), ('dr', 'Debit')],
string='Move Line Type',
required=True
)
analytic_account_id = fields.Many2one(
comodel_name='account.analytic.account',
string='Analytic Account',
ondelete="cascade"
)
template_id = fields.Many2one(
comodel_name='account.move.template',
string='Template'
)
account_tax_id = fields.Many2one(
comodel_name='account.tax',
string='Tax'
)
_sql_constraints = [
('sequence_template_uniq', 'unique (template_id,sequence)',
'The sequence of the line must be unique per template !')
]
@api.constrains('journal_id')
def _check_different_journal(self):
# Check that the journal on these lines are different/same in the case
# of cross journals/single journal
journal_ids = []
all_journal_ids = []
error_message = (
u'If the template is "cross-journals", the Journals must be '
u'different, if the template does not "cross-journals" the '
u'Journals must be the same!'
)
for move_template in self.template_id:
if move_template.template_line_ids:
for template_line in move_template.template_line_ids:
all_journal_ids.append(template_line.journal_id.id)
if template_line.journal_id.id not in journal_ids:
journal_ids.append(template_line.journal_id.id)
if move_template.cross_journals:
if len(all_journal_ids) != len(journal_ids):
raise ValidationError(error_message)
elif len(journal_ids) != 1:
raise ValidationError(error_message)