From a800db0440cacfcfca74c35bd21c49e28c657be3 Mon Sep 17 00:00:00 2001 From: Francisco Javier Luna Vazquez Date: Thu, 26 May 2022 16:20:43 -0500 Subject: [PATCH] [MIG] account_move_name_sequence: Migration to 15.0 --- account_move_name_sequence/__manifest__.py | 2 +- .../models/account_journal.py | 34 ++++++++------- account_move_name_sequence/post_install.py | 42 +++++++++---------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/account_move_name_sequence/__manifest__.py b/account_move_name_sequence/__manifest__.py index 46ab257a..de8ebb9b 100644 --- a/account_move_name_sequence/__manifest__.py +++ b/account_move_name_sequence/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Account Move Number Sequence", - "version": "14.0.1.2.2", + "version": "15.0.1.0.0", "category": "Accounting", "license": "AGPL-3", "summary": "Generate journal entry number from sequence", diff --git a/account_move_name_sequence/models/account_journal.py b/account_move_name_sequence/models/account_journal.py index 41755ee1..9038ec2a 100644 --- a/account_move_name_sequence/models/account_journal.py +++ b/account_move_name_sequence/models/account_journal.py @@ -2,6 +2,7 @@ # Copyright 2022 Vauxoo (https://www.vauxoo.com/) # @author: Alexis de Lattre # @author: Moisés López +# @author: Francisco Luna # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -45,26 +46,26 @@ class AccountJournal(models.Model): raise ValidationError( _( "On journal '%s', the same sequence is used as " - "Entry Sequence and Credit Note Entry Sequence." + "Entry Sequence and Credit Note Entry Sequence.", + journal.display_name, ) - % journal.display_name ) if journal.sequence_id and not journal.sequence_id.company_id: - raise ValidationError( - _( - "The company is not set on sequence '%s' configured on " - "journal '%s'." - ) - % (journal.sequence_id.display_name, journal.display_name) + msg = _( + "The company is not set on sequence '%(sequence)s' configured on " + "journal '%(journal)s'.", + sequence=journal.sequence_id.display_name, + journal=journal.display_name, ) + raise ValidationError(msg) if journal.refund_sequence_id and not journal.refund_sequence_id.company_id: - raise ValidationError( - _( - "The company is not set on sequence '%s' configured as " - "credit note sequence of journal '%s'." - ) - % (journal.refund_sequence_id.display_name, journal.display_name) + msg = _( + "The company is not set on sequence '%(sequence)s' configured as " + "credit note sequence of journal '%(journal)s'.", + sequence=journal.refund_sequence_id.display_name, + journal=journal.display_name, ) + raise ValidationError(msg) @api.model def create(self, vals): @@ -180,7 +181,10 @@ class AccountJournal(models.Model): ) select_max_number = ( "MAX(split_part(name, '%s', %d)::INTEGER) AS max_number" - % (prefixes[-1], prefixes.count(prefixes[-1]) + 1) + % ( + prefixes[-1], + prefixes.count(prefixes[-1]) + 1, + ) ) query = ( "SELECT %s, %s, %s FROM account_move " diff --git a/account_move_name_sequence/post_install.py b/account_move_name_sequence/post_install.py index ef52eeeb..10a69f0e 100644 --- a/account_move_name_sequence/post_install.py +++ b/account_move_name_sequence/post_install.py @@ -2,31 +2,31 @@ # Copyright 2022 Vauxoo (https://www.vauxoo.com/) # @author: Alexis de Lattre # @author: Moisés López +# @author: Francisco Luna # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import SUPERUSER_ID, api def create_journal_sequences(cr, registry): - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - journals = ( - env["account.journal"] - .with_context(active_test=False) - .search([("sequence_id", "=", False)]) - ) - for journal in journals: - journal_vals = { - "code": journal.code, - "name": journal.name, - "company_id": journal.company_id.id, - } - seq_vals = journal._prepare_sequence(journal_vals) - seq_vals.update(journal._prepare_sequence_current_moves()) - vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id} - if journal.type in ("sale", "purchase") and journal.refund_sequence: - rseq_vals = journal._prepare_sequence(journal_vals, refund=True) - rseq_vals.update(journal._prepare_sequence_current_moves(refund=True)) - vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id - journal.write(vals) + env = api.Environment(cr, SUPERUSER_ID, {}) + journals = ( + env["account.journal"] + .with_context(active_test=False) + .search([("sequence_id", "=", False)]) + ) + for journal in journals: + journal_vals = { + "code": journal.code, + "name": journal.name, + "company_id": journal.company_id.id, + } + seq_vals = journal._prepare_sequence(journal_vals) + seq_vals.update(journal._prepare_sequence_current_moves()) + vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id} + if journal.type in ("sale", "purchase") and journal.refund_sequence: + rseq_vals = journal._prepare_sequence(journal_vals, refund=True) + rseq_vals.update(journal._prepare_sequence_current_moves(refund=True)) + vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id + journal.write(vals) return