2014-12-02 12:54:50 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2019-12-05 21:38:47 +01:00
|
|
|
from trytond.i18n import gettext
|
2025-05-27 20:00:18 +02:00
|
|
|
from trytond.model import ModelView, dualmethod, fields
|
2019-12-05 21:38:47 +01:00
|
|
|
from trytond.modules.account.exceptions import PostError
|
2021-12-11 17:58:41 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2019-12-05 21:38:47 +01:00
|
|
|
|
2018-05-30 14:12:53 +02:00
|
|
|
|
2018-06-26 19:11:43 +02:00
|
|
|
class Journal(metaclass=PoolMeta):
|
2018-05-30 14:12:53 +02:00
|
|
|
__name__ = 'account.journal'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
2025-04-04 00:45:18 +02:00
|
|
|
super().__setup__()
|
2018-05-30 14:12:53 +02:00
|
|
|
cls.type.selection.append(('statement', "Statement"))
|
2012-09-29 15:34:37 +02:00
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:43 +02:00
|
|
|
class Move(metaclass=PoolMeta):
|
2012-09-29 15:34:37 +02:00
|
|
|
__name__ = 'account.move'
|
|
|
|
|
|
2025-05-27 20:00:18 +02:00
|
|
|
statement_lines = fields.One2Many(
|
|
|
|
|
'account.statement.line', 'move', "Statement Lines", readonly=True)
|
|
|
|
|
|
2012-09-29 15:34:37 +02:00
|
|
|
@classmethod
|
|
|
|
|
def _get_origin(cls):
|
2025-04-04 00:45:18 +02:00
|
|
|
return super()._get_origin() + ['account.statement']
|
2019-12-05 21:38:47 +01:00
|
|
|
|
2023-10-28 10:56:33 +02:00
|
|
|
@dualmethod
|
2019-12-05 21:38:47 +01:00
|
|
|
@ModelView.button
|
|
|
|
|
def post(cls, moves):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
Statement = pool.get('account.statement')
|
|
|
|
|
for move in moves:
|
|
|
|
|
if (isinstance(move.origin, Statement)
|
|
|
|
|
and move.origin.state != 'posted'):
|
|
|
|
|
raise PostError(
|
|
|
|
|
gettext('account_statement.msg_post_statement_move',
|
|
|
|
|
move=move.rec_name,
|
|
|
|
|
statement=move.origin.rec_name))
|
|
|
|
|
super().post(moves)
|
2021-02-03 21:22:31 +01:00
|
|
|
|
2025-05-27 20:00:18 +02:00
|
|
|
@classmethod
|
|
|
|
|
def copy(cls, moves, default=None):
|
|
|
|
|
default = default.copy() if default is not None else {}
|
|
|
|
|
default.setdefault('statement_lines')
|
|
|
|
|
return super().copy(moves, default=default)
|
|
|
|
|
|
2021-02-03 21:22:31 +01:00
|
|
|
|
|
|
|
|
class MoveLine(metaclass=PoolMeta):
|
|
|
|
|
__name__ = 'account.move.line'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def _get_origin(cls):
|
|
|
|
|
return super()._get_origin() + ['account.statement.line']
|
2025-05-27 20:00:18 +02:00
|
|
|
|
|
|
|
|
@fields.depends('move', '_parent_move.statement_lines')
|
|
|
|
|
def on_change_with_description_used(self, name=None):
|
|
|
|
|
description = super().on_change_with_description_used(name=name)
|
|
|
|
|
if (not description
|
|
|
|
|
and self.move
|
|
|
|
|
and getattr(self.move, 'statement_lines', None)):
|
|
|
|
|
for statement_line in self.move.statement_lines:
|
|
|
|
|
if statement_line.description:
|
|
|
|
|
description = statement_line.description
|
|
|
|
|
break
|
|
|
|
|
return description
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def search_description_used(cls, name, clause):
|
|
|
|
|
operator = clause[1]
|
|
|
|
|
if operator.startswith('!') or operator.startswith('not '):
|
|
|
|
|
bool_op = 'AND'
|
|
|
|
|
else:
|
|
|
|
|
bool_op = 'OR'
|
|
|
|
|
domain = [bool_op,
|
|
|
|
|
super().search_description_used(name, clause),
|
|
|
|
|
('move.statement_lines.description', *clause[1:]),
|
|
|
|
|
]
|
|
|
|
|
return domain
|