2
0

[MIG] account_move_name_sequence: Migration to 15.0

This commit is contained in:
Francisco Javier Luna Vazquez 2022-05-26 16:20:43 -05:00 committed by Rodrigo
parent 3a1b342a62
commit a800db0440
3 changed files with 41 additions and 37 deletions

View File

@ -7,7 +7,7 @@
{ {
"name": "Account Move Number Sequence", "name": "Account Move Number Sequence",
"version": "14.0.1.2.2", "version": "15.0.1.0.0",
"category": "Accounting", "category": "Accounting",
"license": "AGPL-3", "license": "AGPL-3",
"summary": "Generate journal entry number from sequence", "summary": "Generate journal entry number from sequence",

View File

@ -2,6 +2,7 @@
# Copyright 2022 Vauxoo (https://www.vauxoo.com/) # Copyright 2022 Vauxoo (https://www.vauxoo.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com> # @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Moisés López <moylop260@vauxoo.com> # @author: Moisés López <moylop260@vauxoo.com>
# @author: Francisco Luna <fluna@vauxoo.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging import logging
@ -45,26 +46,26 @@ class AccountJournal(models.Model):
raise ValidationError( raise ValidationError(
_( _(
"On journal '%s', the same sequence is used as " "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: if journal.sequence_id and not journal.sequence_id.company_id:
raise ValidationError( msg = _(
_( "The company is not set on sequence '%(sequence)s' configured on "
"The company is not set on sequence '%s' configured on " "journal '%(journal)s'.",
"journal '%s'." sequence=journal.sequence_id.display_name,
) journal=journal.display_name,
% (journal.sequence_id.display_name, journal.display_name)
) )
raise ValidationError(msg)
if journal.refund_sequence_id and not journal.refund_sequence_id.company_id: if journal.refund_sequence_id and not journal.refund_sequence_id.company_id:
raise ValidationError( msg = _(
_( "The company is not set on sequence '%(sequence)s' configured as "
"The company is not set on sequence '%s' configured as " "credit note sequence of journal '%(journal)s'.",
"credit note sequence of journal '%s'." sequence=journal.refund_sequence_id.display_name,
) journal=journal.display_name,
% (journal.refund_sequence_id.display_name, journal.display_name)
) )
raise ValidationError(msg)
@api.model @api.model
def create(self, vals): def create(self, vals):
@ -180,7 +181,10 @@ class AccountJournal(models.Model):
) )
select_max_number = ( select_max_number = (
"MAX(split_part(name, '%s', %d)::INTEGER) AS 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 = ( query = (
"SELECT %s, %s, %s FROM account_move " "SELECT %s, %s, %s FROM account_move "

View File

@ -2,31 +2,31 @@
# Copyright 2022 Vauxoo (https://www.vauxoo.com/) # Copyright 2022 Vauxoo (https://www.vauxoo.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com> # @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Moisés López <moylop260@vauxoo.com> # @author: Moisés López <moylop260@vauxoo.com>
# @author: Francisco Luna <fluna@vauxoo.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api from odoo import SUPERUSER_ID, api
def create_journal_sequences(cr, registry): def create_journal_sequences(cr, registry):
with api.Environment.manage(): env = api.Environment(cr, SUPERUSER_ID, {})
env = api.Environment(cr, SUPERUSER_ID, {}) journals = (
journals = ( env["account.journal"]
env["account.journal"] .with_context(active_test=False)
.with_context(active_test=False) .search([("sequence_id", "=", False)])
.search([("sequence_id", "=", False)]) )
) for journal in journals:
for journal in journals: journal_vals = {
journal_vals = { "code": journal.code,
"code": journal.code, "name": journal.name,
"name": journal.name, "company_id": journal.company_id.id,
"company_id": journal.company_id.id, }
} seq_vals = journal._prepare_sequence(journal_vals)
seq_vals = journal._prepare_sequence(journal_vals) seq_vals.update(journal._prepare_sequence_current_moves())
seq_vals.update(journal._prepare_sequence_current_moves()) vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id}
vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id} if journal.type in ("sale", "purchase") and journal.refund_sequence:
if journal.type in ("sale", "purchase") and journal.refund_sequence: rseq_vals = journal._prepare_sequence(journal_vals, refund=True)
rseq_vals = journal._prepare_sequence(journal_vals, refund=True) rseq_vals.update(journal._prepare_sequence_current_moves(refund=True))
rseq_vals.update(journal._prepare_sequence_current_moves(refund=True)) vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id
vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id journal.write(vals)
journal.write(vals)
return return