From 93b3d27117a31a406a2586b45afa0a077333c67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 11 Feb 2025 12:50:48 +0100 Subject: [PATCH] Replace account move number by post number Closes #13864 --- demo/account_statement.py | 12 +--- modules/account/CHANGELOG | 2 + modules/account/__init__.py | 1 - modules/account/doc/design/journal.inc.rst | 3 +- modules/account/general_journal.fodt | 6 +- modules/account/journal.py | 50 +------------- modules/account/journal.xml | 19 ------ modules/account/move.py | 67 ++++++------------- .../tests/scenario_account_reconcile.rst | 6 +- .../tests/scenario_account_reconciliation.rst | 6 +- .../tests/scenario_close_fiscalyear.rst | 4 -- modules/account/tests/scenario_move_copy.rst | 9 +-- modules/account/tests/test_module.py | 5 -- modules/account/view/journal_form.xml | 15 ++--- modules/account/view/move_form.xml | 4 +- modules/account/view/move_tree.xml | 1 - modules/account_export_winbooks/account.py | 2 +- modules/account_fr/account.py | 4 +- modules/account_fr/tests/scenario_fec.rst | 12 ++-- .../scenario_invoice_alternate_currency.rst | 6 +- .../tests/scenario_invoice_overpayment.rst | 6 +- .../tests/scenario_analytic_account.rst | 5 -- 22 files changed, 50 insertions(+), 195 deletions(-) diff --git a/demo/account_statement.py b/demo/account_statement.py index 2855ae4be9..c05663d323 100644 --- a/demo/account_statement.py +++ b/demo/account_statement.py @@ -14,24 +14,14 @@ def setup(config, modules, company): Statement = Model.get('account.statement') AccountJournal = Model.get('account.journal') Account = Model.get('account.account') - Sequence = Model.get('ir.sequence') - SequenceType = Model.get('ir.sequence.type') Invoice = Model.get('account.invoice') - sequence_type, = SequenceType.find([('name', '=', "Account Journal")]) - sequence = Sequence(name='Statement', - sequence_type=sequence_type, - company=company) - sequence.save() - cash, = Account.find([ ('company', '=', company.id), ('code', '=', '1.1.1'), ]) - account_journal = AccountJournal(name='Bank', - type='statement', - sequence=sequence) + account_journal = AccountJournal(name='Bank', type='statement') account_journal.save() journal = Journal(name='Bank', diff --git a/modules/account/CHANGELOG b/modules/account/CHANGELOG index c33a74b091..c386e24657 100644 --- a/modules/account/CHANGELOG +++ b/modules/account/CHANGELOG @@ -1,3 +1,5 @@ +* Rename post number to number +* Remove number on move and its sequence on journal Version 7.4.0 - 2024-11-04 -------------------------- diff --git a/modules/account/__init__.py b/modules/account/__init__.py index f48993acf6..2a783d0b8c 100644 --- a/modules/account/__init__.py +++ b/modules/account/__init__.py @@ -47,7 +47,6 @@ def register(): configuration.Journal, period.Period, journal.Journal, - journal.JournalSequence, journal.JournalCashContext, journal.JournalPeriod, move.Move, diff --git a/modules/account/doc/design/journal.inc.rst b/modules/account/doc/design/journal.inc.rst index 2567c4c818..25d02fe08e 100644 --- a/modules/account/doc/design/journal.inc.rst +++ b/modules/account/doc/design/journal.inc.rst @@ -7,8 +7,7 @@ A *Journal* represents a book of original entry from traditional manual accounting. In Tryton it allows `Account Moves ` of the same class to be grouped together. -Every account move gets associated with a journal, and the journal defines -what sequence is then used to number the account move. +Every account move gets associated with a journal. Among the journal's properties is a type. This limits where the journal can be used. diff --git a/modules/account/general_journal.fodt b/modules/account/general_journal.fodt index 9109183bab..5570b1bc12 100644 --- a/modules/account/general_journal.fodt +++ b/modules/account/general_journal.fodt @@ -515,7 +515,7 @@ - Journal Entry:<move.number> + Journal Entry:<move.rec_name> Date: <format_date(move.date, user.language)> @@ -527,7 +527,7 @@ <if test="move.state == 'posted'"> - Posted <move.post_number><format_date(move.post_date, user.language)> + Posted<format_date(move.post_date, user.language)> </if> <if test="move.state == 'draft'"> Draft @@ -600,4 +600,4 @@ - \ No newline at end of file + diff --git a/modules/account/journal.py b/modules/account/journal.py index 987081645a..16d8ec26d1 100644 --- a/modules/account/journal.py +++ b/modules/account/journal.py @@ -9,11 +9,9 @@ from trytond.model import ( DeactivableMixin, MatchMixin, ModelSQL, ModelView, Unique, Workflow, fields, sequence_ordered) from trytond.model.exceptions import AccessError -from trytond.modules.company.model import ( - CompanyMultiValueMixin, CompanyValueMixin) from trytond.modules.currency.fields import Monetary from trytond.pool import Pool -from trytond.pyson import Bool, Eval, Id +from trytond.pyson import Eval from trytond.tools import ( grouped_slice, is_full_text, lstrip_wildcard, reduce_ids, sqlite_apply_types) @@ -27,7 +25,7 @@ STATES = { class Journal( DeactivableMixin, MatchMixin, sequence_ordered('matching_sequence', "Matching Sequence"), - ModelSQL, ModelView, CompanyMultiValueMixin): + ModelSQL, ModelView): __name__ = 'account.journal' name = fields.Char('Name', size=None, required=True, translate=True) code = fields.Char('Code', size=None) @@ -39,19 +37,6 @@ class Journal( ('situation', "Situation"), ('write-off', "Write-Off"), ], 'Type', required=True) - sequence = fields.MultiValue(fields.Many2One( - 'ir.sequence', "Sequence", - domain=[ - ('sequence_type', '=', - Id('account', 'sequence_type_account_journal')), - ('company', 'in', [ - Eval('context', {}).get('company', -1), None]), - ], - states={ - 'required': Bool(Eval('context', {}).get('company', -1)), - })) - sequences = fields.One2Many( - 'account.journal.sequence', 'journal', "Sequences") debit = fields.Function(Monetary( "Debit", currency='currency', digits='currency'), 'get_debit_credit_balance') @@ -70,10 +55,6 @@ class Journal( super(Journal, cls).__setup__() cls._order.insert(0, ('name', 'ASC')) - @classmethod - def default_sequence(cls, **pattern): - return cls.multivalue_model('sequence').default_sequence() - @classmethod def search_rec_name(cls, name, clause): _, operator, operand, *extra = clause @@ -185,33 +166,6 @@ class Journal( super().write(*args) -class JournalSequence(ModelSQL, CompanyValueMixin): - __name__ = 'account.journal.sequence' - journal = fields.Many2One( - 'account.journal', "Journal", ondelete='CASCADE', - context={ - 'company': Eval('company', -1), - }, - depends={'company'}) - sequence = fields.Many2One( - 'ir.sequence', "Sequence", - domain=[ - ('sequence_type', '=', - Id('account', 'sequence_type_account_journal')), - ('company', 'in', [Eval('company', -1), None]), - ], - depends={'company'}) - - @classmethod - def default_sequence(cls): - pool = Pool() - ModelData = pool.get('ir.model.data') - try: - return ModelData.get_id('account', 'sequence_account_journal') - except KeyError: - return None - - class JournalCashContext(ModelView): __name__ = 'account.journal.open_cash.context' start_date = fields.Date('Start Date', required=True) diff --git a/modules/account/journal.xml b/modules/account/journal.xml index 2000499974..9a2b4d601e 100644 --- a/modules/account/journal.xml +++ b/modules/account/journal.xml @@ -95,25 +95,6 @@ this repository contains the full copyright notices and license terms. --> - - Account Journal - - - - - - - - - - - - Default Account Journal - - - account.journal.period diff --git a/modules/account/move.py b/modules/account/move.py index 21aed4e93e..d33d9131ab 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -85,8 +85,8 @@ class DescriptionOriginMixin: class Move(DescriptionOriginMixin, ModelSQL, ModelView): __name__ = 'account.move' _rec_name = 'number' - number = fields.Char('Number', required=True, readonly=True) - post_number = fields.Char('Post Number', readonly=True, + number = fields.Char( + "Number", readonly=True, help='Also known as Folio Number.') company = fields.Many2One('company.company', 'Company', required=True, states=_MOVE_STATES) @@ -103,10 +103,8 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): []), ], states=_MOVE_STATES) - journal = fields.Many2One('account.journal', 'Journal', required=True, - states={ - 'readonly': Eval('number') & Eval('journal', None), - }, + journal = fields.Many2One( + 'account.journal', "Journal", required=True, states=_MOVE_STATES, context={ 'company': Eval('company', -1), }, @@ -131,7 +129,6 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): @classmethod def __setup__(cls): cls.number.search_unaccented = False - cls.post_number.search_unaccented = False super(Move, cls).__setup__() t = cls.__table__() cls.create_date.select = True @@ -157,16 +154,20 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): (t.period, Index.Range())), }) + @classmethod + def __register__(cls, module): + table_h = cls.__table_handler__(module) + if (table_h.column_exist('number') + and table_h.column_exist('post_number')): + table_h.drop_column('number') + table_h.column_rename('post_number', 'number') + super().__register__(module) + @classmethod def order_number(cls, tables): table, _ = tables[None] return [CharLength(table.number), table.number] - @classmethod - def order_post_number(cls, tables): - table, _ = tables[None] - return [CharLength(table.post_number), table.post_number] - @staticmethod def default_company(): return Transaction().context.get('company') @@ -276,16 +277,11 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): gettext('account.msg_modify_posted_moved', move=move.rec_name)) - @classmethod - def search_rec_name(cls, name, clause): - if clause[1].startswith('!') or clause[1].startswith('not '): - bool_op = 'AND' + def get_rec_name(self, name): + if self.number: + return self.number else: - bool_op = 'OR' - return [bool_op, - ('post_number',) + tuple(clause[1:]), - (cls._rec_name,) + tuple(clause[1:]), - ] + return f'({self.id})' @classmethod def write(cls, *args): @@ -301,30 +297,6 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): args.extend((moves, values)) super(Move, cls).write(*args) - @classmethod - def create(cls, vlist): - pool = Pool() - Journal = pool.get('account.journal') - context = Transaction().context - - default_company = cls.default_company() - vlist = [x.copy() for x in vlist] - missing_number = defaultdict(list) - for vals in vlist: - if not vals.get('number'): - journal_id = vals.get('journal', context.get('journal')) - company_id = vals.get('company', default_company) - if journal_id: - missing_number[(journal_id, company_id)].append(vals) - for (journal_id, company_id), values in missing_number.items(): - journal = Journal(journal_id) - sequence = journal.get_multivalue('sequence', company=company_id) - with Transaction().set_context(company=company_id): - for vals, number in zip( - values, sequence.get_many(len(values))): - vals['number'] = number - return super().create(vlist) - @classmethod def delete(cls, moves): MoveLine = Pool().get('account.move.line') @@ -374,7 +346,6 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): return origin['date'] default.setdefault('number', None) - default.setdefault('post_number', None) default.setdefault('state', cls.default_state()) default.setdefault('post_date', None) default.setdefault('period', default_period) @@ -539,7 +510,7 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): missing_number = defaultdict(list) for move in c_moves: move.state = 'posted' - if not move.post_number: + if not move.number: move.post_date = today missing_number[move.period.post_move_sequence_used].append( move) @@ -547,7 +518,7 @@ class Move(DescriptionOriginMixin, ModelSQL, ModelView): for sequence, m_moves in missing_number.items(): for move, number in zip( m_moves, sequence.get_many(len(m_moves))): - move.post_number = number + move.number = number cls.save(moves) diff --git a/modules/account/tests/scenario_account_reconcile.rst b/modules/account/tests/scenario_account_reconcile.rst index 76f4ebd915..304345aa2a 100644 --- a/modules/account/tests/scenario_account_reconcile.rst +++ b/modules/account/tests/scenario_account_reconcile.rst @@ -84,11 +84,7 @@ Create Moves to reconcile:: Create a write off method:: - >>> Sequence = Model.get('ir.sequence') - >>> sequence_journal, = Sequence.find( - ... [('sequence_type.name', '=', "Account Journal")], limit=1) - >>> journal_writeoff = Journal(name='Write-Off', type='write-off', - ... sequence=sequence_journal) + >>> journal_writeoff = Journal(name='Write-Off', type='write-off') >>> journal_writeoff.save() >>> WriteOff = Model.get('account.move.reconcile.write_off') >>> writeoff_method = WriteOff() diff --git a/modules/account/tests/scenario_account_reconciliation.rst b/modules/account/tests/scenario_account_reconciliation.rst index 97f0a73a9f..c64aa6db4e 100644 --- a/modules/account/tests/scenario_account_reconciliation.rst +++ b/modules/account/tests/scenario_account_reconciliation.rst @@ -154,11 +154,7 @@ Create Moves for writeoff reconciliation:: Create a write-off payment method:: - >>> Sequence = Model.get('ir.sequence') - >>> sequence_journal, = Sequence.find( - ... [('sequence_type.name', '=', "Account Journal")], limit=1) - >>> journal_writeoff = Journal(name='Write-Off', type='write-off', - ... sequence=sequence_journal) + >>> journal_writeoff = Journal(name='Write-Off', type='write-off') >>> journal_writeoff.save() >>> WriteOff = Model.get('account.move.reconcile.write_off') >>> writeoff_method = WriteOff() diff --git a/modules/account/tests/scenario_close_fiscalyear.rst b/modules/account/tests/scenario_close_fiscalyear.rst index 2d9f314f9a..efea40bfe1 100644 --- a/modules/account/tests/scenario_close_fiscalyear.rst +++ b/modules/account/tests/scenario_close_fiscalyear.rst @@ -43,14 +43,10 @@ Get accounts:: Prepare the closing settings for fiscalyear close:: - >>> journal_sequence, = Sequence.find([ - ... ('sequence_type.name', '=', "Account Journal"), - ... ], limit=1) >>> journal_closing = Journal() >>> journal_closing.name = 'Closing' >>> journal_closing.code = 'CLO' >>> journal_closing.type = 'situation' - >>> journal_closing.sequence = journal_sequence >>> journal_closing.save() >>> period_closing = Period() >>> period_closing.name = 'Closing' diff --git a/modules/account/tests/scenario_move_copy.rst b/modules/account/tests/scenario_move_copy.rst index bbc38207b2..ac1038e98c 100644 --- a/modules/account/tests/scenario_move_copy.rst +++ b/modules/account/tests/scenario_move_copy.rst @@ -10,8 +10,7 @@ Imports:: >>> from trytond.modules.account.tests.tools import ( ... create_chart, create_fiscalyear, get_accounts) >>> from trytond.modules.company.tests.tools import create_company - >>> from trytond.tests.tools import ( - ... activate_modules, assertEqual, assertNotEqual, assertTrue) + >>> from trytond.tests.tools import activate_modules, assertEqual, assertNotEqual Activate modules:: @@ -57,8 +56,7 @@ Create a posted move:: Copy move on open period:: >>> copy_move, = move.duplicate() - >>> assertTrue(copy_move.number) - >>> copy_move.post_number + >>> copy_move.number >>> copy_move.state 'draft' >>> copy_move.post_date @@ -79,8 +77,7 @@ Copy move on closed period:: >>> config.skip_warning = True >>> copy_move, = move.duplicate() - >>> assertTrue(copy_move.number) - >>> copy_move.post_number + >>> copy_move.number >>> copy_move.state 'draft' >>> copy_move.post_date diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index 04fc119634..4325c6d442 100644 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -120,7 +120,6 @@ def get_fiscalyear(company, today=None, start_date=None, end_date=None): def close_fiscalyear(fiscalyear): pool = Pool() - Sequence = pool.get('ir.sequence') Journal = pool.get('account.journal') Period = pool.get('account.period') Account = pool.get('account.account') @@ -130,14 +129,10 @@ def close_fiscalyear(fiscalyear): 'account.fiscalyear.balance_non_deferral', type='wizard') # Balance non-deferral - journal_sequence, = Sequence.search([ - ('sequence_type.name', '=', "Account Journal"), - ], limit=1) journal_closing, = Journal.create([{ 'name': 'Closing', 'code': 'CLO', 'type': 'situation', - 'sequence': journal_sequence.id, }]) period_closing, = Period.create([{ 'name': 'Closing', diff --git a/modules/account/view/journal_form.xml b/modules/account/view/journal_form.xml index 0b36caccd6..b56cde633f 100644 --- a/modules/account/view/journal_form.xml +++ b/modules/account/view/journal_form.xml @@ -4,16 +4,15 @@ this repository contains the full copyright notices and license terms. -->