Files
tryton/modules/account_statement/account.py
T

81 lines
2.7 KiB
Python
Raw Normal View History

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.
2015-01-02 15:43:29 +01:00
from itertools import groupby
from operator import itemgetter
from sql.operators import Concat
from trytond.i18n import gettext
from trytond.model import ModelView
2015-01-02 15:43:29 +01:00
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
from trytond.tools import grouped_slice, reduce_ids
2012-09-29 15:34:37 +02:00
from trytond.modules.account.exceptions import PostError
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):
super(Journal, cls).__setup__()
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'
2015-01-02 15:43:29 +01:00
@classmethod
def __register__(cls, module_name):
pool = Pool()
StatementLine = pool.get('account.statement.line')
cursor = Transaction().connection.cursor()
2015-01-02 15:43:29 +01:00
sql_table = cls.__table__()
super(Move, cls).__register__(module_name)
# Migration from 3.4:
# account.statement.line origin changed to account.statement
statement_line = StatementLine.__table__()
cursor.execute(*sql_table.join(statement_line,
condition=(
Concat(StatementLine.__name__ + ',', statement_line.id)
== sql_table.origin
)
).select(sql_table.id, statement_line.statement,
order_by=(sql_table.id, statement_line.statement)))
for statement_id, values in groupby(cursor, itemgetter(1)):
2015-01-02 15:43:29 +01:00
ids = [x[0] for x in values]
for sub_ids in grouped_slice(ids):
red_sql = reduce_ids(sql_table.id, sub_ids)
cursor.execute(*sql_table.update(
columns=[sql_table.origin],
values=['account.statement,%s' % statement_id],
where=red_sql))
2012-09-29 15:34:37 +02:00
@classmethod
def _get_origin(cls):
2015-01-02 15:43:29 +01:00
return super(Move, cls)._get_origin() + ['account.statement']
@classmethod
@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
class MoveLine(metaclass=PoolMeta):
__name__ = 'account.move.line'
@classmethod
def _get_origin(cls):
return super()._get_origin() + ['account.statement.line']