/
account_journal.py
29 lines (24 loc) · 1.1 KB
/
account_journal.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
# © 2019 Eficent Business and IT Consulting Services S.L.
# © 2019 Serpent Consulting Services Pvt. Ltd.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class AccountJournal(models.Model):
_inherit = "account.journal"
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
domain="[('user_ids', '=', uid)]",
help="Operating Unit that will be used in payments, "
"when this journal is used.")
@api.multi
@api.constrains('type')
def _check_ou(self):
for journal in self:
if journal.type in ('bank', 'cash') \
and journal.company_id.ou_is_self_balanced \
and not journal.operating_unit_id:
raise UserError(_('Configuration error. If defined as '
'self-balanced at company level, the '
'operating unit is mandatory in bank '
'journal.'))